mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-09 04:35:33 -05:00
update tests
This commit is contained in:
parent
37751c79e4
commit
4325fda345
2 changed files with 23 additions and 23 deletions
|
|
@ -49,22 +49,21 @@ let logf = Log_.logf
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
Printf.printf "============\nstart\n";
|
Printf.printf "============\nstart\n";
|
||||||
|
let@ nursery = F.Nursery.with_create_top ~on:runner () in
|
||||||
let clock = ref TS.init in
|
let clock = ref TS.init in
|
||||||
let fib =
|
let fib =
|
||||||
F.spawn_top ~on:runner @@ fun () ->
|
F.spawn nursery @@ fun nursery ->
|
||||||
let subs =
|
let subs =
|
||||||
List.init 5 (fun i ->
|
List.init 5 (fun i ->
|
||||||
F.spawn_link ~protect:false @@ fun () ->
|
F.spawn nursery ~protect:false @@ fun _n ->
|
||||||
Thread.delay (float i *. 0.01);
|
Thread.delay (float i *. 0.01);
|
||||||
i)
|
i)
|
||||||
in
|
in
|
||||||
|
|
||||||
ignore
|
F.spawn_ignore nursery ~protect:false (fun _n ->
|
||||||
(F.spawn_link ~protect:false @@ fun () ->
|
|
||||||
Thread.delay 0.4;
|
Thread.delay 0.4;
|
||||||
TS.tick clock;
|
TS.tick clock;
|
||||||
logf !clock "other fib done"
|
logf !clock "other fib done");
|
||||||
: _ F.t);
|
|
||||||
|
|
||||||
logf (TS.tick_get clock) "wait for subs";
|
logf (TS.tick_get clock) "wait for subs";
|
||||||
List.iteri
|
List.iteri
|
||||||
|
|
@ -92,8 +91,9 @@ let () =
|
||||||
Printf.printf "============\nstart\n";
|
Printf.printf "============\nstart\n";
|
||||||
|
|
||||||
let clock = ref TS.init in
|
let clock = ref TS.init in
|
||||||
|
let@ nursery = F.Nursery.with_create_top ~on:runner () in
|
||||||
let fib =
|
let fib =
|
||||||
F.spawn_top ~on:runner @@ fun () ->
|
F.spawn nursery @@ fun nursery ->
|
||||||
let@ () =
|
let@ () =
|
||||||
F.with_self_cancel_callback (fun ebt ->
|
F.with_self_cancel_callback (fun ebt ->
|
||||||
logf (TS.tick_get clock) "main fiber cancelled with %s"
|
logf (TS.tick_get clock) "main fiber cancelled with %s"
|
||||||
|
|
@ -104,7 +104,7 @@ let () =
|
||||||
let subs =
|
let subs =
|
||||||
List.init 10 (fun i ->
|
List.init 10 (fun i ->
|
||||||
let clock = ref (0 :: i :: !clock) in
|
let clock = ref (0 :: i :: !clock) in
|
||||||
F.spawn_link ~protect:false @@ fun () ->
|
F.spawn nursery ~protect:false @@ fun _n ->
|
||||||
let@ () =
|
let@ () =
|
||||||
F.with_self_cancel_callback (fun _ ->
|
F.with_self_cancel_callback (fun _ ->
|
||||||
logf (TS.tick_get clock) "sub-fiber %d was cancelled" i)
|
logf (TS.tick_get clock) "sub-fiber %d was cancelled" i)
|
||||||
|
|
@ -126,11 +126,9 @@ let () =
|
||||||
| Error _ -> logf (i :: post) "fiber %d resolved as error" i))
|
| Error _ -> logf (i :: post) "fiber %d resolved as error" i))
|
||||||
subs;
|
subs;
|
||||||
|
|
||||||
ignore
|
F.spawn_ignore nursery ~protect:false (fun _n ->
|
||||||
(F.spawn_link ~protect:false @@ fun () ->
|
|
||||||
Thread.delay 0.2;
|
Thread.delay 0.2;
|
||||||
logf (TS.tick_get clock) "other fib done"
|
logf (TS.tick_get clock) "other fib done");
|
||||||
: _ F.t);
|
|
||||||
|
|
||||||
logf (TS.tick_get clock) "wait for subs";
|
logf (TS.tick_get clock) "wait for subs";
|
||||||
List.iteri
|
List.iteri
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,7 @@ module Render = struct
|
||||||
end
|
end
|
||||||
|
|
||||||
let run ~pool ~pool_name () =
|
let run ~pool ~pool_name () =
|
||||||
|
let@ nursery = F.Nursery.with_create_top ~on:pool () in
|
||||||
let tracer = Tracer.create () in
|
let tracer = Tracer.create () in
|
||||||
|
|
||||||
let sub_sub_child ~idx ~idx_child ~idx_sub ~idx_sub_sub () =
|
let sub_sub_child ~idx ~idx_child ~idx_sub ~idx_sub_sub () =
|
||||||
|
|
@ -110,7 +111,7 @@ let run ~pool ~pool_name () =
|
||||||
done
|
done
|
||||||
in
|
in
|
||||||
|
|
||||||
let sub_child ~idx ~idx_child ~idx_sub () =
|
let sub_child ~idx ~idx_child ~idx_sub nursery =
|
||||||
let@ () =
|
let@ () =
|
||||||
Tracer.with_span tracer (spf "child_%d.%d.%d" idx idx_child idx_sub)
|
Tracer.with_span tracer (spf "child_%d.%d.%d" idx idx_child idx_sub)
|
||||||
in
|
in
|
||||||
|
|
@ -122,19 +123,19 @@ let run ~pool ~pool_name () =
|
||||||
|
|
||||||
let subs =
|
let subs =
|
||||||
List.init 2 (fun idx_sub_sub ->
|
List.init 2 (fun idx_sub_sub ->
|
||||||
F.spawn_link ~protect:true (fun () ->
|
F.spawn ~protect:true nursery (fun _nursery ->
|
||||||
sub_sub_child ~idx ~idx_child ~idx_sub ~idx_sub_sub ()))
|
sub_sub_child ~idx ~idx_child ~idx_sub ~idx_sub_sub ()))
|
||||||
in
|
in
|
||||||
List.iter F.await subs
|
List.iter F.await subs
|
||||||
in
|
in
|
||||||
|
|
||||||
let top_child ~idx ~idx_child () =
|
let top_child ~idx ~idx_child nursery =
|
||||||
let@ () = Tracer.with_span tracer (spf "child.%d.%d" idx idx_child) in
|
let@ () = Tracer.with_span tracer (spf "child.%d.%d" idx idx_child) in
|
||||||
|
|
||||||
let subs =
|
let subs =
|
||||||
List.init 2 (fun k ->
|
List.init 2 (fun k ->
|
||||||
F.spawn_link ~protect:true @@ fun () ->
|
F.spawn nursery ~protect:true @@ fun nursery ->
|
||||||
sub_child ~idx ~idx_child ~idx_sub:k ())
|
sub_child ~idx ~idx_child ~idx_sub:k nursery)
|
||||||
in
|
in
|
||||||
|
|
||||||
let@ () =
|
let@ () =
|
||||||
|
|
@ -144,12 +145,13 @@ let run ~pool ~pool_name () =
|
||||||
List.iter F.await subs
|
List.iter F.await subs
|
||||||
in
|
in
|
||||||
|
|
||||||
let top idx =
|
let top nursery idx =
|
||||||
let@ () = Tracer.with_span tracer (spf "top_%d" idx) in
|
let@ () = Tracer.with_span tracer (spf "top_%d" idx) in
|
||||||
|
|
||||||
let subs =
|
let subs =
|
||||||
List.init 5 (fun j ->
|
List.init 5 (fun j ->
|
||||||
F.spawn_link ~protect:true @@ fun () -> top_child ~idx ~idx_child:j ())
|
F.spawn nursery ~protect:true @@ fun nursery ->
|
||||||
|
top_child ~idx ~idx_child:j nursery)
|
||||||
in
|
in
|
||||||
|
|
||||||
List.iter F.await subs
|
List.iter F.await subs
|
||||||
|
|
@ -157,7 +159,7 @@ let run ~pool ~pool_name () =
|
||||||
|
|
||||||
Printf.printf "run test on pool = %s\n" pool_name;
|
Printf.printf "run test on pool = %s\n" pool_name;
|
||||||
let fibs =
|
let fibs =
|
||||||
List.init 8 (fun idx -> F.spawn_top ~on:pool (fun () -> top idx))
|
List.init 8 (fun idx -> F.spawn nursery (fun nursery -> top nursery idx))
|
||||||
in
|
in
|
||||||
List.iter F.wait_block_exn fibs;
|
List.iter F.wait_block_exn fibs;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue