mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
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>
This commit is contained in:
parent
743b600311
commit
511c5f5bf0
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user