[glib: 8/17] tests: Take explicit connection and context when ensuring testserver up
- From: Sebastian Dröge <sdroege src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 8/17] tests: Take explicit connection and context when ensuring testserver up
- Date: Mon, 24 Feb 2020 10:02:10 +0000 (UTC)
commit b2e543f6a4c0278e8777fe6ce2f63b5ecb1c2054
Author: Philip Withnall <withnall endlessm com>
Date: Thu Feb 20 11:49:12 2020 +0000
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
gio/tests/gdbus-connection-loss.c | 4 ++--
gio/tests/gdbus-tests.c | 28 ++++++++++++++--------------
gio/tests/gdbus-tests.h | 3 ++-
gio/tests/gdbus-threading.c | 4 ++--
4 files changed, 20 insertions(+), 19 deletions(-)
---
diff --git a/gio/tests/gdbus-connection-loss.c b/gio/tests/gdbus-connection-loss.c
index 8f7023f3f..a34a9923c 100644
--- a/gio/tests/gdbus-connection-loss.c
+++ b/gio/tests/gdbus-connection-loss.c
@@ -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();
diff --git a/gio/tests/gdbus-tests.c b/gio/tests/gdbus-tests.c
index 35e379bd2..66f16e02f 100644
--- a/gio/tests/gdbus-tests.c
+++ b/gio/tests/gdbus-tests.c
@@ -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);
}
/* ---------------------------------------------------------------------------------------------------- */
diff --git a/gio/tests/gdbus-tests.h b/gio/tests/gdbus-tests.h
index 00cda3713..eaef23480 100644
--- a/gio/tests/gdbus-tests.h
+++ b/gio/tests/gdbus-tests.h
@@ -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
diff --git a/gio/tests/gdbus-threading.c b/gio/tests/gdbus-threading.c
index b0183c710..b2112b07b 100644
--- a/gio/tests/gdbus-threading.c
+++ b/gio/tests/gdbus-threading.c
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]