Skip to content

Commit

Permalink
add a retry mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
zapashcanon committed Jun 13, 2024
1 parent 609d53a commit a25ee62
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions bench/tool/tool.ml
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,23 @@ let fork_and_run_on_file ~i ~fmt ~output_dir ~file ~tool ~timeout =
Bos.OS.Dir.create ~path:true ~mode:0o755 output_dir
in
let dst_stderr = Fpath.(output_dir / "stderr") in
let pid = Unix.fork () in
let result =
if pid = 0 then begin
ExtUnix.Specific.setpgid 0 0;
dup ~dst:Fpath.(output_dir / "stdout") ~src:Unix.stdout;
dup ~dst:dst_stderr ~src:Unix.stderr;
execvp ~output_dir tool file (int_of_float timeout)
end
else begin
wait_pid ~pid ~timeout ~tool ~dst_stderr
end
let rec loop retries =
let pid = Unix.fork () in
if pid = 0 then begin
ExtUnix.Specific.setpgid 0 0;
dup ~dst:Fpath.(output_dir / "stdout") ~src:Unix.stdout;
dup ~dst:dst_stderr ~src:Unix.stderr;
execvp ~output_dir tool file (int_of_float timeout)
end
else begin
match wait_pid ~pid ~timeout ~tool ~dst_stderr with
| (Signaled _ | Stopped _) as result ->
if retries = 0 then result else loop (pred retries)
| result -> result
end
in
loop 3
in
Format.fprintf fmt "%a@\n" Report.Run_result.pp result;
result

0 comments on commit a25ee62

Please sign in to comment.