[glib/wip/pwithnall/test-converter-stream-fail: 2/2] tests: Fix a flaky wait in converter-stream




commit 8e185e12c971a2e5cfea2a88a365230c64193ad7
Author: Philip Withnall <pwithnall endlessos org>
Date:   Mon Nov 22 13:22:25 2021 +0000

    tests: Fix a flaky wait in converter-stream
    
    Rather than waiting for a fixed period of time, poll in a loop until the
    condition the test is expecting is true.
    
    A better solution would be to use a `GSource` and wait until that’s
    dispatched. But doing so might affect the behaviour of the
    `GInputStream` under test, so busy-wait instead.
    
    Fixes this CI failure: https://gitlab.gnome.org/GNOME/glib/-/jobs/1630758
    
    ```
    (some socket debug output)
    Bail out! GLib-GIO:ERROR:../gio/tests/converter-stream.c:1037:test_converter_pollable: assertion failed 
(res == -1): (1 == -1)
    ```
    
    I could not reproduce the failure remotely with a few hundred
    invocations of the test, so it might only present itself on BSD, which
    presumably has different socket timing behaviour from Linux.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 gio/tests/converter-stream.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/gio/tests/converter-stream.c b/gio/tests/converter-stream.c
index 6befa274c..8c4731590 100644
--- a/gio/tests/converter-stream.c
+++ b/gio/tests/converter-stream.c
@@ -1022,10 +1022,10 @@ test_converter_pollable (void)
        }
 
       /* Wait a few ticks to check for the pipe to propagate the
-       * write. Finesses the race condition in the following test,
-       * where is_readable fails because the write hasn't propagated,
-       * but the read then succeeds because it has. */
-      g_usleep (80L);
+       * write. We can’t wait on a GSource as that might affect the stream under
+       * test, so just poll. */
+      while (!g_pollable_input_stream_is_readable (pollable_in))
+        g_usleep (80L);
 
       is_readable = g_pollable_input_stream_is_readable (pollable_in);
       res = g_pollable_input_stream_read_nonblocking (pollable_in,


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