[glib: 1/2] tests: Wait for gdbus-testserver to die when killing it




commit 511c5f5bf03a1eb3ef617c1eb6e3fdf29e52c5e7
Author: Philip Withnall <pwithnall endlessos org>
Date:   Tue Nov 16 22:47:15 2021 +0000

    tests: Wait for gdbus-testserver to die when killing it
    
    This was previously done (by commit 63038d1e4c) in one of the cases
    where `kill_test_service()` was called — but not the other.
    
    This meant that one instance of `gdbus-testserver` could still be
    around when (as it happens, due to the order of the tests) the
    `/gdbus/proxy/no-match-rule` test was run. It would start a second
    instance of `gdbus-testserver`, which would exit early due to the test
    name still being owned on the bus. The first (killed) instance of
    `gdbus-testserver` would then exit, leaving no test servers running, and
    hence the new test would fail.
    
    This was being seen as frequent CI failures, particularly on FreeBSD
    (must have slightly different timing for process signalling and
    termination from Linux).
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 gio/tests/gdbus-proxy.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
---
diff --git a/gio/tests/gdbus-proxy.c b/gio/tests/gdbus-proxy.c
index a16d70c20..eed75acf4 100644
--- a/gio/tests/gdbus-proxy.c
+++ b/gio/tests/gdbus-proxy.c
@@ -733,6 +733,16 @@ test_basic (GDBusProxy *proxy)
   g_object_unref (connection);
 }
 
+static void
+name_disappeared_cb (GDBusConnection *connection,
+                     const gchar     *name,
+                     gpointer         user_data)
+{
+  gboolean *name_disappeared = user_data;
+  *name_disappeared = TRUE;
+  g_main_context_wakeup (NULL);
+}
+
 static void
 kill_test_service (GDBusConnection *connection)
 {
@@ -741,6 +751,8 @@ kill_test_service (GDBusConnection *connection)
   GVariant *ret;
   GError *error = NULL;
   const gchar *name = "com.example.TestService";
+  guint watch_id;
+  gboolean name_disappeared = FALSE;
 
   ret = g_dbus_connection_call_sync (connection,
                                      "org.freedesktop.DBus",
@@ -755,7 +767,18 @@ kill_test_service (GDBusConnection *connection)
                                      &error);
   g_variant_get (ret, "(u)", &pid);
   g_variant_unref (ret);
+
+  /* Watch the name and wait until it’s disappeared. */
+  watch_id = g_bus_watch_name_on_connection (connection, name,
+                                             G_BUS_NAME_WATCHER_FLAGS_NONE,
+                                             NULL, name_disappeared_cb,
+                                             &name_disappeared, NULL);
   kill (pid, SIGTERM);
+
+  while (!name_disappeared)
+    g_main_context_iteration (NULL, TRUE);
+
+  g_bus_unwatch_name (watch_id);
 #else
   g_warning ("Can't kill com.example.TestService");
 #endif
@@ -798,8 +821,6 @@ test_proxy_with_flags (GDBusProxyFlags flags)
 
   kill_test_service (connection);
 
-  _g_assert_property_notify (proxy, "g-name-owner");
-
   owner = g_dbus_proxy_get_name_owner (proxy);
   g_assert_null (owner);
   g_free (owner);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]