[glib: 1/3] tests: Fix race condition on cancellation in unix-streams test




commit 0c1fa95827244ae0842408c8a631e39b97f8c72b
Author: Philip Withnall <pwithnall endlessos org>
Date:   Mon Oct 17 13:02:02 2022 +0100

    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>

 gio/tests/unix-streams.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
---
diff --git a/gio/tests/unix-streams.c b/gio/tests/unix-streams.c
index e32e2861d3..6246e583ea 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;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]