Skip to content

Commit

Permalink
fix: more reliable wait_pids in test
Browse files Browse the repository at this point in the history
  • Loading branch information
leostera committed Mar 21, 2024
1 parent a9c585e commit 1d2fe96
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
10 changes: 6 additions & 4 deletions riot/runtime/import.ml
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,12 @@ let wait_pids pids =
(* And we can enter the receive loop, filtering out the pids as they come.
When the list of pids becomes empty, we exit the recursion. *)
let rec do_wait pids =
match receive ~selector () with
| Process_down pid ->
let pids = List.filter (fun pid' -> not (Pid.equal pid' pid)) pids in
if List.length pids = 0 then () else do_wait pids
if List.length pids = 0 then ()
else
match receive ~selector () with
| Process_down pid ->
let pids = List.filter (fun pid' -> not (Pid.equal pid' pid)) pids in
do_wait pids
in
do_wait pids

Expand Down
11 changes: 6 additions & 5 deletions test/link_processes_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ let main () =
loop ())
in

List.iter monitor [ pid1; pid2 ];

sleep 0.5;
(* once we send this exit signal to pid1, and it dies, it should take pid2 down with it *)
exit pid1 Normal;
let _ =
spawn (fun () ->
sleep 0.5;
(* once we send this exit signal to pid1, and it dies, it should take pid2 down with it *)
exit pid1 Normal)
in

(* so we'll wait for both pids to be dead *)
wait_pids [ pid1; pid2 ];
Expand Down

0 comments on commit 1d2fe96

Please sign in to comment.