Skip to content

Commit ea7b9f4

Browse files
pwhelanedsiper
authored andcommitted
tests: rutime: out_http: simplify and make the in_http test more robust.
Signed-off-by: Phillip Adair Stewart Whelan <[email protected]>
1 parent 4db79b4 commit ea7b9f4

File tree

1 file changed

+45
-68
lines changed

1 file changed

+45
-68
lines changed

tests/runtime/out_http.c

Lines changed: 45 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,39 +1040,6 @@ void flb_test_json_date_format_java_sql_timestamp()
10401040
test_ctx_destroy(ctx);
10411041
}
10421042

1043-
static struct test_ctx *test_ctx_create_in_http(struct flb_lib_out_cb *cb)
1044-
{
1045-
int i_ffd;
1046-
int o_ffd;
1047-
struct test_ctx *ctx = NULL;
1048-
1049-
ctx = flb_malloc(sizeof(struct test_ctx));
1050-
if (!TEST_CHECK(ctx != NULL)) {
1051-
TEST_MSG("malloc failed");
1052-
flb_errno();
1053-
return NULL;
1054-
}
1055-
1056-
/* Service config */
1057-
ctx->flb = flb_create();
1058-
flb_service_set(ctx->flb,
1059-
"Flush", "0.200000000",
1060-
"Grace", "1",
1061-
"Log_Level", "error",
1062-
NULL);
1063-
1064-
/* Input */
1065-
i_ffd = flb_input(ctx->flb, (char *) "http", NULL);
1066-
TEST_CHECK(i_ffd >= 0);
1067-
ctx->i_ffd = i_ffd;
1068-
1069-
/* Output */
1070-
o_ffd = flb_output(ctx->flb, (char *) "lib", cb);
1071-
ctx->o_ffd = o_ffd;
1072-
1073-
return ctx;
1074-
}
1075-
10761043
int callback_test(void* data, size_t size, void* cb_data)
10771044
{
10781045
int num;
@@ -1087,79 +1054,89 @@ int callback_test(void* data, size_t size, void* cb_data)
10871054
/* test to make sure out_http is always able to work with in_http by default. */
10881055
void flb_test_in_http()
10891056
{
1090-
struct test_ctx *ctx_in_http;
1091-
struct test_ctx *ctx_out_http;
1057+
struct test_ctx *ctx;
10921058
int ret;
10931059
int num;
1060+
int i_ffd;
1061+
int o_ffd;
1062+
int trys;
10941063
struct flb_lib_out_cb cb;
1064+
char *buf = "[1, {\"msg\":\"hello world\"}]";
1065+
size_t size = strlen(buf);
10951066

10961067
cb.cb = callback_test;
10971068
cb.data = NULL;
10981069
clear_output_num();
10991070

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

1105-
ctx_in_http = test_ctx_create_in_http(&cb);
1106-
if (!TEST_CHECK(ctx_in_http != NULL)) {
1072+
ctx = test_ctx_create();
1073+
if (!TEST_CHECK(ctx != NULL)) {
11071074
TEST_MSG("test_ctx_create failed");
11081075
exit(EXIT_FAILURE);
11091076
}
11101077

1111-
ctx_out_http = test_ctx_create();
1112-
if (!TEST_CHECK(ctx_out_http != NULL)) {
1113-
TEST_MSG("test_ctx_create failed");
1114-
exit(EXIT_FAILURE);
1115-
}
1078+
ret = flb_input_set(ctx->flb,
1079+
ctx->i_ffd,
1080+
"tag", "lib",
1081+
NULL);
1082+
TEST_CHECK(ret == 0);
1083+
1084+
/* Input */
1085+
i_ffd = flb_input(ctx->flb, (char *) "http", NULL);
1086+
TEST_CHECK(i_ffd >= 0);
11161087

1117-
ret = flb_input_set(ctx_in_http->flb,
1118-
ctx_in_http->i_ffd,
1088+
ret = flb_input_set(ctx->flb,
1089+
i_ffd,
11191090
"port", "8888",
1091+
"tag", "http",
11201092
"host", "127.0.0.1",
11211093
NULL);
11221094
TEST_CHECK(ret == 0);
11231095

1096+
/* Output */
1097+
o_ffd = flb_output(ctx->flb, (char *) "lib", &cb);
1098+
TEST_CHECK(o_ffd >= 0);
1099+
ret = flb_output_set(ctx->flb,
1100+
o_ffd,
1101+
"match", "http",
1102+
NULL);
1103+
TEST_CHECK(ret == 0);
1104+
11241105
/* explicitly do not set anything beyond match, port and localhost
11251106
* to be sure the default options work with in_http.
11261107
*/
1127-
ret = flb_output_set(ctx_out_http->flb,
1128-
ctx_out_http->o_ffd,
1129-
"match", "*",
1108+
ret = flb_output_set(ctx->flb,
1109+
ctx->o_ffd,
1110+
"match", "lib",
11301111
"host", "127.0.0.1",
11311112
"port", "8888",
11321113
NULL);
11331114
TEST_CHECK(ret == 0);
11341115

11351116
/* Start the engines */
1136-
ret = flb_start(ctx_in_http->flb);
1137-
TEST_CHECK(ret == 0);
1138-
ret = flb_start(ctx_out_http->flb);
1117+
ret = flb_start(ctx->flb);
11391118
TEST_CHECK(ret == 0);
11401119

11411120
/* Ingest data sample */
1142-
ret = flb_lib_push(ctx_out_http->flb,
1143-
ctx_out_http->i_ffd,
1144-
(char *) buf1,
1145-
size1);
1146-
TEST_CHECK(ret >= 0);
1147-
ret = flb_lib_push(ctx_out_http->flb,
1148-
ctx_out_http->i_ffd,
1149-
(char *) buf2,
1150-
size2);
1121+
ret = flb_lib_push(ctx->flb,
1122+
ctx->i_ffd,
1123+
(char *) buf,
1124+
size);
11511125
TEST_CHECK(ret >= 0);
11521126

1153-
/* waiting to flush */
1154-
flb_time_msleep(500);
1127+
/* try several times to detect the record being flushed. */
1128+
for (trys = 0, num = 0; trys < 20 && num <= 0; trys++) {
1129+
num = get_output_num();
1130+
if (num <= 0) {
1131+
flb_time_msleep(500);
1132+
}
1133+
}
11551134

1156-
num = get_output_num();
11571135
if (!TEST_CHECK(num > 0)) {
11581136
TEST_MSG("no outputs");
11591137
}
11601138

1161-
test_ctx_destroy(ctx_out_http);
1162-
test_ctx_destroy(ctx_in_http);
1139+
test_ctx_destroy(ctx);
11631140
}
11641141

11651142
/* Test list */

0 commit comments

Comments
 (0)