Commit 7f256e63 authored by Philip Withnall's avatar Philip Withnall

tests: Fix small race in GSubprocess tests

This was introduced in commit 7846d615: g_subprocess_get_identifier()
will return NULL after the subprocess has exited, and the subprocess in
the `noop` test will exit as soon as it has started spawning. So if the
scheduler scheduled the testprog subprocess quickly, descheduled the
parent test process until the testprog exited, then the return value
from g_subprocess_get_identifier() would be NULL.

Move the g_subprocess_get_identifier() test to one which calls testprog
in `sleep-forever` mode, since that is guaranteed not to exit until
killed (which we do later in the test).
Signed-off-by: Philip Withnall's avatarPhilip Withnall <withnall@endlessm.com>
parent e6a55def
......@@ -66,14 +66,11 @@ test_noop (void)
GError **error = &local_error;
GPtrArray *args;
GSubprocess *proc;
const gchar *id;
args = get_test_subprocess_args ("noop", NULL);
proc = g_subprocess_newv ((const gchar * const *) args->pdata, G_SUBPROCESS_FLAGS_NONE, error);
g_ptr_array_free (args, TRUE);
g_assert_no_error (local_error);
id = g_subprocess_get_identifier (proc);
g_assert_nonnull (id);
g_subprocess_wait_check (proc, NULL, error);
g_assert_no_error (local_error);
......@@ -1297,12 +1294,16 @@ test_terminate (void)
GSubprocess *proc;
GPtrArray *args;
GMainLoop *loop;
const gchar *id;
args = get_test_subprocess_args ("sleep-forever", NULL);
proc = g_subprocess_newv ((const gchar * const *) args->pdata, G_SUBPROCESS_FLAGS_NONE, error);
g_ptr_array_free (args, TRUE);
g_assert_no_error (local_error);
id = g_subprocess_get_identifier (proc);
g_assert_nonnull (id);
loop = g_main_loop_new (NULL, TRUE);
g_subprocess_wait_async (proc, NULL, on_request_quit_exited, loop);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment