11#include <fluent-bit/flb_sds.h>
22#include <fluent-bit/flb_mem.h>
33#include <fluent-bit/flb_log.h>
4+ #include <fluent-bit/flb_time.h>
45
56#include "flb_tests_internal.h"
67
1112#define TEST_RECORD_02 "other type of message"
1213#define TEST_RECORD_02_SIZE sizeof(TEST_RECORD_02) - 1
1314
14- static int check_clock (int timeout , time_t start )
15+ static int check_clock (uint64_t timeout , struct flb_time * tm_start )
1516{
16- time_t now = time (NULL );
17-
18- if (!(TEST_CHECK ((start + timeout ) >= now ))) {
19- TEST_MSG ("clock error, unsuppresed log: now=%ld, timeout=%ld, diff=%ld" ,
20- now , start + timeout , now - (start + timeout ));
17+ struct flb_time tm_now ;
18+ uint64_t diff ;
19+ uint64_t now ;
20+ uint64_t start ;
21+
22+ flb_time_get (& tm_now );
23+ now = flb_time_to_millisec (& tm_now );
24+ start = flb_time_to_millisec (tm_start );
25+ diff = now - start ;
26+
27+ if (!(TEST_CHECK (diff < timeout ))) {
28+ TEST_MSG ("clock error, unsuppresed log: now=%llu, start=%llu timeout=%llu(%llu), diff=%llu" ,
29+ now , start , start + timeout , timeout , diff );
2130 return -1 ;
2231 }
2332
2433 return 0 ;
2534}
2635
27- static int update_and_check_clock (int timeout , int ret , time_t * clock )
36+ static int update_and_check_clock (uint64_t timeout , int ret , struct flb_time * clock )
2837{
2938 int ret_val ;
3039
@@ -33,8 +42,8 @@ static int update_and_check_clock(int timeout, int ret, time_t *clock)
3342 }
3443
3544 /* false means timeout. check interval. */
36- ret_val = check_clock (timeout , * clock );
37- * clock = time ( NULL ); /* reset clock */
45+ ret_val = check_clock (timeout , clock );
46+ flb_time_get ( clock ); /* reset clock */
3847
3948 return ret_val ;
4049}
@@ -45,10 +54,10 @@ static void cache_basic_timeout()
4554 int ret ;
4655 int ret_1 ;
4756 int ret_2 ;
48- int timeout = 5 ;
49- time_t clock1 ;
50- time_t clock2 ;
51- time_t start ;
57+ uint64_t timeout = 5000 ;
58+ struct flb_time clock1 ;
59+ struct flb_time clock2 ;
60+ struct flb_time start ;
5261 struct flb_log_cache * cache ;
5362 struct flb_log_cache_entry * entry ;
5463
@@ -81,10 +90,10 @@ static void cache_basic_timeout()
8190 cache = flb_log_cache_create (timeout , 4 );
8291 TEST_CHECK (cache != NULL );
8392
84- clock1 = time ( NULL );
93+ flb_time_get ( & clock1 );
8594 ret_1 = flb_log_cache_check_suppress (cache , TEST_RECORD_01 , TEST_RECORD_01_SIZE );
8695
87- clock2 = time ( NULL );
96+ flb_time_get ( & clock2 );
8897 ret_2 = flb_log_cache_check_suppress (cache , TEST_RECORD_02 , TEST_RECORD_02_SIZE );
8998
9099 TEST_CHECK (ret_1 == FLB_FALSE );
@@ -93,7 +102,7 @@ static void cache_basic_timeout()
93102 sleep (1 );
94103
95104
96- for (i = 1 , start = time ( NULL ); i < 10 && start + (timeout * 20 ) > time (NULL ); i ++ ) {
105+ for (i = 1 , flb_time_get ( & start ); i < 10 && flb_time_to_millisec ( & start ) + (timeout * 20 ) > time (NULL )* 1000 ; i ++ ) {
97106 ret_1 = flb_log_cache_check_suppress (cache , TEST_RECORD_01 , TEST_RECORD_01_SIZE );
98107 ret = update_and_check_clock (timeout , ret_1 , & clock1 );
99108 if (!TEST_CHECK (ret == 0 )) {
0 commit comments