tests/mainloop: Fix assertions to really avoid race conditions
authorColin Walters <walters@verbum.org>
Thu, 11 Jul 2013 15:07:17 +0000 (11:07 -0400)
committerColin Walters <walters@verbum.org>
Sun, 14 Jul 2013 13:46:43 +0000 (14:46 +0100)
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

index 7d61d7a..7e27b3c 100644 (file)
@@ -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);