Skip to content

Commit

Permalink
in_dummy: add unit tests for rate and time_interval.
Browse files Browse the repository at this point in the history
Signed-off-by: Francisco Valente <[email protected]>
  • Loading branch information
franciscovalentecastro committed Oct 27, 2023
1 parent 108a459 commit e68e37e
Showing 1 changed file with 95 additions and 6 deletions.
101 changes: 95 additions & 6 deletions tests/runtime/in_simple_systems.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,68 @@ void do_test_records_single(char *system, void (*records_cb)(struct callback_rec
flb_destroy(ctx);
}

void do_test_records_wait_time(char *system, int wait_time, void (*records_cb)(struct callback_records *), ...)
{
flb_ctx_t *ctx = NULL;
int in_ffd;
int out_ffd;
va_list va;
char *key;
char *value;
int i;
struct flb_lib_out_cb cb;
struct callback_records *records;

records = flb_calloc(1, sizeof(struct callback_records));
records->num_records = 0;
records->records = NULL;
cb.cb = callback_add_record;
cb.data = (void *)records;

/* initialize */
set_result(0);

ctx = flb_create();

in_ffd = flb_input(ctx, (char *) system, NULL);
TEST_CHECK(in_ffd >= 0);
TEST_CHECK(flb_input_set(ctx, in_ffd, "tag", "test", NULL) == 0);

va_start(va, records_cb);
while ((key = va_arg(va, char *))) {
value = va_arg(va, char *);
TEST_CHECK(value != NULL);
TEST_CHECK(flb_input_set(ctx, in_ffd, key, value, NULL) == 0);
}
va_end(va);

out_ffd = flb_output(ctx, (char *) "lib", &cb);
TEST_CHECK(out_ffd >= 0);
TEST_CHECK(flb_output_set(ctx, out_ffd, "match", "test", NULL) == 0);

TEST_CHECK(flb_service_set(ctx, "Flush", "1",
"Grace", "1",
NULL) == 0);

/* Start test */
TEST_CHECK(flb_start(ctx) == 0);

/* Set wait_time plus 4 sec passed. It must have flushed */
sleep(wait_time + 4);

records_cb(records);

flb_stop(ctx);

for (i = 0; i < records->num_records; i++) {
flb_lib_free(records->records[i].data);
}
flb_free(records->records);
flb_free(records);

flb_destroy(ctx);
}

void flb_test_in_disk_flush()
{
do_test("disk",
Expand Down Expand Up @@ -471,6 +533,21 @@ void flb_test_dummy_records_message_copies_100(struct callback_records *records)
TEST_CHECK(records->num_records >= 100);
}

void flb_test_dummy_records_message_time_interval_3_rate_1(struct callback_records *records)
{
TEST_CHECK(records->num_records >= 1);
}

void flb_test_dummy_records_message_time_interval_3_rate_10(struct callback_records *records)
{
TEST_CHECK(records->num_records >= 10);
}

void flb_test_dummy_records_message_time_interval_6_rate_100(struct callback_records *records)
{
TEST_CHECK(records->num_records >= 100);
}

void flb_test_in_dummy_flush()
{
do_test("dummy", NULL);
Expand All @@ -493,14 +570,26 @@ void flb_test_in_dummy_flush()
"fixed_timestamp", "on",
NULL);
do_test_records_single("dummy", flb_test_dummy_records_message_copies_1,
"copies", "1",
NULL);
"copies", "1",
NULL);
do_test_records_single("dummy", flb_test_dummy_records_message_copies_5,
"copies", "5",
NULL);
"copies", "5",
NULL);
do_test_records_single("dummy", flb_test_dummy_records_message_copies_100,
"copies", "100",
NULL);
"copies", "100",
NULL);
do_test_records_wait_time("dummy", 3, flb_test_dummy_records_message_time_interval_3_rate_1,
"time_interval", "3",
"rate", "1",
NULL);
do_test_records_wait_time("dummy", 3, flb_test_dummy_records_message_time_interval_3_rate_10,
"time_interval", "3",
"rate", "10",
NULL);
do_test_records_wait_time("dummy", 6, flb_test_dummy_records_message_time_interval_6_rate_100,
"time_interval", "6",
"rate", "100",
NULL);
}

void flb_test_in_dummy_thread_flush()
Expand Down

0 comments on commit e68e37e

Please sign in to comment.