From 863510fd27ec2f8f8c165fe6155bf23f348c7af5 Mon Sep 17 00:00:00 2001 From: Phillip Whelan Date: Tue, 12 Dec 2023 11:56:38 -0300 Subject: [PATCH] tests: in_dummy: try and wait for the first record before doing checks. Signed-off-by: Phillip Whelan --- tests/runtime/in_simple_systems.c | 43 +++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/tests/runtime/in_simple_systems.c b/tests/runtime/in_simple_systems.c index 9f1a9d2e49f..fb9c119635f 100644 --- a/tests/runtime/in_simple_systems.c +++ b/tests/runtime/in_simple_systems.c @@ -104,6 +104,7 @@ void do_test(char *system, ...) va_list va; char *key; char *value; + int trys; struct flb_lib_out_cb cb; cb.cb = callback_test; @@ -150,17 +151,20 @@ void do_test(char *system, ...) /* Start test */ TEST_CHECK(flb_start(ctx) == 0); - /* 2 sec passed. It must have flushed */ - sleep(2); + for (trys = 0; trys < 5 && get_result() == 0; trys++) { + sleep(1); + } + flb_info("[test] check status 1"); ret = get_result(); TEST_CHECK(ret > 0); - /* 4 sec passed. It must have flushed */ - sleep(2); + for (trys = 0; trys < 5 && get_result() == ret; trys++) { + sleep(1); + } + flb_info("[test] check status 2"); - ret = get_result(); - TEST_CHECK(ret > 0); + TEST_CHECK(get_result() > ret); flb_stop(ctx); flb_destroy(ctx); @@ -174,7 +178,8 @@ void do_test_records(char *system, void (*records_cb)(struct callback_records *) va_list va; char *key; char *value; - int i; + int idx; + int trys; struct flb_lib_out_cb cb; struct callback_records *records; @@ -212,15 +217,16 @@ void do_test_records(char *system, void (*records_cb)(struct callback_records *) /* Start test */ TEST_CHECK(flb_start(ctx) == 0); - /* 4 sec passed. It must have flushed */ - sleep(5); + for (trys = 0; trys < 5 && records->num_records <= 0; trys++) { + sleep(1); + } records_cb(records); flb_stop(ctx); - for (i = 0; i < records->num_records; i++) { - flb_lib_free(records->records[i].data); + for (idx = 0; idx < records->num_records; idx++) { + flb_lib_free(records->records[idx].data); } flb_free(records->records); flb_free(records); @@ -525,16 +531,31 @@ void flb_test_dummy_records_message_copies_1(struct callback_records *records) void flb_test_dummy_records_message_copies_5(struct callback_records *records) { + int trys; + + for (trys = 0; trys < 5 && records->num_records < 5; trys++) { + sleep(1); + } TEST_CHECK(records->num_records >= 5); } void flb_test_dummy_records_message_copies_100(struct callback_records *records) { + int trys; + + for (trys = 0; trys < 100 && records->num_records < 100; trys++) { + sleep(1); + } TEST_CHECK(records->num_records >= 100); } void flb_test_dummy_records_message_rate(struct callback_records *records) { + int trys; + + for (trys = 0; trys < 20 && records->num_records < 20; trys++) { + sleep(1); + } TEST_CHECK(records->num_records >= 20); }