Merge branch 'test-failures' into 'main'

tests: Fix timeout sources in gdbus-auth and gapplication tests

See merge request GNOME/glib!3323
This commit is contained in:
Philip Withnall 2023-03-14 10:26:27 +00:00
commit 8fbb8dc442
2 changed files with 12 additions and 21 deletions

View File

@ -1071,6 +1071,8 @@ typedef struct
{
gboolean allow_replacement;
GSubprocess *subprocess;
GApplication *app; /* (not owned) */
guint timeout_id;
} TestReplaceData;
static void
@ -1116,11 +1118,12 @@ activate (gpointer data)
}
static gboolean
quit_already (gpointer data)
quit_already (gpointer user_data)
{
GApplication *app = data;
TestReplaceData *data = user_data;
g_application_quit (app);
g_application_quit (data->app);
data->timeout_id = 0;
return G_SOURCE_REMOVE;
}
@ -1159,22 +1162,22 @@ test_replace (gconstpointer data)
gboolean name_lost = FALSE;
TestReplaceData data;
GTestDBus *bus;
guint timeout_id = 0;
data.allow_replacement = allow;
data.subprocess = NULL;
data.timeout_id = 0;
bus = g_test_dbus_new (0);
g_test_dbus_up (bus);
app = g_application_new ("org.gtk.TestApplication.Replace", allow ? G_APPLICATION_ALLOW_REPLACEMENT : G_APPLICATION_DEFAULT_FLAGS);
app = data.app = g_application_new ("org.gtk.TestApplication.Replace", allow ? G_APPLICATION_ALLOW_REPLACEMENT : G_APPLICATION_DEFAULT_FLAGS);
g_application_set_inactivity_timeout (app, 500);
g_signal_connect (app, "name-lost", G_CALLBACK (name_was_lost), &name_lost);
g_signal_connect (app, "startup", G_CALLBACK (startup_cb), &data);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
if (!allow)
timeout_id = g_timeout_add_seconds (1, quit_already, app);
data.timeout_id = g_timeout_add_seconds (1, quit_already, &data);
g_application_run (app, G_N_ELEMENTS (argv) - 1, argv);
@ -1184,7 +1187,7 @@ test_replace (gconstpointer data)
else
g_assert_false (name_lost);
g_clear_handle_id (&timeout_id, g_source_remove);
g_clear_handle_id (&data.timeout_id, g_source_remove);
g_object_unref (app);
g_free (binpath);

View File

@ -111,15 +111,6 @@ test_auth_on_new_connection (GDBusServer *server,
return FALSE;
}
static gboolean
test_auth_on_timeout (gpointer user_data)
{
g_error ("Timeout waiting for client");
g_assert_not_reached ();
return G_SOURCE_REMOVE;
}
typedef struct
{
const gchar *address;
@ -162,7 +153,6 @@ test_auth_mechanism (const gchar *allowed_client_mechanism,
GMainLoop *loop;
GThread *client_thread;
TestAuthData data;
guint timeout_id;
server = server_new_for_mechanism (allowed_server_mechanism);
@ -173,13 +163,12 @@ test_auth_mechanism (const gchar *allowed_client_mechanism,
G_CALLBACK (test_auth_on_new_connection),
loop);
timeout_id = g_timeout_add_seconds (5, test_auth_on_timeout, NULL);
data.allowed_client_mechanism = allowed_client_mechanism;
data.allowed_server_mechanism = allowed_server_mechanism;
data.address = g_dbus_server_get_client_address (server);
/* run the D-Bus client in a thread */
/* Run the D-Bus client in a thread. If this hangs forever, the test harness
* (typically Meson) will eventually kill the test. */
client_thread = g_thread_new ("gdbus-client-thread",
test_auth_client_thread_func,
&data);
@ -191,7 +180,6 @@ test_auth_mechanism (const gchar *allowed_client_mechanism,
g_dbus_server_stop (server);
g_thread_join (client_thread);
g_source_remove (timeout_id);
while (g_main_context_iteration (NULL, FALSE));
g_main_loop_unref (loop);