From 7aa83536af12caa135979b6539aefb74a58db81a Mon Sep 17 00:00:00 2001 From: Iain Lane Date: Fri, 18 Jan 2019 15:20:21 +0000 Subject: [PATCH 1/2] gio/tests/gdbus-proxy: Make `proxy_ready` test start the server after the proxy There's a race here, as revealed by Debian's buildds. We call g_dbus_proxy_new() to create a proxy for the test server, with callback proxy_ready() Then we call g_spawn_command_line_async() to start the test server, and then start the main loop. proxy_ready() assumes that the test server hasn't been started when it is called. But there is no guarantee that these asynchronous operations involving spawning a process won't happen in a different order that mean the bus name *does* have an owner. What we can do is move starting the server inside of proxy_ready(), so we know that the test server isn't started until after the proxy is created. We also add an assertion to check that it is indeed not running before we execute it. --- gio/tests/gdbus-proxy.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gio/tests/gdbus-proxy.c b/gio/tests/gdbus-proxy.c index 8a2c324a2..b8d542429 100644 --- a/gio/tests/gdbus-proxy.c +++ b/gio/tests/gdbus-proxy.c @@ -808,11 +808,19 @@ proxy_ready (GObject *source, { GDBusProxy *proxy; GError *error; + gchar *owner; error = NULL; proxy = g_dbus_proxy_new_for_bus_finish (result, &error); g_assert_no_error (error); + owner = g_dbus_proxy_get_name_owner (proxy); + g_assert_null (owner); + g_free (owner); + + /* this is safe; we explicitly kill the service later on */ + g_assert (g_spawn_command_line_async (g_test_get_filename (G_TEST_BUILT, "gdbus-testserver", NULL), NULL)); + _g_assert_property_notify (proxy, "g-name-owner"); test_basic (proxy); @@ -847,9 +855,6 @@ test_async (void) proxy_ready, NULL); - /* this is safe; testserver will exit once the bus goes away */ - g_assert (g_spawn_command_line_async (g_test_get_filename (G_TEST_BUILT, "gdbus-testserver", NULL), NULL)); - id = g_timeout_add (10000, fail_test, NULL); g_main_loop_run (loop); From 63038d1e4c29428cc94ce9bfcc01eb6e1bcb2b3a Mon Sep 17 00:00:00 2001 From: Iain Lane Date: Fri, 18 Jan 2019 15:26:27 +0000 Subject: [PATCH 2/2] gio/tests/gdbus-proxy: test_proxy: check the server is properly killed We kill the test service at the end of this test. Let's also ensure that the name on the bus goes away and that we are notified about this happening. --- gio/tests/gdbus-proxy.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gio/tests/gdbus-proxy.c b/gio/tests/gdbus-proxy.c index b8d542429..6e092f42b 100644 --- a/gio/tests/gdbus-proxy.c +++ b/gio/tests/gdbus-proxy.c @@ -766,6 +766,7 @@ test_proxy (void) GDBusProxy *proxy; GDBusConnection *connection; GError *error; + gchar *owner; error = NULL; connection = g_bus_get_sync (G_BUS_TYPE_SESSION, @@ -783,7 +784,7 @@ test_proxy (void) &error); g_assert_no_error (error); - /* this is safe; testserver will exit once the bus goes away */ + /* this is safe; we explicitly kill the service later on */ g_assert (g_spawn_command_line_async (g_test_get_filename (G_TEST_BUILT, "gdbus-testserver", NULL), NULL)); _g_assert_property_notify (proxy, "g-name-owner"); @@ -794,8 +795,15 @@ test_proxy (void) test_signals (proxy); test_expected_interface (proxy); - g_object_unref (proxy); 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); + + g_object_unref (proxy); g_object_unref (connection); }