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>
This commit is contained in:
Iain Lane 2014-03-31 11:06:05 +01:00 committed by Simon McVittie
parent 3beb67f9f3
commit fe1a2dc196
4 changed files with 56 additions and 9 deletions

View File

@ -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;

View File

@ -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

View File

@ -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__ */

View File

@ -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;