Skip to content

Commit

Permalink
Merge pull request #5559 from freddy77/elapsed_test
Browse files Browse the repository at this point in the history
  • Loading branch information
psafont authored Apr 15, 2024
2 parents 4cdebd7 + d26f0b8 commit 5b59bc6
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions ocaml/forkexecd/test/fe_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,23 @@ let test_delay () =
let start = Unix.gettimeofday () in
let exe = Printf.sprintf "/proc/%d/exe" (Unix.getpid ()) in
let args = ["sleep"] in
(* Need to have fractional part because some internal usage split integer
and fractional and do computation.
Better to have a high fractional part (> 0.5) to more probably exceed
the unit.
*)
let timeout = 1.7 in
try
Forkhelpers.execute_command_get_output ~timeout:4.0 exe args |> ignore ;
Forkhelpers.execute_command_get_output ~timeout exe args |> ignore ;
failwith "Failed to timeout"
with
| Forkhelpers.Subprocess_timeout ->
Printf.printf "Caught timeout exception after %f seconds\n%!"
(Unix.gettimeofday () -. start) ;
()
let elapsed = Unix.gettimeofday () -. start in
Printf.printf "Caught timeout exception after %f seconds\n%!" elapsed ;
if elapsed < timeout then
failwith "Process exited too soon" ;
if elapsed > timeout +. 0.2 then
failwith "Excessive time elapsed"
| e ->
failwith
(Printf.sprintf "Failed with unexpected exception: %s"
Expand Down Expand Up @@ -261,7 +270,7 @@ let slave = function
pid (List.length filtered) ls
)

let sleep () = Unix.sleep 5 ; Printf.printf "Ok\n"
let sleep () = Unix.sleep 3 ; Printf.printf "Ok\n"

let echo out err =
if out <> "" then print_endline out ;
Expand Down

0 comments on commit 5b59bc6

Please sign in to comment.