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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3348>
This commit is contained in:
Sebastian Wick 2023-10-25 23:35:09 +02:00 committed by Marge Bot
parent ac2f6e8b9e
commit 8c3c29d0c0

View File

@ -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 *