[glib] tests/mainloop: Fix assertions to really avoid race conditions



commit ff68fca9e9fc7b534af86f2928d80830b331716f
Author: Colin Walters <walters verbum org>
Date:   Thu Jul 11 11:07:17 2013 -0400

    tests/mainloop: Fix assertions to really avoid race conditions
    
    As the comment says, we may be delayed an arbitrary amount of time on
    non-idle systems; update the assertions to reflect this.
    
    This should fix periodic failures in the gnome-ostree continuous
    integration system.
    
    https://bugzilla.gnome.org/700460

 glib/tests/mainloop.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)
---
diff --git a/glib/tests/mainloop.c b/glib/tests/mainloop.c
index 7d61d7a..7e27b3c 100644
--- a/glib/tests/mainloop.c
+++ b/glib/tests/mainloop.c
@@ -193,12 +193,16 @@ test_timeouts (void)
 
   g_main_loop_run (loop);
 
-  /* this is a race condition; under some circumstances we might not get 10
-   * 100ms runs in 1050 ms, so consider 9 as "close enough" */
-  g_assert_cmpint (a, >=, 9);
+  /* We may be delayed for an arbitrary amount of time - for example,
+   * it's possible for all timeouts to fire exactly once.
+   */
+  g_assert_cmpint (a, >, 0);
+  g_assert_cmpint (a, >=, b);
+  g_assert_cmpint (b, >=, c);
+
   g_assert_cmpint (a, <=, 10);
-  g_assert_cmpint (b, ==, 4);
-  g_assert_cmpint (c, ==, 3);
+  g_assert_cmpint (b, <=, 4);
+  g_assert_cmpint (c, <=, 3);
 
   g_main_loop_unref (loop);
   g_main_context_unref (ctx);


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