Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for Bounded_queue.list_of_exn #166

Merged
merged 1 commit into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/bounded_queue/bounded_queue_intf.mli
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ module type BOUNDED_QUEUE = sig

val drop_exn : 'a t -> unit
(** [drop_exn queue] removes the top element of the [queue].

@raises Empty if the [queue] is empty. *)

(** {2 Producer functions} *)
Expand Down
33 changes: 28 additions & 5 deletions test/bounded_queue/dscheck_bounded_queue.ml
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,36 @@ let push_push_with_capacity () =
(* got the same number of items out as in *)
Atomic.check (fun () -> capacity = List.length items)))

let pop_pop () =
let push_pop_of_list () =
Atomic.trace (fun () ->
let cue = Cue.create () in
let items_total = 4 in
let pushed = List.init items_total (fun x -> x + 1) in
let cue = Cue.of_list_exn pushed in

for i = 1 to items_total do
Cue.try_push cue i |> ignore
done;
Atomic.spawn (fun () -> Cue.try_push cue 42 |> ignore);

(* consumer *)
let popped = ref [] in
Atomic.spawn (fun () ->
for _ = 1 to items_total do
begin
match Cue.pop_opt cue with
| None -> ()
| Some v -> popped := v :: !popped
end
done);

(* checks*)
Atomic.final (fun () ->
Atomic.check (fun () ->
let remaining = drain cue in
let pushed = pushed @ [ 42 ] in
List.sort Int.compare (!popped @ remaining) = pushed)))

let pop_pop () =
Atomic.trace (fun () ->
let items_total = 4 in
let cue = Cue.of_list_exn (List.init items_total (fun x -> x + 1)) in

(* two consumers *)
let lists = [ ref []; ref [] ] in
Expand Down Expand Up @@ -369,6 +391,7 @@ let tests =
test_case "2-domains-is_empty" `Slow is_empty;
test_case "1-producer-1-consumer-capacity" `Slow push_pop_with_capacity;
test_case "1-push-1-drop" `Slow push_drop;
test_case "1-push-1-pop-of_list" `Slow push_pop_of_list;
test_case "2-producers" `Slow push_push;
test_case "2-producers-capacity" `Slow push_push_with_capacity;
test_case "2-consumers" `Slow pop_pop;
Expand Down
Loading