[Patch] lib/audit_logging Fix flapping test

Gary Lockyer gary at catalyst.net.nz
Sun Jun 10 04:08:32 UTC 2018

Have seen failures of test_json_add_timestamp on sn_devel

A summary of the autobuild process is here:


You can see logs of the failed task here:


This patch widens the expected times to ensure that it passes reliably. The test is intended to ensure that a time stamp is generated and is correctly formatted and that the value is reasonable.

In the failure the time stamp appears to be after the finish time, I'm guessing this is a precision/rounding issue but I'd appreciate any thoughts/insights.


-------------- next part --------------
From e24dcb4fb1bff49ebd5b188bc3d0585797bcdfe5 Mon Sep 17 00:00:00 2001
From: Gary Lockyer <gary at catalyst.net.nz>
Date: Sat, 9 Jun 2018 14:58:51 +0200
Subject: [PATCH] lib/audit_logging fix flapping test

Add an adjustment to the before and after values to cater for the
occasional differences between the calculated times.

The exact value of the time stamp is not important what is important is
that is correctly formatted and that the value is reasonable i.e. it's
close enough to the current time.

Signed-off-by: Gary Lockyer <gary at catalyst.net.nz>
 lib/audit_logging/tests/audit_logging_test.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/audit_logging/tests/audit_logging_test.c b/lib/audit_logging/tests/audit_logging_test.c
index 6be71f3..26875c9 100644
--- a/lib/audit_logging/tests/audit_logging_test.c
+++ b/lib/audit_logging/tests/audit_logging_test.c
@@ -219,6 +219,7 @@ static void test_json_add_timestamp(void **state)
 	time_t before;
 	time_t after;
 	time_t actual;
+	const int adjustment = 1;
 	object = json_new_object();
@@ -255,7 +256,10 @@ static void test_json_add_timestamp(void **state)
 	 * The timestamp should be before <= actual <= after
+	 * but we adjust the times to cater for any precision issues.
+	before -= adjustment;
+	after += adjustment;
 	assert_true(difftime(actual, before) >= 0);
 	assert_true(difftime(after, actual) >= 0);

More information about the samba-technical mailing list