[glib-networking/mcatanzaro/tls1.2] Fix flakiness in test_connection_read_time_out_write()



commit 718514c7bb88674cfa2c0027dbfbe41d4a1fdf8c
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Sun Aug 18 17:35:16 2019 -0500

    Fix flakiness in test_connection_read_time_out_write()
    
    For some reason, this test is only flaky when running with TLS 1.2 for
    me. Whatever, the problem is clear: the read can sometimes take a very
    long time. This is weird, but no reason to fail the test over it. Note
    this only happens for me when running very many tests at once (e.g. with
    'meson --repeat'), not when running them sequentially.

 tls/tests/connection.c | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)
---
diff --git a/tls/tests/connection.c b/tls/tests/connection.c
index ab6deb5..1206350 100644
--- a/tls/tests/connection.c
+++ b/tls/tests/connection.c
@@ -1548,15 +1548,28 @@ socket_client_timed_out_write (gpointer user_data)
   /* read TEST_DATA_LENGTH once */
   size = g_input_stream_read (input_stream, &buffer, TEST_DATA_LENGTH,
                               NULL, &error);
-  g_assert_no_error (error);
-  g_assert_cmpint (size, ==, TEST_DATA_LENGTH);
+  if (error)
+    {
+      /* This should very rarely ever happen, but in practice it can take more
+       * than one second to read under heavy load, or when running many tests
+       * simultaneously, so don't fail if this happens.
+       */
+      g_assert_error (error, G_IO_ERROR, G_IO_ERROR_TIMED_OUT);
+      g_assert_cmpint (size, ==, -1);
+      g_clear_error (&error);
+    }
+  else
+    {
+      g_assert_no_error (error);
+      g_assert_cmpint (size, ==, TEST_DATA_LENGTH);
 
-  /* read TEST_DATA_LENGTH again to cause the time out */
-  size = g_input_stream_read (input_stream, &buffer, TEST_DATA_LENGTH,
-                              NULL, &error);
-  g_assert_error (error, G_IO_ERROR, G_IO_ERROR_TIMED_OUT);
-  g_assert_cmpint (size, ==, -1);
-  g_clear_error (&error);
+      /* read TEST_DATA_LENGTH again to cause the time out */
+      size = g_input_stream_read (input_stream, &buffer, TEST_DATA_LENGTH,
+                                  NULL, &error);
+      g_assert_error (error, G_IO_ERROR, G_IO_ERROR_TIMED_OUT);
+      g_assert_cmpint (size, ==, -1);
+      g_clear_error (&error);
+    }
 
   /* write after a timeout, session should still be valid */
   size = g_output_stream_write (output_stream, TEST_DATA, TEST_DATA_LENGTH,


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