Skip to content

Commit

Permalink
tests: in_dummy: try and wait for the first record before doing checks.
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Whelan <[email protected]>
  • Loading branch information
pwhelan committed Dec 12, 2023
1 parent 06056b0 commit 863510f
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions tests/runtime/in_simple_systems.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 863510f

Please sign in to comment.