tests: Take explicit connection and context when ensuring testserver up

This introduces no functional changes, but makes the code a little more
explicit about which connection and main context it’s operating on.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1515
This commit is contained in:
Philip Withnall 2020-02-20 11:49:12 +00:00
parent 1a51681e6d
commit b2e543f6a4
4 changed files with 20 additions and 19 deletions

View File

@ -124,14 +124,14 @@ main (int argc,
g_assert (g_spawn_command_line_async (path, NULL));
g_free (path);
ensure_gdbus_testserver_up ();
/* Create the connection in the main thread */
error = NULL;
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
g_assert_no_error (error);
g_assert (c != NULL);
ensure_gdbus_testserver_up (c, NULL);
g_test_add_func ("/gdbus/connection-loss", test_connection_loss);
ret = g_test_run();

View File

@ -87,20 +87,15 @@ _give_up (gpointer data)
}
void
ensure_gdbus_testserver_up (void)
ensure_gdbus_testserver_up (GDBusConnection *connection,
GMainContext *context)
{
guint id;
gchar *name_owner;
GDBusConnection *connection;
GSource *timeout_source = NULL;
GDBusProxy *proxy;
GError *error = NULL;
connection = g_bus_get_sync (G_BUS_TYPE_SESSION,
NULL,
&error);
g_assert_no_error (error);
error = NULL;
g_main_context_push_thread_default (context);
proxy = g_dbus_proxy_new_sync (connection,
G_DBUS_PROXY_FLAGS_NONE,
@ -112,8 +107,11 @@ ensure_gdbus_testserver_up (void)
&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");
timeout_source = g_timeout_source_new_seconds (60);
g_source_set_callback (timeout_source, _give_up,
"waited more than ~ 60s for gdbus-testserver to take its bus name",
NULL);
g_source_attach (timeout_source, context);
while (TRUE)
{
@ -122,13 +120,15 @@ ensure_gdbus_testserver_up (void)
if (name_owner != NULL)
break;
g_main_context_iteration (NULL, TRUE);
g_main_context_iteration (context, TRUE);
}
g_source_remove (id);
g_source_destroy (timeout_source);
g_source_unref (timeout_source);
g_free (name_owner);
g_object_unref (proxy);
g_object_unref (connection);
g_main_context_pop_thread_default (context);
}
/* ---------------------------------------------------------------------------------------------------- */

View File

@ -114,7 +114,8 @@ GDBusConnection *_g_bus_get_priv (GBusType bus_type,
GCancellable *cancellable,
GError **error);
void ensure_gdbus_testserver_up (void);
void ensure_gdbus_testserver_up (GDBusConnection *connection,
GMainContext *context);
G_END_DECLS

View File

@ -603,14 +603,14 @@ main (int argc,
g_assert_true (g_spawn_command_line_async (path, NULL));
g_free (path);
ensure_gdbus_testserver_up ();
/* Create the connection in the main thread */
error = NULL;
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
g_assert_no_error (error);
g_assert_nonnull (c);
ensure_gdbus_testserver_up (c, NULL);
g_test_add_func ("/gdbus/delivery-in-thread", test_delivery_in_thread);
g_test_add_func ("/gdbus/method-calls-in-thread", test_method_calls_in_thread);
g_test_add_func ("/gdbus/threaded-singleton", test_threaded_singleton);