From 55b41c90157919bd15019e18c30227974af1ce3a Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Fri, 21 Jul 2017 00:45:30 +0300 Subject: [PATCH] Patch up file test to allow for a bit of time discrepancy Since one cannot really compare system time to filesystem time (see e.g. https://lkml.org/lkml/2017/3/30/809), allow for 1 second error to avoid (or at least minimize) random test failures. --- libtransmission/file-test.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/libtransmission/file-test.c b/libtransmission/file-test.c index f6739ef08..79a0064a3 100644 --- a/libtransmission/file-test.c +++ b/libtransmission/file-test.c @@ -184,8 +184,8 @@ static int test_get_info(void) check_ptr(err, ==, NULL); check_int(info.type, ==, TR_SYS_PATH_IS_FILE); check_uint(info.size, ==, 4); - check_int(info.last_modified_at, >=, t); - check_int(info.last_modified_at, <=, time(NULL)); + check_int(info.last_modified_at, >=, t - 1); + check_int(info.last_modified_at, <=, time(NULL) + 1); /* Good file info (by handle) */ fd = tr_sys_file_open(path1, TR_SYS_FILE_READ, 0, NULL); @@ -194,8 +194,8 @@ static int test_get_info(void) check_ptr(err, ==, NULL); check_int(info.type, ==, TR_SYS_PATH_IS_FILE); check_uint(info.size, ==, 4); - check_int(info.last_modified_at, >=, t); - check_int(info.last_modified_at, <=, time(NULL)); + check_int(info.last_modified_at, >=, t - 1); + check_int(info.last_modified_at, <=, time(NULL) + 1); tr_sys_file_close(fd, NULL); tr_sys_path_remove(path1, NULL); @@ -208,8 +208,8 @@ static int test_get_info(void) check_ptr(err, ==, NULL); check_int(info.type, ==, TR_SYS_PATH_IS_DIRECTORY); check_uint(info.size, !=, (uint64_t)-1); - check_int(info.last_modified_at, >=, t); - check_int(info.last_modified_at, <=, time(NULL)); + check_int(info.last_modified_at, >=, t - 1); + check_int(info.last_modified_at, <=, time(NULL) + 1); tr_sys_path_remove(path1, NULL); if (create_symlink(path1, path2, false)) @@ -228,8 +228,8 @@ static int test_get_info(void) check_ptr(err, ==, NULL); check_int(info.type, ==, TR_SYS_PATH_IS_FILE); check_uint(info.size, ==, 4); - check_int(info.last_modified_at, >=, t); - check_int(info.last_modified_at, <=, time(NULL)); + check_int(info.last_modified_at, >=, t - 1); + check_int(info.last_modified_at, <=, time(NULL) + 1); /* Good file info (by handle) */ fd = tr_sys_file_open(path1, TR_SYS_FILE_READ, 0, NULL); @@ -238,8 +238,8 @@ static int test_get_info(void) check_ptr(err, ==, NULL); check_int(info.type, ==, TR_SYS_PATH_IS_FILE); check_uint(info.size, ==, 4); - check_int(info.last_modified_at, >=, t); - check_int(info.last_modified_at, <=, time(NULL)); + check_int(info.last_modified_at, >=, t - 1); + check_int(info.last_modified_at, <=, time(NULL) + 1); tr_sys_file_close(fd, NULL); tr_sys_path_remove(path2, NULL); @@ -252,8 +252,8 @@ static int test_get_info(void) check_ptr(err, ==, NULL); check_int(info.type, ==, TR_SYS_PATH_IS_DIRECTORY); check_uint(info.size, !=, (uint64_t)-1); - check_int(info.last_modified_at, >=, t); - check_int(info.last_modified_at, <=, time(NULL)); + check_int(info.last_modified_at, >=, t - 1); + check_int(info.last_modified_at, <=, time(NULL) + 1); tr_sys_path_remove(path2, NULL); tr_sys_path_remove(path1, NULL);