@@ -131,13 +131,14 @@ static int cb_check_json_str_list(void *record, size_t size, void *data)
131131}
132132
133133static struct test_tail_ctx * test_tail_ctx_create (struct flb_lib_out_cb * data ,
134- char * * paths , int path_num )
134+ char * * paths , int path_num , int override )
135135{
136136 int i_ffd ;
137137 int o_ffd ;
138138 int i ;
139139 int j ;
140140 int fd ;
141+ int o_flags ;
141142 struct test_tail_ctx * ctx = NULL ;
142143
143144 if (!TEST_CHECK (data != NULL )){
@@ -173,6 +174,9 @@ static struct test_tail_ctx *test_tail_ctx_create(struct flb_lib_out_cb *data,
173174 o_ffd = flb_output (ctx -> flb , (char * ) "lib" , (void * ) data );
174175 ctx -> o_ffd = o_ffd ;
175176
177+ /* open() flags */
178+ o_flags = O_RDWR | O_CREAT ;
179+
176180 if (paths != NULL ) {
177181 ctx -> fds = flb_malloc (sizeof (int ) * path_num );
178182 ctx -> filepaths = paths ;
@@ -185,8 +189,14 @@ static struct test_tail_ctx *test_tail_ctx_create(struct flb_lib_out_cb *data,
185189 }
186190
187191 for (i = 0 ; i < path_num ; i ++ ) {
188- unlink (paths [i ]);
189- fd = open (paths [i ], O_RDWR | O_CREAT , S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );
192+ if (override ) {
193+ unlink (paths [i ]);
194+ }
195+ else {
196+ o_flags |= O_APPEND ;
197+ }
198+
199+ fd = open (paths [i ], o_flags , S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );
190200 if (!TEST_CHECK (fd >= 0 )) {
191201 TEST_MSG ("open failed. errno=%d path[%d]=%s" , errno , i , paths [i ]);
192202 flb_destroy (ctx -> flb );
@@ -211,7 +221,7 @@ static void test_tail_ctx_destroy(struct test_tail_ctx *ctx)
211221 TEST_CHECK (ctx != NULL );
212222
213223 if (ctx -> fds != NULL ) {
214- for (i = 0 ; i < ctx -> fd_num ; i ++ ) {
224+ for (i = 0 ; i < ctx -> fd_num ; i ++ ) {
215225 close (ctx -> fds [i ]);
216226 unlink (ctx -> filepaths [i ]);
217227 }
@@ -229,7 +239,7 @@ static ssize_t write_msg(struct test_tail_ctx *ctx, char *msg, size_t msg_len)
229239 int i ;
230240 ssize_t w_byte ;
231241
232- for (i = 0 ; i < ctx -> fd_num ; i ++ ) {
242+ for (i = 0 ; i < ctx -> fd_num ; i ++ ) {
233243 flb_time_msleep (100 );
234244 w_byte = write (ctx -> fds [i ], msg , msg_len );
235245 if (!TEST_CHECK (w_byte == msg_len )) {
@@ -242,6 +252,7 @@ static ssize_t write_msg(struct test_tail_ctx *ctx, char *msg, size_t msg_len)
242252 TEST_MSG ("write failed ret=%ld" , w_byte );
243253 return -1 ;
244254 }
255+ fsync (ctx -> fds [i ]);
245256 flb_time_msleep (100 );
246257 }
247258 return w_byte ;
@@ -809,7 +820,7 @@ void flb_test_path_comma()
809820 cb_data .cb = cb_count_msgpack ;
810821 cb_data .data = & unused ;
811822
812- ctx = test_tail_ctx_create (& cb_data , & file [0 ], sizeof (file )/sizeof (char * ));
823+ ctx = test_tail_ctx_create (& cb_data , & file [0 ], sizeof (file )/sizeof (char * ), FLB_TRUE );
813824 if (!TEST_CHECK (ctx != NULL )) {
814825 TEST_MSG ("test_ctx_create failed" );
815826 exit (EXIT_FAILURE );
@@ -866,7 +877,7 @@ void flb_test_path_key()
866877 cb_data .cb = cb_check_json_str_list ;
867878 cb_data .data = & expected ;
868879
869- ctx = test_tail_ctx_create (& cb_data , & file [0 ], sizeof (file )/sizeof (char * ));
880+ ctx = test_tail_ctx_create (& cb_data , & file [0 ], sizeof (file )/sizeof (char * ), FLB_TRUE );
870881 if (!TEST_CHECK (ctx != NULL )) {
871882 TEST_MSG ("test_ctx_create failed" );
872883 exit (EXIT_FAILURE );
@@ -921,7 +932,7 @@ void flb_test_exclude_path()
921932 cb_data .cb = cb_count_msgpack ;
922933 cb_data .data = & unused ;
923934
924- ctx = test_tail_ctx_create (& cb_data , & file [0 ], sizeof (file )/sizeof (char * ));
935+ ctx = test_tail_ctx_create (& cb_data , & file [0 ], sizeof (file )/sizeof (char * ), FLB_TRUE );
925936 if (!TEST_CHECK (ctx != NULL )) {
926937 TEST_MSG ("test_ctx_create failed" );
927938 exit (EXIT_FAILURE );
@@ -984,7 +995,7 @@ void flb_test_offset_key()
984995 }
985996
986997
987- ctx = test_tail_ctx_create (& cb_data , & file [0 ], sizeof (file )/sizeof (char * ) );
998+ ctx = test_tail_ctx_create (& cb_data , & file [0 ], sizeof (file )/sizeof (char * ), FLB_TRUE );
988999 if (!TEST_CHECK (ctx != NULL )) {
9891000 TEST_MSG ("test_ctx_create failed" );
9901001 exit (EXIT_FAILURE );
@@ -1050,7 +1061,7 @@ void flb_test_skip_empty_lines()
10501061 cb_data .cb = cb_check_json_str_list ;
10511062 cb_data .data = & expected ;
10521063
1053- ctx = test_tail_ctx_create (& cb_data , & file [0 ], sizeof (file )/sizeof (char * ) );
1064+ ctx = test_tail_ctx_create (& cb_data , & file [0 ], sizeof (file )/sizeof (char * ), FLB_TRUE );
10541065 if (!TEST_CHECK (ctx != NULL )) {
10551066 TEST_MSG ("test_ctx_create failed" );
10561067 exit (EXIT_FAILURE );
@@ -1115,7 +1126,7 @@ static int ignore_older(int expected, char *ignore_older)
11151126 cb_data .cb = cb_count_msgpack ;
11161127 cb_data .data = & unused ;
11171128
1118- ctx = test_tail_ctx_create (& cb_data , & file [0 ], sizeof (file )/sizeof (char * ) );
1129+ ctx = test_tail_ctx_create (& cb_data , & file [0 ], sizeof (file )/sizeof (char * ), FLB_TRUE );
11191130 if (!TEST_CHECK (ctx != NULL )) {
11201131 TEST_MSG ("test_ctx_create failed" );
11211132 return -1 ;
@@ -1216,7 +1227,7 @@ void flb_test_inotify_watcher_false()
12161227 cb_data .cb = cb_check_json_str_list ;
12171228 cb_data .data = & expected ;
12181229
1219- ctx = test_tail_ctx_create (& cb_data , & file [0 ], sizeof (file )/sizeof (char * ) );
1230+ ctx = test_tail_ctx_create (& cb_data , & file [0 ], sizeof (file )/sizeof (char * ), FLB_TRUE );
12201231 if (!TEST_CHECK (ctx != NULL )) {
12211232 TEST_MSG ("test_ctx_create failed" );
12221233 exit (EXIT_FAILURE );
@@ -1277,7 +1288,7 @@ void flb_test_parser()
12771288 cb_data .cb = cb_check_json_str_list ;
12781289 cb_data .data = & expected ;
12791290
1280- ctx = test_tail_ctx_create (& cb_data , & file [0 ], sizeof (file )/sizeof (char * ) );
1291+ ctx = test_tail_ctx_create (& cb_data , & file [0 ], sizeof (file )/sizeof (char * ), FLB_TRUE );
12811292 if (!TEST_CHECK (ctx != NULL )) {
12821293 TEST_MSG ("test_ctx_create failed" );
12831294 exit (EXIT_FAILURE );
@@ -1337,7 +1348,7 @@ void flb_test_tag_regex()
13371348 cb_data .cb = cb_check_json_str_list ;
13381349 cb_data .data = & expected ;
13391350
1340- ctx = test_tail_ctx_create (& cb_data , & file [0 ], sizeof (file )/sizeof (char * ) );
1351+ ctx = test_tail_ctx_create (& cb_data , & file [0 ], sizeof (file )/sizeof (char * ), FLB_TRUE );
13411352 if (!TEST_CHECK (ctx != NULL )) {
13421353 TEST_MSG ("test_ctx_create failed" );
13431354 exit (EXIT_FAILURE );
@@ -1400,7 +1411,7 @@ void flb_test_db()
14001411 cb_data .cb = cb_count_msgpack ;
14011412 cb_data .data = & unused ;
14021413
1403- ctx = test_tail_ctx_create (& cb_data , & file [0 ], sizeof (file )/sizeof (char * ) );
1414+ ctx = test_tail_ctx_create (& cb_data , & file [0 ], sizeof (file )/sizeof (char * ), FLB_FALSE );
14041415 if (!TEST_CHECK (ctx != NULL )) {
14051416 TEST_MSG ("test_ctx_create failed" );
14061417 exit (EXIT_FAILURE );
@@ -1451,8 +1462,7 @@ void flb_test_db()
14511462 cb_data .cb = cb_count_msgpack ;
14521463 cb_data .data = & unused ;
14531464
1454-
1455- ctx = test_tail_ctx_create (& cb_data , & file [0 ], sizeof (file )/sizeof (char * ));
1465+ ctx = test_tail_ctx_create (& cb_data , & file [0 ], sizeof (file )/sizeof (char * ), FLB_FALSE );
14561466 if (!TEST_CHECK (ctx != NULL )) {
14571467 TEST_MSG ("test_ctx_create failed" );
14581468 unlink (db );
@@ -1462,6 +1472,7 @@ void flb_test_db()
14621472 ret = flb_input_set (ctx -> flb , ctx -> o_ffd ,
14631473 "path" , file [0 ],
14641474 "db" , db ,
1475+ "db.sync" , "full" ,
14651476 NULL );
14661477 TEST_CHECK (ret == 0 );
14671478
@@ -1496,7 +1507,6 @@ void flb_test_db()
14961507 }
14971508
14981509 test_tail_ctx_destroy (ctx );
1499-
15001510 unlink (db );
15011511}
15021512#endif /* FLB_HAVE_SQLDB */
0 commit comments