From e6456bcfb682113b2b623e9ccd9bcec46626e4ed Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Wed, 4 Dec 2013 12:48:53 +0100 Subject: [PATCH] gdbus-connection: Work around race in connection tests GDBusConnection cleanup is inherently racy due to its use of worker threads. Put tests that expect a NULL G_BUS_TYPE_SESSION singleton as the first tests to work around cleanup races. https://bugzilla.gnome.org/show_bug.cgi?id=719837 --- gio/tests/gdbus-connection.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/gio/tests/gdbus-connection.c b/gio/tests/gdbus-connection.c index a041acbdf..b3a5120f9 100644 --- a/gio/tests/gdbus-connection.c +++ b/gio/tests/gdbus-connection.c @@ -120,6 +120,23 @@ a_gdestroynotify_that_sets_a_gboolean_to_true_and_quits_loop (gpointer user_data g_main_loop_quit (loop); } +static void +test_connection_bus_failure (void) +{ + GDBusConnection *c; + GError *error = NULL; + + /* + * Check for correct behavior when no bus is present + * + */ + c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); + g_assert (error != NULL); + g_assert (!g_dbus_error_is_remote_error (error)); + g_assert (c == NULL); + g_error_free (error); +} + static void test_connection_life_cycle (void) { @@ -136,16 +153,6 @@ test_connection_life_cycle (void) error = NULL; - /* - * Check for correct behavior when no bus is present - * - */ - c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); - g_assert (error != NULL); - g_assert (!g_dbus_error_is_remote_error (error)); - g_assert (c == NULL); - g_error_free (error); - /* * Check for correct behavior when a bus is present */ @@ -1227,6 +1234,9 @@ main (int argc, g_test_dbus_unset (); + /* gdbus cleanup is pretty racy due to worker threads, so always do this test first */ + g_test_add_func ("/gdbus/connection/bus-failure", test_connection_bus_failure); + g_test_add_func ("/gdbus/connection/basic", test_connection_basic); g_test_add_func ("/gdbus/connection/life-cycle", test_connection_life_cycle); g_test_add_func ("/gdbus/connection/send", test_connection_send);