Skip to content

tests: Fix an intermittent timing error with testing g_usleep(0)

Philip Withnall requested to merge pwithnall/glib:timer-test-fix into main

The code to test that g_usleep(0) returns immediately assumes that g_usleep(1) always takes longer, but that’s not necessarily always the case. Even if no sleeping happens, the function call for g_usleep(0) could get descheduled and take longer than normal.

This results in occasional failures like this one:

GLib:ERROR:../glib/tests/timer.c:367:test_usleep_with_zero_wait: assertion failed (elapsed0 <= elapsed1): (0.000206 <= 0.000202)

(Source: https://gitlab.gnome.org/GNOME/glib/-/jobs/2898468)

I can’t think of a suitable invariant comparison which can be done with the timers, but running the comparison 10 times and allowing it to fail once should work. A probabilistic test of g_usleep(0).

Signed-off-by: Philip Withnall pwithnall@endlessos.org

Merge request reports