summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosep Puigdemont <josep.puigdemont@enea.com>2013-05-21 16:46:25 +0200
committerColin Walters <walters@verbum.org>2013-05-21 11:18:08 -0400
commitc9cc0beb3a8c298b843efdb71822a71cc078a8ac (patch)
tree3cf348042c2f521cb39757250ab6a4b91f5cf794
parent4edc2f1a9330006a5d615bc16264b5328da6fe66 (diff)
downloadglib-c9cc0beb3a8c298b843efdb71822a71cc078a8ac.tar.gz
Timeout the test if dbus sevice has not appeared in due time.
The test /gdbus/connection/large_message waits for a dbus name to appear. The dbus name is created by a another process executed in the background. If for some reason this fails, the test will likely wait forever. This will avoid this situation by making the test fail if the dbus service has not appeared after 10 seconds. https://bugzilla.gnome.org/show_bug.cgi?id=698981
-rw-r--r--gio/tests/gdbus-connection-slow.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/gio/tests/gdbus-connection-slow.c b/gio/tests/gdbus-connection-slow.c
index 889a75eff..e4b79df12 100644
--- a/gio/tests/gdbus-connection-slow.c
+++ b/gio/tests/gdbus-connection-slow.c
@@ -120,6 +120,18 @@ test_connection_flush (void)
* is fragmented when shoved across any transport
*/
#define LARGE_MESSAGE_STRING_LENGTH (20*1024*1024)
+/* the test will fail if the service name has not appeared after this amount of seconds */
+#define LARGE_MESSAGE_TIMEOUT_SECONDS 10
+
+static gboolean
+large_message_timeout_cb (gpointer data)
+{
+ (void)data;
+
+ g_error ("Error: timeout waiting for dbus name to appear\n");
+
+ return FALSE;
+}
static void
large_message_on_name_appeared (GDBusConnection *connection,
@@ -133,6 +145,8 @@ large_message_on_name_appeared (GDBusConnection *connection,
GVariant *result;
guint n;
+ g_assert (g_source_remove (GPOINTER_TO_UINT (user_data)));
+
request = g_new (gchar, LARGE_MESSAGE_STRING_LENGTH + 1);
for (n = 0; n < LARGE_MESSAGE_STRING_LENGTH; n++)
request[n] = '0' + (n%10);
@@ -175,6 +189,7 @@ test_connection_large_message (void)
{
guint watcher_id;
gchar *path;
+ guint timeout_id;
session_bus_up ();
@@ -183,12 +198,16 @@ test_connection_large_message (void)
g_assert (g_spawn_command_line_async (path, NULL));
g_free (path);
+ timeout_id = g_timeout_add_seconds (LARGE_MESSAGE_TIMEOUT_SECONDS,
+ large_message_timeout_cb,
+ NULL);
+
watcher_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
"com.example.TestService",
G_BUS_NAME_WATCHER_FLAGS_NONE,
large_message_on_name_appeared,
large_message_on_name_vanished,
- NULL, /* user_data */
+ GUINT_TO_POINTER (timeout_id), /* user_data */
NULL); /* GDestroyNotify */
g_main_loop_run (loop);
g_bus_unwatch_name (watcher_id);