From 8c3c29d0c0e127c490914822d48eeec88efc8a9b Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Wed, 25 Oct 2023 23:35:09 +0200 Subject: [PATCH] tests/wayland-test-utils: Keep track of process exit Whenever a MetaWaylandTestClient exists without success the calling test will fail. This fixes a bunch of cases where the test would get stuck waiting for some event from the client when it already died and won't be able to send the event. Part-of: --- src/tests/meta-wayland-test-utils.c | 60 ++++++++++++++++------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/src/tests/meta-wayland-test-utils.c b/src/tests/meta-wayland-test-utils.c index 0c1f4bf02..a90c05ce7 100644 --- a/src/tests/meta-wayland-test-utils.c +++ b/src/tests/meta-wayland-test-utils.c @@ -28,7 +28,7 @@ struct _MetaWaylandTestClient { GSubprocess *subprocess; char *path; - GMainLoop *main_loop; + gboolean finished; }; static char * @@ -42,6 +42,27 @@ get_test_client_path (const char *test_client_name) NULL); } +static void +wayland_test_client_finished (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + MetaWaylandTestClient *wayland_test_client = user_data; + GError *error = NULL; + + if (!g_subprocess_wait_finish (wayland_test_client->subprocess, + res, + &error)) + { + g_error ("Failed to wait for Wayland test client '%s': %s", + wayland_test_client->path, error->message); + } + + g_assert_true (g_subprocess_get_successful (wayland_test_client->subprocess)); + + wayland_test_client->finished = TRUE; +} + MetaWaylandTestClient * meta_wayland_test_client_new (MetaContext *context, const char *test_client_name) @@ -76,44 +97,29 @@ meta_wayland_test_client_new (MetaContext *context, wayland_test_client = g_new0 (MetaWaylandTestClient, 1); wayland_test_client->subprocess = subprocess; wayland_test_client->path = g_strdup (test_client_name); - wayland_test_client->main_loop = g_main_loop_new (NULL, FALSE); + + g_subprocess_wait_async (wayland_test_client->subprocess, NULL, + wayland_test_client_finished, + wayland_test_client); return wayland_test_client; } static void -wayland_test_client_finished (GObject *source_object, - GAsyncResult *res, - gpointer user_data) +wayland_test_client_destroy (MetaWaylandTestClient *wayland_test_client) { - MetaWaylandTestClient *wayland_test_client = user_data; - GError *error = NULL; - - if (!g_subprocess_wait_finish (wayland_test_client->subprocess, - res, - &error)) - { - g_error ("Failed to wait for Wayland test client '%s': %s", - wayland_test_client->path, error->message); - } - - g_main_loop_quit (wayland_test_client->main_loop); + g_free (wayland_test_client->path); + g_object_unref (wayland_test_client->subprocess); + g_free (wayland_test_client); } void meta_wayland_test_client_finish (MetaWaylandTestClient *wayland_test_client) { - g_subprocess_wait_async (wayland_test_client->subprocess, NULL, - wayland_test_client_finished, wayland_test_client); + while (!wayland_test_client->finished) + g_main_context_iteration (NULL, TRUE); - g_main_loop_run (wayland_test_client->main_loop); - - g_assert_true (g_subprocess_get_successful (wayland_test_client->subprocess)); - - g_main_loop_unref (wayland_test_client->main_loop); - g_free (wayland_test_client->path); - g_object_unref (wayland_test_client->subprocess); - g_free (wayland_test_client); + wayland_test_client_destroy (wayland_test_client); } MetaWindow *