[glib] tests: Ensure GCancellable is cancelled before operation is started



commit eb589e2bfee8bcde410e1bae4ec3da6b105fbcf9
Author: Philip Withnall <withnall endlessm com>
Date:   Sat Jan 26 11:38:20 2019 +0000

    tests: Ensure GCancellable is cancelled before operation is started
    
    In the writev() tests, the handling of cancellation is tested. However,
    the GCancellable was cancelled after the writev_async() call was
    started. Depending on the implementation of the writev() vfunc, the
    operation could be done in a thread or in callbacks on the current
    thread’s main loop. If done in a separate thread, there’s a chance that
    enough of the write could happen before cancellation reaches that thread
    that the overall operation returns success with a short write.
    
    That would cause the test to fail, sometimes.
    
    Avoid that by cancelling the GCancellable before starting the writev()
    operation.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>
    Reviewed-by: nobody

 gio/tests/file.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
---
diff --git a/gio/tests/file.c b/gio/tests/file.c
index affa0bce6..658d17549 100644
--- a/gio/tests/file.c
+++ b/gio/tests/file.c
@@ -1534,11 +1534,10 @@ test_writev_async_all_cancellation (void)
   ostream = g_io_stream_get_output_stream (G_IO_STREAM (iostream));
 
   cancellable = g_cancellable_new ();
+  g_cancellable_cancel (cancellable);
 
   g_output_stream_writev_all_async (ostream, vectors, G_N_ELEMENTS (vectors), 0, cancellable, 
test_writev_all_cb, &data);
 
-  g_cancellable_cancel (cancellable);
-
   while (!data.done)
     g_main_context_iteration (NULL, TRUE);
 


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