diff --git a/test/await/dune b/test/await/dune index db90ee84..ae32a3d1 100644 --- a/test/await/dune +++ b/test/await/dune @@ -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)) diff --git a/test/await/t_many.ml b/test/await/t_many.ml new file mode 100644 index 00000000..9d3e18ef --- /dev/null +++ b/test/await/t_many.ml @@ -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 ()