From 375943ea215871c0fe6d1d02e970cb2d71c8445c Mon Sep 17 00:00:00 2001 From: Mike Gorse Date: Thu, 26 Apr 2012 16:06:34 -0500 Subject: [PATCH] Fix the gdbus-proxy async test The async test had several problems: - It created a proxy and did not launch a main loop, meaning that its callback would usually not get called, or, if it did get called, the test harness would have taken down the connection already, causing an assertion failure when the proxy had an error. - It was dependent on the proxy test to set up the server and would fail because some properties were modified by that test. https://bugzilla.gnome.org/show_bug.cgi?id=674805 --- gio/tests/gdbus-proxy.c | 47 +++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/gio/tests/gdbus-proxy.c b/gio/tests/gdbus-proxy.c index 0d3866644..255e85584 100644 --- a/gio/tests/gdbus-proxy.c +++ b/gio/tests/gdbus-proxy.c @@ -732,6 +732,30 @@ test_basic (GDBusProxy *proxy) g_object_unref (connection); } +static void +kill_test_service (GDBusConnection *connection) +{ + guint pid; + GVariant *ret; + GError *error = NULL; + const gchar *name = "com.example.TestService"; + + ret = g_dbus_connection_call_sync (connection, + "org.freedesktop.DBus", + "/org/freedesktop/DBus", + "org.freedesktop.DBus", + "GetConnectionUnixProcessID", + g_variant_new ("(s)", name), + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + g_variant_get (ret, "(u)", &pid); + g_variant_unref (ret); + kill (pid, SIGTERM); +} + static void test_proxy (void) { @@ -767,6 +791,7 @@ test_proxy (void) test_expected_interface (proxy); g_object_unref (proxy); + kill_test_service (connection); g_object_unref (connection); } @@ -784,13 +809,23 @@ proxy_ready (GObject *source, proxy = g_dbus_proxy_new_for_bus_finish (result, &error); g_assert_no_error (error); + _g_assert_property_notify (proxy, "g-name-owner"); + test_basic (proxy); test_methods (proxy); test_properties (proxy); test_signals (proxy); test_expected_interface (proxy); + kill_test_service (g_dbus_proxy_get_connection (proxy)); g_object_unref (proxy); + g_main_loop_quit (loop); +} + +static gboolean +fail_test (gpointer user_data) +{ + g_assert_not_reached (); } static void @@ -807,6 +842,12 @@ test_async (void) NULL, /* GCancellable */ proxy_ready, NULL); + + /* this is safe; testserver will exit once the bus goes away */ + g_assert (g_spawn_command_line_async (SRCDIR "/gdbus-testserver.py", NULL)); + + g_timeout_add (10000, fail_test, NULL); + g_main_loop_run (loop); } static void @@ -831,12 +872,6 @@ test_no_properties (void) g_object_unref (proxy); } -static gboolean -fail_test (gpointer user_data) -{ - g_assert_not_reached (); -} - static void check_error (GObject *source, GAsyncResult *result,