From: Gary Lockyer Date: Mon, 25 Jun 2018 21:39:56 +0000 (+1200) Subject: dsdb audit: Fix timestamp tests X-Git-Tag: tevent-0.9.37~223 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=113da7ac67a79deb71e3bfb2def9abd85655f36f;p=thirdparty%2Fsamba.git dsdb audit: Fix timestamp tests Fix flapping test: [242(3560)/242 at 25m3s] samba4.dsdb.samdb.ldb_modules.audit_log UNEXPECTED(failure): samba4.dsdb.samdb.ldb_modules.audit_log.test_operation_json_empty(none) REASON: Exception: Exception: difftime(after, actual) >= 0 ../source4/dsdb/samdb/ldb_modules/tests/test_audit_log.c:74: error: The tests truncate the microsecond portion of the time, so the difference could be less than 0. Signed-off-by: Gary Lockyer Reviewed-by: Andrew Bartlett Autobuild-User(master): Andrew Bartlett Autobuild-Date(master): Tue Jun 26 06:09:46 CEST 2018 on sn-devel-144 --- diff --git a/source4/dsdb/samdb/ldb_modules/tests/test_audit_log.c b/source4/dsdb/samdb/ldb_modules/tests/test_audit_log.c index 6bb79cf5175..fdce2d48d48 100644 --- a/source4/dsdb/samdb/ldb_modules/tests/test_audit_log.c +++ b/source4/dsdb/samdb/ldb_modules/tests/test_audit_log.c @@ -28,6 +28,7 @@ int ldb_audit_log_module_init(const char *version); #include "lib/ldb/include/ldb_private.h" #include +#include /* * Test helper to check ISO 8601 timestamps for validity @@ -40,6 +41,7 @@ static void check_timestamp(time_t before, const char* timestamp) struct tm tm; time_t after; time_t actual; + const double lower = -1; after = time(NULL); @@ -69,9 +71,12 @@ static void check_timestamp(time_t before, const char* timestamp) /* * The timestamp should be before <= actual <= after + * Note: as the microsecond portion of the time is truncated we use + * a -1 as the lower bound for the time difference instead of + * zero */ - assert_true(difftime(actual, before) >= 0); - assert_true(difftime(after, actual) >= 0); + assert_true(difftime(actual, before) >= lower); + assert_true(difftime(after, actual) >= lower); } static void test_has_password_changed(void **state)