Skip to content

Commit

Permalink
CI: fix spurious failure on busy system
Browse files Browse the repository at this point in the history
```
File "ocaml/libs/clock/dune", line 27, characters 19-33:
27 |   (names test_date test_timer_run)
                        ^^^^^^^^^^^^^^                                                                                                                                       qcheck random seed: 423397317                                                                                                                                                Testing `Timer'.                                                                                                                                                             This run has ID `D009HP55'.                                                      �[<35;18;6M
F.............

┌──────────────────────────────────────────────────────────────────────────────┐
│ [FAIL]        Timer          0   Timer.remaining.                            │
└──────────────────────────────────────────────────────────────────────────────┘
Sleeping for 0.150000 seconds...
Sleeping for 0.000500 seconds...

test `Timer.remaining` failed on ≥ 1 cases:
1ms
Expected to have spare time, but got excess: 1.91μs. Duration: 1ms, actual: 999μs, timer:
elapsed: 1.03ms
duration: 1ms
```

Here we asked for a sleep of 0.5ms, but got woken up twice as late.
And the quickcheck property was expecting that the actual wake up time won't be twice as wrong.
In reality it can wake up by arbitrary amounts of time later based on how busy the OS is,
but we do need to check that the wakeups are not completely wrong.

So skip the check on very short durations, but keep it on the longer 100ms and 300ms tests.

Signed-off-by: Edwin Török <[email protected]>
  • Loading branch information
edwintorok committed Aug 13, 2024
1 parent f72aff2 commit 2b3a0a6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ocaml/libs/clock/test_timer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ let test_timer_remaining =
(not (Timer.span_is_shorter Mtime.Span.(2 * actual) ~than:duration)) ;
let () =
match Timer.remaining timer with
| Expired _ when half < 0.05 ->
(* OS timer may not be accurate for very short sleeps,
or the system might be busy.
Skip the strict test on very short durations, we'll still test this on the 100ms+ ones.
*)
()
| Expired t ->
Test.fail_reportf
"Expected to have spare time, but got excess: %a. Duration: %a, \
Expand Down

0 comments on commit 2b3a0a6

Please sign in to comment.