mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-11 18:23:07 +02:00
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:
parent
1a51681e6d
commit
b2e543f6a4
@ -124,14 +124,14 @@ main (int argc,
|
|||||||
g_assert (g_spawn_command_line_async (path, NULL));
|
g_assert (g_spawn_command_line_async (path, NULL));
|
||||||
g_free (path);
|
g_free (path);
|
||||||
|
|
||||||
ensure_gdbus_testserver_up ();
|
|
||||||
|
|
||||||
/* Create the connection in the main thread */
|
/* Create the connection in the main thread */
|
||||||
error = NULL;
|
error = NULL;
|
||||||
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
|
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert (c != NULL);
|
g_assert (c != NULL);
|
||||||
|
|
||||||
|
ensure_gdbus_testserver_up (c, NULL);
|
||||||
|
|
||||||
g_test_add_func ("/gdbus/connection-loss", test_connection_loss);
|
g_test_add_func ("/gdbus/connection-loss", test_connection_loss);
|
||||||
|
|
||||||
ret = g_test_run();
|
ret = g_test_run();
|
||||||
|
@ -87,20 +87,15 @@ _give_up (gpointer data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ensure_gdbus_testserver_up (void)
|
ensure_gdbus_testserver_up (GDBusConnection *connection,
|
||||||
|
GMainContext *context)
|
||||||
{
|
{
|
||||||
guint id;
|
|
||||||
gchar *name_owner;
|
gchar *name_owner;
|
||||||
GDBusConnection *connection;
|
GSource *timeout_source = NULL;
|
||||||
GDBusProxy *proxy;
|
GDBusProxy *proxy;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
connection = g_bus_get_sync (G_BUS_TYPE_SESSION,
|
g_main_context_push_thread_default (context);
|
||||||
NULL,
|
|
||||||
&error);
|
|
||||||
|
|
||||||
g_assert_no_error (error);
|
|
||||||
error = NULL;
|
|
||||||
|
|
||||||
proxy = g_dbus_proxy_new_sync (connection,
|
proxy = g_dbus_proxy_new_sync (connection,
|
||||||
G_DBUS_PROXY_FLAGS_NONE,
|
G_DBUS_PROXY_FLAGS_NONE,
|
||||||
@ -112,8 +107,11 @@ ensure_gdbus_testserver_up (void)
|
|||||||
&error);
|
&error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
|
|
||||||
id = g_timeout_add_seconds (60, _give_up,
|
timeout_source = g_timeout_source_new_seconds (60);
|
||||||
"waited more than ~ 60s for gdbus-testserver to take its bus name");
|
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)
|
while (TRUE)
|
||||||
{
|
{
|
||||||
@ -122,13 +120,15 @@ ensure_gdbus_testserver_up (void)
|
|||||||
if (name_owner != NULL)
|
if (name_owner != NULL)
|
||||||
break;
|
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_free (name_owner);
|
||||||
g_object_unref (proxy);
|
g_object_unref (proxy);
|
||||||
g_object_unref (connection);
|
|
||||||
|
g_main_context_pop_thread_default (context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------------- */
|
||||||
|
@ -114,7 +114,8 @@ GDBusConnection *_g_bus_get_priv (GBusType bus_type,
|
|||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
void ensure_gdbus_testserver_up (void);
|
void ensure_gdbus_testserver_up (GDBusConnection *connection,
|
||||||
|
GMainContext *context);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
@ -603,14 +603,14 @@ main (int argc,
|
|||||||
g_assert_true (g_spawn_command_line_async (path, NULL));
|
g_assert_true (g_spawn_command_line_async (path, NULL));
|
||||||
g_free (path);
|
g_free (path);
|
||||||
|
|
||||||
ensure_gdbus_testserver_up ();
|
|
||||||
|
|
||||||
/* Create the connection in the main thread */
|
/* Create the connection in the main thread */
|
||||||
error = NULL;
|
error = NULL;
|
||||||
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
|
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert_nonnull (c);
|
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/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/method-calls-in-thread", test_method_calls_in_thread);
|
||||||
g_test_add_func ("/gdbus/threaded-singleton", test_threaded_singleton);
|
g_test_add_func ("/gdbus/threaded-singleton", test_threaded_singleton);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user