Skip to content

Commit abb2fea

Browse files
committed
Use a quota when running tests with FIFO schedulers
The quota is selected from the range [1, 100]: - A quota of 1 is an edge case worth testing. - A quota of 100 is high enough that fibers are unlikely to encounter it during most tests. This also changes the test scheduler to print details on the scheduler in case the `main` raises.
1 parent 7c20b53 commit abb2fea

File tree

1 file changed

+47
-29
lines changed

1 file changed

+47
-29
lines changed

test/test_scheduler.ocaml5.ml

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,53 @@ let rec run_fiber ?(max_domains = 1) ?(allow_lwt = true) ?fatal_exn_handler
2727
| _ -> `Lwt
2828
in
2929
let n_domains = Int.min max_domains (Domain.recommended_domain_count ()) in
30-
ignore
31-
(match scheduler with
32-
| `Fifos -> "fifos"
33-
| `Multififos -> "multififos"
34-
| `Randos -> "randos"
35-
| `Lwt -> "lwt");
36-
match scheduler with
37-
| `Lwt ->
38-
if Picos_thread.is_main_thread () && allow_lwt then begin
39-
let old_hook = !Lwt.async_exception_hook in
40-
begin
41-
match fatal_exn_handler with
42-
| None -> ()
43-
| Some hook -> Lwt.async_exception_hook := hook
44-
end;
45-
match Lwt_main.run (Picos_lwt_unix.run_fiber fiber main) with
46-
| result ->
47-
Lwt.async_exception_hook := old_hook;
48-
result
49-
| exception exn ->
50-
Lwt.async_exception_hook := old_hook;
51-
raise exn
52-
end
53-
else run_fiber ~max_domains ~allow_lwt fiber main
54-
| `Randos ->
55-
Picos_randos.run_fiber_on ?fatal_exn_handler ~n_domains fiber main
56-
| `Fifos -> Picos_fifos.run_fiber ?fatal_exn_handler fiber main
57-
| `Multififos ->
58-
Picos_multififos.run_fiber_on ?fatal_exn_handler ~n_domains fiber main
30+
let quota = 1 + Random.int 100 in
31+
match
32+
match scheduler with
33+
| `Lwt ->
34+
if Picos_thread.is_main_thread () && allow_lwt then
35+
Some
36+
(fun () ->
37+
let old_hook = !Lwt.async_exception_hook in
38+
begin
39+
match fatal_exn_handler with
40+
| None -> ()
41+
| Some hook -> Lwt.async_exception_hook := hook
42+
end;
43+
match Lwt_main.run (Picos_lwt_unix.run_fiber fiber main) with
44+
| result ->
45+
Lwt.async_exception_hook := old_hook;
46+
result
47+
| exception exn ->
48+
Lwt.async_exception_hook := old_hook;
49+
raise exn)
50+
else None
51+
| `Randos ->
52+
Some
53+
(fun () ->
54+
Picos_randos.run_fiber_on ?fatal_exn_handler ~n_domains fiber main)
55+
| `Fifos ->
56+
Some
57+
(fun () -> Picos_fifos.run_fiber ~quota ?fatal_exn_handler fiber main)
58+
| `Multififos ->
59+
Some
60+
(fun () ->
61+
Picos_multififos.run_fiber_on ~quota ?fatal_exn_handler ~n_domains
62+
fiber main)
63+
with
64+
| None -> run_fiber ~max_domains ~allow_lwt ?fatal_exn_handler fiber main
65+
| Some run -> begin
66+
try run ()
67+
with exn ->
68+
Printf.printf "Test_scheduler: %s ~quota:%d ~n_domains:%d\n%!"
69+
(match scheduler with
70+
| `Fifos -> "fifos"
71+
| `Multififos -> "multififos"
72+
| `Randos -> "randos"
73+
| `Lwt -> "lwt")
74+
quota n_domains;
75+
raise exn
76+
end
5977

6078
let run ?max_domains ?allow_lwt ?fatal_exn_handler ?(forbid = false) main =
6179
let computation = Computation.create ~mode:`LIFO () in

0 commit comments

Comments
 (0)