[glib: 1/2] tests: Add some rounding tolerance in timeout test
- From: Sebastian Dröge <sdroege src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/2] tests: Add some rounding tolerance in timeout test
- Date: Sun, 13 Dec 2020 09:17:18 +0000 (UTC)
commit ff563867886585f4b48601553f820e08f1f9ac0e
Author: Philip Withnall <pwithnall endlessos org>
Date: Fri Dec 11 12:37:26 2020 +0000
tests: Add some rounding tolerance in timeout test
Occasionally this test fails in CI with the message:
```
assertion failed: (current_time / 1000000 - last_time / 1000000 == 1)
```
The way this calculation is done at the moment, a difference of 1001ms
between `current_time` and `last_time` can result in failure, if the
times are close to a multiple to 1000ms.
Change it to only truncate the result after doing the subtraction, and
add a 500ms tolerance to account for scheduling delays in the test. (For
example, the `test_func()` could be called, then descheduled before it
gets to call `g_get_monotonic_time()`.
Additionally, change the test to use `g_assert_cmpint()` so that future
failures provide more useful debug information.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
glib/tests/timeout.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
---
diff --git a/glib/tests/timeout.c b/glib/tests/timeout.c
index fc836f312..9e4d047a6 100644
--- a/glib/tests/timeout.c
+++ b/glib/tests/timeout.c
@@ -152,11 +152,13 @@ test_func (gpointer data)
/* We accept 2 on the first iteration because _add_seconds() can
* have an initial latency of 1 second, see its documentation.
+ *
+ * Allow up to 500ms leeway for rounding and scheduling.
*/
if (count == 0)
- g_assert (current_time / 1000000 - last_time / 1000000 <= 2);
+ g_assert_cmpint (current_time / 1000 - last_time / 1000, <=, 2500);
else
- g_assert (current_time / 1000000 - last_time / 1000000 == 1);
+ g_assert_cmpint (current_time / 1000 - last_time / 1000, <=, 1500);
last_time = current_time;
count++;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]