Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: rutime: out_http: simplify and make the in_http test more robust. #8897

Merged
merged 1 commit into from
May 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 45 additions & 68 deletions tests/runtime/out_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -1040,39 +1040,6 @@ void flb_test_json_date_format_java_sql_timestamp()
test_ctx_destroy(ctx);
}

static struct test_ctx *test_ctx_create_in_http(struct flb_lib_out_cb *cb)
{
int i_ffd;
int o_ffd;
struct test_ctx *ctx = NULL;

ctx = flb_malloc(sizeof(struct test_ctx));
if (!TEST_CHECK(ctx != NULL)) {
TEST_MSG("malloc failed");
flb_errno();
return NULL;
}

/* Service config */
ctx->flb = flb_create();
flb_service_set(ctx->flb,
"Flush", "0.200000000",
"Grace", "1",
"Log_Level", "error",
NULL);

/* Input */
i_ffd = flb_input(ctx->flb, (char *) "http", NULL);
TEST_CHECK(i_ffd >= 0);
ctx->i_ffd = i_ffd;

/* Output */
o_ffd = flb_output(ctx->flb, (char *) "lib", cb);
ctx->o_ffd = o_ffd;

return ctx;
}

int callback_test(void* data, size_t size, void* cb_data)
{
int num;
Expand All @@ -1087,79 +1054,89 @@ int callback_test(void* data, size_t size, void* cb_data)
/* test to make sure out_http is always able to work with in_http by default. */
void flb_test_in_http()
{
struct test_ctx *ctx_in_http;
struct test_ctx *ctx_out_http;
struct test_ctx *ctx;
int ret;
int num;
int i_ffd;
int o_ffd;
int trys;
struct flb_lib_out_cb cb;
char *buf = "[1, {\"msg\":\"hello world\"}]";
size_t size = strlen(buf);

cb.cb = callback_test;
cb.data = NULL;
clear_output_num();

char *buf1 = "[1, {\"msg\":\"hello world\"}]";
size_t size1 = strlen(buf1);
char *buf2 = "[2, {\"msg\":\"hello world\"}]";
size_t size2 = strlen(buf2);

ctx_in_http = test_ctx_create_in_http(&cb);
if (!TEST_CHECK(ctx_in_http != NULL)) {
ctx = test_ctx_create();
if (!TEST_CHECK(ctx != NULL)) {
TEST_MSG("test_ctx_create failed");
exit(EXIT_FAILURE);
}

ctx_out_http = test_ctx_create();
if (!TEST_CHECK(ctx_out_http != NULL)) {
TEST_MSG("test_ctx_create failed");
exit(EXIT_FAILURE);
}
ret = flb_input_set(ctx->flb,
ctx->i_ffd,
"tag", "lib",
NULL);
TEST_CHECK(ret == 0);

/* Input */
i_ffd = flb_input(ctx->flb, (char *) "http", NULL);
TEST_CHECK(i_ffd >= 0);

ret = flb_input_set(ctx_in_http->flb,
ctx_in_http->i_ffd,
ret = flb_input_set(ctx->flb,
i_ffd,
"port", "8888",
"tag", "http",
"host", "127.0.0.1",
NULL);
TEST_CHECK(ret == 0);

/* Output */
o_ffd = flb_output(ctx->flb, (char *) "lib", &cb);
TEST_CHECK(o_ffd >= 0);
ret = flb_output_set(ctx->flb,
o_ffd,
"match", "http",
NULL);
TEST_CHECK(ret == 0);

/* explicitly do not set anything beyond match, port and localhost
* to be sure the default options work with in_http.
*/
ret = flb_output_set(ctx_out_http->flb,
ctx_out_http->o_ffd,
"match", "*",
ret = flb_output_set(ctx->flb,
ctx->o_ffd,
"match", "lib",
"host", "127.0.0.1",
"port", "8888",
NULL);
TEST_CHECK(ret == 0);

/* Start the engines */
ret = flb_start(ctx_in_http->flb);
TEST_CHECK(ret == 0);
ret = flb_start(ctx_out_http->flb);
ret = flb_start(ctx->flb);
TEST_CHECK(ret == 0);

/* Ingest data sample */
ret = flb_lib_push(ctx_out_http->flb,
ctx_out_http->i_ffd,
(char *) buf1,
size1);
TEST_CHECK(ret >= 0);
ret = flb_lib_push(ctx_out_http->flb,
ctx_out_http->i_ffd,
(char *) buf2,
size2);
ret = flb_lib_push(ctx->flb,
ctx->i_ffd,
(char *) buf,
size);
TEST_CHECK(ret >= 0);

/* waiting to flush */
flb_time_msleep(500);
/* try several times to detect the record being flushed. */
for (trys = 0, num = 0; trys < 20 && num <= 0; trys++) {
num = get_output_num();
if (num <= 0) {
flb_time_msleep(500);
}
}

num = get_output_num();
if (!TEST_CHECK(num > 0)) {
TEST_MSG("no outputs");
}

test_ctx_destroy(ctx_out_http);
test_ctx_destroy(ctx_in_http);
test_ctx_destroy(ctx);
}

/* Test list */
Expand Down
Loading