From ded4e7e0256dd1a99e7acc025ede0e7f57436c8b Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 6 May 2024 21:24:53 +0100 Subject: [PATCH] gdbus-proxy test: Wait before asserting name owner has gone away GDBusConnection sends each signal to recipients in a separate idle callback, and there's no particular guarantee about the order in which they're scheduled or dispatched. For the NameOwnerChanged signal that reports the name becoming unowned, it's possible that g_bus_watch_name() gets its idle callback called before the GDBusProxy:g-name-owner machinery has updated the name owner, in which case the assertion will fail. Fixing GNOME/glib#3268 introduced a new subscription to NameOwnerChanged which can alter the order of delivery, particularly in the case where G_DBUS_PROXY_FLAGS_NO_MATCH_RULE was used (as tested in /gdbus/proxy/no-match-rule). The resulting test failure is intermittent, but reliably appears within 100 repetitions of that test. Fixes: 511c5f5b "tests: Wait for gdbus-testserver to die when killing it" Signed-off-by: Simon McVittie --- gio/tests/gdbus-proxy.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gio/tests/gdbus-proxy.c b/gio/tests/gdbus-proxy.c index ac5f720fa..ab36eae0e 100644 --- a/gio/tests/gdbus-proxy.c +++ b/gio/tests/gdbus-proxy.c @@ -780,6 +780,12 @@ kill_test_service (GDBusConnection *connection) while (!name_disappeared) g_main_context_iteration (NULL, TRUE); + /* GDBusConnection doesn't guarantee that different subscriptions to the + * same signal will get their callbacks scheduled in any particular order, + * so make sure they have all happened */ + while (g_main_context_iteration (NULL, FALSE)) + continue; + g_bus_unwatch_name (watch_id); #else g_warning ("Can't kill com.example.TestService");