From 2b3a0a6cfeb537c28c7f14b0a8c475d906295ea6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Tue, 13 Aug 2024 10:06:38 +0100 Subject: [PATCH] CI: fix spurious failure on busy system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` 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 --- ocaml/libs/clock/test_timer.ml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ocaml/libs/clock/test_timer.ml b/ocaml/libs/clock/test_timer.ml index 3729826cfa3..b94a3c470d2 100644 --- a/ocaml/libs/clock/test_timer.ml +++ b/ocaml/libs/clock/test_timer.ml @@ -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, \