Skip to content

tests: Reduce wakeup interval in gdbus-threading

When checking that the connection has the expected number of refs, the test would block on a GMainContext iteration for up to 3s before waking up and failing (if the refcount was still not as expected).

This check was written in the expectation that changing the refcount of the connection would only happen due to dispatching a source on GMainContext — hence the GMainContext would wake up as the refcount changed.

That’s probably not actually true though. It might be the case that the connection’s refcount is changed on from the GDBus worker thread, which would not cause any wakeups on the main thread’s GMainContext.

In this case, the GMainContext iteration in assert_connection_has_one_ref() would block for the full 3s, and then wake up and notice the refcount is correct (then the test would proceed).

That’s fine, apart from the fact that test_threaded_singleton() does this 1000 times. If the slow case is hit on a significant number of those test runs, the test will take around 3000s to complete, which is significantly more than meson’s test timeout of 360s. So the test fails with something like:

220/266 glib:gio+slow / gdbus-threading         TIMEOUT 360.07 s

--- command ---
G_TEST_SRCDIR='/builds/GNOME/glib/gio/tests' GIO_MODULE_DIR='' G_TEST_BUILDDIR='/builds/GNOME/glib/_build/gio/tests' /builds/GNOME/glib/_build/gio/tests/gdbus-threading
--- stdout ---
\# random seed: R02S83fe8de22db4d4f376e6d179e2bdd601
1..3
\# Start of gdbus tests
ok 1 /gdbus/delivery-in-thread
ok 2 /gdbus/method-calls-in-thread
\# GLib-GIO-DEBUG: refcount of 0x5602de913660 is not right (3 rather than 1) in test_threaded_singleton(), sleeping
\# GLib-GIO-DEBUG: refcount of 0x5602de913660 is not right (3 rather than 1) in test_threaded_singleton(), sleeping
\# GLib-GIO-DEBUG: refcount of 0x5602de913c60 is not right (3 rather than 1) in test_threaded_singleton(), sleeping
\# GLib-GIO-DEBUG: refcount of 0x5602de913c60 is not right (3 rather than 1) in test_threaded_singleton(), sleeping
\# GLib-GIO-DEBUG: refcount of 0x5602de913260 is not right (3 rather than 1) in test_threaded_singleton(), sleeping
\# GLib-GIO-DEBUG: refcount of 0x5602de913260 is not right (3 rather than 1) in test_threaded_singleton(), sleeping

From this log, it can be seen that the sleep is happening on a different GMainContext every other time, so the test is making progress.

Assuming this is a correct diagnosis (it’s a lot of guessing), this commit tries to fix the test by adding a wakeup timeout to the GMainContext in assert_connection_has_one_ref(), which will wake it up every 50ms to re-check the exit condition.

This polling approach has been taken because it doesn’t seem feasible to make sure that every g_object_ref()/g_object_unref() call on a GDBusConnection causes the main context to wake up.

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

Merge request reports