Package: glib2.0 / 2.42.1-1

gdbus-tests-wait-up-to-60s-for-gdbus-testserver-to-t.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
From 2a5467bcd3869e0d8e7ca21294763341f133c6c1 Mon Sep 17 00:00:00 2001
From: Iain Lane <iain.lane@canonical.com>
Date: Mon, 31 Mar 2014 11:06:05 +0100
Subject: [PATCH] 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.

https://bugzilla.gnome.org/show_bug.cgi?id=724113
---
 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(-)

--- a/gio/tests/gdbus-connection-loss.c
+++ b/gio/tests/gdbus-connection-loss.c
@@ -124,8 +124,7 @@
   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;
--- a/gio/tests/gdbus-tests.c
+++ b/gio/tests/gdbus-tests.c
@@ -77,6 +77,58 @@
   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
--- a/gio/tests/gdbus-tests.h
+++ b/gio/tests/gdbus-tests.h
@@ -114,6 +114,8 @@
                                   GCancellable       *cancellable,
                                   GError            **error);
 
+void ensure_gdbus_testserver_up (void);
+
 G_END_DECLS
 
 #endif /* __TESTS_H__ */
--- a/gio/tests/gdbus-threading.c
+++ b/gio/tests/gdbus-threading.c
@@ -421,7 +421,6 @@
   GDBusProxy *proxy;
   GDBusConnection *connection;
   GError *error;
-  gchar *name_owner;
 
   error = NULL;
   connection = g_bus_get_sync (G_BUS_TYPE_SESSION,
@@ -439,10 +438,6 @@
                                  &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);
@@ -598,8 +593,7 @@
   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;