Merge branch 'test-failure-gdbus-proxy' into 'main'

tests: Wait for gdbus-testserver to die when killing it

See merge request GNOME/glib!2341
This commit is contained in:
Sebastian Dröge 2021-11-17 07:45:51 +00:00
commit e7e2949f31

View File

@ -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 its 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);