diff options
author | Philip Withnall <pwithnall@endlessos.org> | 2022-10-17 13:02:02 +0100 |
---|---|---|
committer | Philip Withnall <pwithnall@endlessos.org> | 2022-10-17 13:02:02 +0100 |
commit | 0c1fa95827244ae0842408c8a631e39b97f8c72b (patch) | |
tree | f9c4aa13d7264ded8b297c3ee58b59eb1db07458 | |
parent | b7f2b09c309669874d926f292a2195183b6008a2 (diff) | |
download | glib-0c1fa95827244ae0842408c8a631e39b97f8c72b.tar.gz |
tests: Fix race condition on cancellation in unix-streams test
The cancellable may be cancelled just after the operation succeeds in a
different thread. So instead of checking whether the cancellable is
cancelled, check whether the operation returned a `CANCELLED` error, and
*then* assert that the cancellable is cancelled.
This should fix
https://pwithnall.pages.gitlab.gnome.org/-/glib/-/jobs/2338552/artifacts/_build/meson-logs/testlog.txt:
```
ok 1 /unix-streams/basic
Bail out! GLib-GIO:ERROR:../gio/tests/unix-streams.c:149:main_thread_skipped: assertion failed (err == (g-io-error-quark, 19)): err is NULL
stderr:
```
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
-rw-r--r-- | gio/tests/unix-streams.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/gio/tests/unix-streams.c b/gio/tests/unix-streams.c index e32e2861d..6246e583e 100644 --- a/gio/tests/unix-streams.c +++ b/gio/tests/unix-streams.c @@ -144,9 +144,9 @@ main_thread_skipped (GObject *source, GAsyncResult *res, gpointer user_data) nskipped = g_input_stream_skip_finish (in, res, &err); - if (g_cancellable_is_cancelled (main_cancel)) + if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { - g_assert_error (err, G_IO_ERROR, G_IO_ERROR_CANCELLED); + g_assert_true (g_cancellable_is_cancelled (main_cancel)); do_main_cancel (out); g_clear_error (&err); return; @@ -180,9 +180,9 @@ main_thread_read (GObject *source, GAsyncResult *res, gpointer user_data) nread = g_input_stream_read_finish (in, res, &err); - if (g_cancellable_is_cancelled (main_cancel)) + if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { - g_assert_error (err, G_IO_ERROR, G_IO_ERROR_CANCELLED); + g_assert_true (g_cancellable_is_cancelled (main_cancel)); do_main_cancel (out); g_clear_error (&err); return; @@ -218,9 +218,9 @@ main_thread_wrote (GObject *source, GAsyncResult *res, gpointer user_data) nwrote = g_output_stream_write_finish (out, res, &err); - if (g_cancellable_is_cancelled (main_cancel)) + if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { - g_assert_error (err, G_IO_ERROR, G_IO_ERROR_CANCELLED); + g_assert_true (g_cancellable_is_cancelled (main_cancel)); do_main_cancel (out); g_clear_error (&err); return; |