[glib] gdbus tests: wait up to 60s for gdbus-testserver to take its bus name
- From: Simon McVittie <smcv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gdbus tests: wait up to 60s for gdbus-testserver to take its bus name
- Date: Thu, 14 May 2015 11:42:07 +0000 (UTC)
commit fe1a2dc1965b564727480c8a99740252ea81274b
Author: Iain Lane <iain lane canonical com>
Date: Mon Mar 31 11:06:05 2014 +0100
gdbus tests: wait up to 60s for gdbus-testserver to take its bus name
Previously, we waited up to 0.5s, but that can fail on slow
architectures like ARM; now we wait up to 60s in 0.1s increments.
Patch originally by Simon McVittie <simon mcvittie collabora co uk>,
modified by Iain Lane to be called earlier, to catch all testcases in a
particular test.
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=724113
Reviewed-by: Simon McVittie <simon mcvittie collabora co uk>
Acked-by: Matthias Clasen <mclasen redhat com>
gio/tests/gdbus-connection-loss.c | 3 +-
gio/tests/gdbus-tests.c | 52 +++++++++++++++++++++++++++++++++++++
gio/tests/gdbus-tests.h | 2 +
gio/tests/gdbus-threading.c | 8 +-----
4 files changed, 56 insertions(+), 9 deletions(-)
---
diff --git a/gio/tests/gdbus-connection-loss.c b/gio/tests/gdbus-connection-loss.c
index d807193..8ebb870 100644
--- a/gio/tests/gdbus-connection-loss.c
+++ b/gio/tests/gdbus-connection-loss.c
@@ -124,8 +124,7 @@ main (int argc,
g_assert (g_spawn_command_line_async (path, NULL));
g_free (path);
- /* wait for the service to come up */
- usleep (500 * 1000);
+ ensure_gdbus_testserver_up ();
/* Create the connection in the main thread */
error = NULL;
diff --git a/gio/tests/gdbus-tests.c b/gio/tests/gdbus-tests.c
index 8b64e85..8237dd0 100644
--- a/gio/tests/gdbus-tests.c
+++ b/gio/tests/gdbus-tests.c
@@ -77,6 +77,58 @@ _g_assert_property_notify_run (gpointer object,
return data.timed_out;
}
+static gboolean
+_give_up (gpointer data)
+{
+ g_error ("%s", (const gchar *) data);
+ g_return_val_if_reached (TRUE);
+}
+
+void
+ensure_gdbus_testserver_up (void)
+{
+ guint id;
+ gchar *name_owner;
+ GDBusConnection *connection;
+ GDBusProxy *proxy;
+ GError *error = NULL;
+
+ connection = g_bus_get_sync (G_BUS_TYPE_SESSION,
+ NULL,
+ &error);
+
+ g_assert_no_error (error);
+ error = NULL;
+
+ proxy = g_dbus_proxy_new_sync (connection,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL, /* GDBusInterfaceInfo */
+ "com.example.TestService", /* name */
+ "/com/example/TestObject", /* object path */
+ "com.example.Frob", /* interface */
+ NULL, /* GCancellable */
+ &error);
+ g_assert_no_error (error);
+
+ id = g_timeout_add_seconds (60, _give_up,
+ "waited more than ~ 60s for gdbus-testserver to take its bus name");
+
+ while (TRUE)
+ {
+ name_owner = g_dbus_proxy_get_name_owner (proxy);
+
+ if (name_owner != NULL)
+ break;
+
+ g_main_context_iteration (NULL, TRUE);
+ }
+
+ g_source_remove (id);
+ g_free (name_owner);
+ g_object_unref (proxy);
+ g_object_unref (connection);
+}
+
/* ---------------------------------------------------------------------------------------------------- */
typedef struct
diff --git a/gio/tests/gdbus-tests.h b/gio/tests/gdbus-tests.h
index 538b265..6e31d7b 100644
--- a/gio/tests/gdbus-tests.h
+++ b/gio/tests/gdbus-tests.h
@@ -114,6 +114,8 @@ GDBusConnection *_g_bus_get_priv (GBusType bus_type,
GCancellable *cancellable,
GError **error);
+void ensure_gdbus_testserver_up (void);
+
G_END_DECLS
#endif /* __TESTS_H__ */
diff --git a/gio/tests/gdbus-threading.c b/gio/tests/gdbus-threading.c
index 8d656c6..0e9b8b4 100644
--- a/gio/tests/gdbus-threading.c
+++ b/gio/tests/gdbus-threading.c
@@ -419,7 +419,6 @@ test_method_calls_in_thread (void)
GDBusProxy *proxy;
GDBusConnection *connection;
GError *error;
- gchar *name_owner;
error = NULL;
connection = g_bus_get_sync (G_BUS_TYPE_SESSION,
@@ -437,10 +436,6 @@ test_method_calls_in_thread (void)
&error);
g_assert_no_error (error);
- name_owner = g_dbus_proxy_get_name_owner (proxy);
- g_assert_cmpstr (name_owner, !=, NULL);
- g_free (name_owner);
-
test_method_calls_on_proxy (proxy);
g_object_unref (proxy);
@@ -596,8 +591,7 @@ main (int argc,
g_assert (g_spawn_command_line_async (path, NULL));
g_free (path);
- /* wait for the service to come up */
- usleep (500 * 1000);
+ ensure_gdbus_testserver_up ();
/* Create the connection in the main thread */
error = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]