mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-10 13:14:05 -05:00
add test for await
This commit is contained in:
parent
62777e1112
commit
f98bcf2f08
2 changed files with 30 additions and 1 deletions
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
(tests
|
||||
(names t_fib1 t_futs1)
|
||||
(names t_fib1 t_futs1 t_many)
|
||||
(enabled_if (>= %{ocaml_version} 5.0))
|
||||
(libraries moonpool trace tracy-client.trace))
|
||||
|
|
|
|||
29
test/await/t_many.ml
Normal file
29
test/await/t_many.ml
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
open Moonpool
|
||||
|
||||
let pool = Pool.create ~min:4 ()
|
||||
|
||||
let run () =
|
||||
let t1 = Unix.gettimeofday () in
|
||||
|
||||
let n = 1_000_000 in
|
||||
let n_tasks = 10 in
|
||||
let task () =
|
||||
let l = List.init n (fun x -> Fut.spawn ~on:pool (fun () -> x)) in
|
||||
Fut.spawn ~on:pool (fun () ->
|
||||
List.fold_left
|
||||
(fun n x ->
|
||||
let _res = Fut.await_exn x in
|
||||
n + 1)
|
||||
0 l)
|
||||
in
|
||||
|
||||
let futs =
|
||||
List.init n_tasks (fun _ -> Fut.spawn ~on:pool task |> Fut.join ~on:pool)
|
||||
in
|
||||
|
||||
let lens = List.map Fut.wait_block_exn futs in
|
||||
Printf.printf "awaited %d items (%d times)\n%!" (List.hd lens) n_tasks;
|
||||
Printf.printf "in %.4fs\n%!" (Unix.gettimeofday () -. t1);
|
||||
assert (List.for_all (fun s -> s = n) lens)
|
||||
|
||||
let () = run ()
|
||||
Loading…
Add table
Reference in a new issue