dsdb audit: Fix timestamp tests
authorGary Lockyer <gary@catalyst.net.nz>
Mon, 25 Jun 2018 21:39:56 +0000 (09:39 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 26 Jun 2018 04:09:46 +0000 (06:09 +0200)
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 <gary@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Tue Jun 26 06:09:46 CEST 2018 on sn-devel-144

source4/dsdb/samdb/ldb_modules/tests/test_audit_log.c

index 6bb79cf5175b92534b9644ab2694d45d9e125681..fdce2d48d48afc6aa7d7e304e12fe649db725986 100644 (file)
@@ -28,6 +28,7 @@ int ldb_audit_log_module_init(const char *version);
 
 #include "lib/ldb/include/ldb_private.h"
 #include <regex.h>
+#include <float.h>
 
 /*
  * 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)