mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-05 19:00:33 -05:00
test for Moonpool_fib.main
This commit is contained in:
parent
48fbf876dc
commit
c878b1a198
2 changed files with 44 additions and 1 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
(tests
|
(tests
|
||||||
(names
|
(names
|
||||||
t_fib1 t_fls)
|
t_fib1 t_fls t_main)
|
||||||
(enabled_if
|
(enabled_if
|
||||||
(>= %{ocaml_version} 5.0))
|
(>= %{ocaml_version} 5.0))
|
||||||
(libraries
|
(libraries
|
||||||
|
|
|
||||||
43
test/fiber/t_main.ml
Normal file
43
test/fiber/t_main.ml
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
open Moonpool
|
||||||
|
module F = Moonpool_fib
|
||||||
|
|
||||||
|
let ( let@ ) = ( @@ )
|
||||||
|
|
||||||
|
let () =
|
||||||
|
let r =
|
||||||
|
F.main @@ fun runner ->
|
||||||
|
let f1 = F.spawn (fun () -> 1) in
|
||||||
|
let f2 = F.spawn_top ~on:runner (fun () -> 2) in
|
||||||
|
let f3 = F.spawn (fun () -> F.await f1 + 10) in
|
||||||
|
let r = F.await f2 + F.await f3 in
|
||||||
|
assert (r = 13);
|
||||||
|
r
|
||||||
|
in
|
||||||
|
assert (r = 13)
|
||||||
|
|
||||||
|
let () =
|
||||||
|
(* run fibers in the background, await them in the main thread *)
|
||||||
|
let@ bg = Fifo_pool.with_ ~num_threads:4 () in
|
||||||
|
let r =
|
||||||
|
F.main @@ fun runner ->
|
||||||
|
let f1 = F.spawn_top ~on:bg (fun () -> 1) in
|
||||||
|
let f2 = F.spawn_top ~on:runner (fun () -> 2) in
|
||||||
|
let f3 = F.spawn_top ~on:bg (fun () -> F.await f1 + 10) in
|
||||||
|
let r = F.await f2 + F.await f3 in
|
||||||
|
assert (r = 13);
|
||||||
|
r
|
||||||
|
in
|
||||||
|
assert (r = 13)
|
||||||
|
|
||||||
|
let () =
|
||||||
|
try
|
||||||
|
let _r =
|
||||||
|
F.main @@ fun _r ->
|
||||||
|
let fib = F.spawn (fun () -> failwith "oops") in
|
||||||
|
F.await fib
|
||||||
|
in
|
||||||
|
|
||||||
|
assert false
|
||||||
|
with Failure msg ->
|
||||||
|
(* Printf.eprintf "got %S\n%!" msg; *)
|
||||||
|
assert (msg = "oops")
|
||||||
Loading…
Add table
Reference in a new issue