diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f59d452cfa..3d38b2569f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -816,6 +816,7 @@ add_subdirectory(${FLB_PATH_LIB_JSMN}) # Runtime Tests (filter_kubernetes) requires HTTP Server if(FLB_TESTS_RUNTIME) FLB_OPTION(FLB_HTTP_SERVER ON) + FLB_OPTION(FLB_IN_EVENT_TEST ON) endif() # Monkey Core Library diff --git a/cmake/windows-setup.cmake b/cmake/windows-setup.cmake index 48a749b4d29..b3306266e8f 100644 --- a/cmake/windows-setup.cmake +++ b/cmake/windows-setup.cmake @@ -95,7 +95,7 @@ if(FLB_WINDOWS_DEFAULTS) set(FLB_OUT_CHRONICLE Yes) set(FLB_OUT_DATADOG Yes) set(FLB_OUT_ES Yes) - set(FLB_OUT_EXIT No) + set(FLB_OUT_EXIT Yes) set(FLB_OUT_FORWARD Yes) set(FLB_OUT_GELF Yes) set(FLB_OUT_HTTP Yes) diff --git a/plugins/filter_kubernetes/kube_meta.c b/plugins/filter_kubernetes/kube_meta.c index 63426e9467c..f8371b1a826 100644 --- a/plugins/filter_kubernetes/kube_meta.c +++ b/plugins/filter_kubernetes/kube_meta.c @@ -58,8 +58,13 @@ static int file_to_buffer(const char *path, ssize_t bytes; FILE *fp; struct stat st; + const char *file_mode = "r"; - if (!(fp = fopen(path, "r"))) { +#ifdef FLB_SYSTEM_WINDOWS + file_mode = "rb"; +#endif + + if (!(fp = fopen(path, file_mode))) { return -1; } @@ -337,8 +342,13 @@ static int get_meta_file_info(struct flb_kube *ctx, const char *namespace, struct stat sb; int packed = -1; int ret; + int open_flags = O_RDONLY; char uri[1024]; +#ifdef FLB_SYSTEM_WINDOWS + open_flags |= O_BINARY; +#endif + if (ctx->meta_preload_cache_dir && namespace) { if (podname && strlen(podname) > 0) { @@ -350,7 +360,7 @@ static int get_meta_file_info(struct flb_kube *ctx, const char *namespace, ctx->meta_preload_cache_dir, namespace); } if (ret > 0) { - fd = open(uri, O_RDONLY, 0); + fd = open(uri, open_flags, 0); if (fd != -1) { if (fstat(fd, &sb) == 0) { payload = flb_malloc(sb.st_size); diff --git a/plugins/filter_throttle/throttle.c b/plugins/filter_throttle/throttle.c index d1a2c51b23b..74f0fb268ee 100644 --- a/plugins/filter_throttle/throttle.c +++ b/plugins/filter_throttle/throttle.c @@ -92,8 +92,9 @@ void *time_ticker(void *args) ctx->hash->total / ctx->hash->size); } pthread_mutex_unlock(&throttle_mut); - /* sleep is a cancelable function */ + /* Windows sleep is not a pthread cancellation point. */ sleep(ctx->ticker_data.seconds); + pthread_testcancel(); } } diff --git a/plugins/in_event_test/event_test.c b/plugins/in_event_test/event_test.c index bf09de01b0e..4a224ab82c6 100644 --- a/plugins/in_event_test/event_test.c +++ b/plugins/in_event_test/event_test.c @@ -33,8 +33,8 @@ #define STATUS_PENDING -1 #define CALLBACK_TIME 2 /* 2 seconds */ -#define SERVER_PORT "9092" -#define SERVER_IFACE "0.0.0.0" +#define SERVER_PORT "0" +#define SERVER_IFACE "127.0.0.1" struct unit_test { int id; @@ -55,7 +55,8 @@ struct unit_test tests[] = { struct event_test { flb_pipefd_t pipe[2]; - int server_fd; + flb_sockfd_t server_fd; + int server_port; int client_coll_id; struct flb_upstream *upstream; struct unit_test *tests; @@ -127,9 +128,9 @@ static int cb_collector_time(struct flb_input_instance *ins, * to our local pipe. */ val = 1; - ret = write(ctx->pipe[1], &val, sizeof(val)); + ret = flb_pipe_w(ctx->pipe[1], &val, sizeof(val)); if (ret == -1) { - flb_errno(); + flb_pipe_error(); set_unit_test_status(ctx, 0, STATUS_ERROR); flb_engine_exit(config); } @@ -143,13 +144,13 @@ static int cb_collector_fd(struct flb_input_instance *ins, struct flb_config *config, void *in_context) { uint64_t val = 0; - size_t bytes; + ssize_t bytes; struct unit_test *ut; struct event_test *ctx = (struct event_test *) in_context; - bytes = read(ctx->pipe[0], &val, sizeof(val)); + bytes = flb_pipe_r(ctx->pipe[0], &val, sizeof(val)); if (bytes <= 0) { - flb_errno(); + flb_pipe_error(); set_unit_test_status(ctx, 1, STATUS_ERROR); flb_engine_exit(config); } @@ -242,12 +243,28 @@ static struct event_test *config_create(struct flb_input_instance *ins) return ctx; } +static int get_server_port(flb_sockfd_t fd) +{ + int ret; + socklen_t len; + struct sockaddr_in addr; + + len = sizeof(addr); + ret = getsockname(fd, (struct sockaddr *) &addr, &len); + if (ret == -1) { + return -1; + } + + return ntohs(addr.sin_port); +} + /* Initialize plugin */ static int cb_event_test_init(struct flb_input_instance *ins, struct flb_config *config, void *data) { - int fd; int ret; + int port; + flb_sockfd_t fd; struct unit_test *ut; struct event_test *ctx = NULL; struct flb_upstream *upstream; @@ -297,7 +314,15 @@ static int cb_event_test_init(struct flb_input_instance *ins, return -1; } flb_net_socket_nonblocking(fd); - ctx->server_fd = fd; + ctx->server_fd = fd; + + port = get_server_port(ctx->server_fd); + if (port <= 0) { + flb_errno(); + config_destroy(ctx); + return -1; + } + ctx->server_port = port; /* socket server */ ret = flb_input_set_collector_socket(ins, @@ -321,7 +346,7 @@ static int cb_event_test_init(struct flb_input_instance *ins, ctx->client_coll_id = ret; /* upstream context for socket client */ - upstream = flb_upstream_create(config, "127.0.0.1", atoi(SERVER_PORT), + upstream = flb_upstream_create(config, SERVER_IFACE, ctx->server_port, FLB_IO_TCP, NULL); if (!upstream) { config_destroy(ctx); diff --git a/plugins/in_kubernetes_events/kubernetes_events.c b/plugins/in_kubernetes_events/kubernetes_events.c index 2728d30bb7a..080733480cd 100644 --- a/plugins/in_kubernetes_events/kubernetes_events.c +++ b/plugins/in_kubernetes_events/kubernetes_events.c @@ -54,8 +54,13 @@ static int file_to_buffer(const char *path, ssize_t bytes; FILE *fp; struct stat st; + const char *file_mode = "r"; - if (!(fp = fopen(path, "r"))) { +#ifdef FLB_SYSTEM_WINDOWS + file_mode = "rb"; +#endif + + if (!(fp = fopen(path, file_mode))) { return -1; } @@ -303,7 +308,7 @@ static bool check_event_is_filtered(struct k8s_events *ctx, msgpack_object *obj, flb_sds_t uid; uint64_t resource_version; - outdated = cfl_time_now() - (ctx->retention_time * 1000000000L); + outdated = cfl_time_now() - ((uint64_t) ctx->retention_time * 1000000000ULL); if (flb_time_to_nanosec(event_time) < outdated) { flb_plg_debug(ctx->ins, "Item is older than retention_time: %" PRIu64 " < %" PRIu64, flb_time_to_nanosec(event_time), outdated); @@ -655,7 +660,8 @@ static int k8s_events_cleanup_db(struct flb_input_instance *ins, FLB_INPUT_RETURN(0); } - retention_time_ago = cfl_time_now() - (ctx->retention_time * 1000000000L); + retention_time_ago = cfl_time_now() - + ((uint64_t) ctx->retention_time * 1000000000ULL); sqlite3_bind_int64(ctx->stmt_delete_old_kubernetes_events, 1, (int64_t)retention_time_ago); ret = sqlite3_step(ctx->stmt_delete_old_kubernetes_events); diff --git a/plugins/in_tail/tail_scan_win32.c b/plugins/in_tail/tail_scan_win32.c index c5349ccf7b2..229ddaf1b9c 100644 --- a/plugins/in_tail/tail_scan_win32.c +++ b/plugins/in_tail/tail_scan_win32.c @@ -48,7 +48,8 @@ static int tail_is_excluded(char *path, struct flb_tail_config *ctx) mk_list_foreach(head, ctx->exclude_list) { pattern = mk_list_entry(head, struct flb_slist_entry, _head); - if (PathMatchSpecA(path, pattern->str)) { + if (PathMatchSpecA(path, pattern->str) || + PathMatchSpecA(PathFindFileNameA(path), pattern->str)) { return FLB_TRUE; } } diff --git a/plugins/out_loki/loki.c b/plugins/out_loki/loki.c index 928f8bba927..e8608277538 100644 --- a/plugins/out_loki/loki.c +++ b/plugins/out_loki/loki.c @@ -759,6 +759,11 @@ static int read_label_map_path_file(struct flb_output_instance *ins, flb_sds_t p struct stat st; size_t file_size; size_t ret_size; + const char *file_mode = "r"; + +#ifdef FLB_SYSTEM_WINDOWS + file_mode = "rb"; +#endif ret = access(path, R_OK); if (ret < 0) { @@ -775,7 +780,7 @@ static int read_label_map_path_file(struct flb_output_instance *ins, flb_sds_t p } file_size = st.st_size; - fp = fopen(path, "r"); + fp = fopen(path, file_mode); if (fp == NULL) { flb_plg_error(ins, "can't open %s", path); return -1; diff --git a/plugins/out_s3/s3.c b/plugins/out_s3/s3.c index ac70da12957..c12c6c79ac9 100644 --- a/plugins/out_s3/s3.c +++ b/plugins/out_s3/s3.c @@ -57,7 +57,11 @@ FLB_TLS_DEFINE(struct worker_info, s3_worker_info); #ifdef FLB_SYSTEM_WINDOWS static int setenv(const char *name, const char *value, int overwrite) { - return SetEnvironmentVariableA(name, value); + if (overwrite == 0 && getenv(name) != NULL) { + return 0; + } + + return _putenv_s(name, value); } #endif @@ -391,6 +395,37 @@ static flb_sds_t concat_path(char *p1, char *p2) return dir; } +static flb_sds_t create_buffer_path(struct flb_s3 *ctx) +{ +#ifdef FLB_SYSTEM_WINDOWS + char *temp_dir; + flb_sds_t dir; + flb_sds_t tmp; + + if (strcmp(ctx->store_dir, "/tmp/fluent-bit/s3") == 0) { + temp_dir = getenv("TEMP"); + if (temp_dir == NULL) { + temp_dir = getenv("TMP"); + } + + if (temp_dir != NULL) { + dir = flb_sds_create_size(64); + tmp = flb_sds_printf(&dir, "%s/fluent-bit/s3/%s", + temp_dir, ctx->bucket); + if (tmp == NULL) { + flb_errno(); + flb_sds_destroy(dir); + return NULL; + } + + return tmp; + } + } +#endif + + return concat_path(ctx->store_dir, ctx->bucket); +} + /* Reads in index value from metadata file and sets seq_index to value */ static int read_seq_index(char *seq_index_file, uint64_t *seq_index) { @@ -769,7 +804,7 @@ static int cb_s3_init(struct flb_output_instance *ins, * We append the bucket name to the dir, to support multiple instances * of this plugin using the same buffer dir */ - tmp_sds = concat_path(ctx->store_dir, ctx->bucket); + tmp_sds = create_buffer_path(ctx); if (!tmp_sds) { flb_plg_error(ctx->ins, "Could not construct buffer path"); return -1; @@ -1103,8 +1138,14 @@ static int cb_s3_init(struct flb_output_instance *ins, ctx->provider->provider_vtable->init(ctx->provider); ctx->timer_created = FLB_FALSE; - ctx->timer_ms = (int) (ctx->upload_timeout / 6) * 1000; - if (s3_plugin_under_test() == FLB_FALSE) { + if (s3_plugin_under_test() == FLB_TRUE) { + ctx->timer_ms = (int) (ctx->upload_timeout * 1000 / 6); + if (ctx->timer_ms < 100) { + ctx->timer_ms = 100; + } + } + else { + ctx->timer_ms = (int) (ctx->upload_timeout / 6) * 1000; if (ctx->timer_ms > UPLOAD_TIMER_MAX_WAIT) { ctx->timer_ms = UPLOAD_TIMER_MAX_WAIT; } diff --git a/plugins/out_syslog/syslog.c b/plugins/out_syslog/syslog.c index b191fe778b9..f9ad5fadb6a 100644 --- a/plugins/out_syslog/syslog.c +++ b/plugins/out_syslog/syslog.c @@ -969,8 +969,8 @@ static int cb_syslog_exit(void *data, struct flb_config *config) flb_upstream_destroy(ctx->u); } - if (ctx->fd > 0) { - close(ctx->fd); + if (ctx->fd != FLB_INVALID_SOCKET) { + flb_socket_close(ctx->fd); } flb_syslog_config_destroy(ctx); diff --git a/tests/include/aws_client_mock.h b/tests/include/aws_client_mock.h index 7cdfc81066d..d0d00a85cd0 100644 --- a/tests/include/aws_client_mock.h +++ b/tests/include/aws_client_mock.h @@ -67,12 +67,21 @@ #define AWS_CLIENT_MOCK_H /* Variadic Argument Counter, Counts up to 64 variadic args */ +#ifdef _MSC_VER +#define FLB_AWS_CLIENT_MOCK_COUNT64(...) \ + _FLB_AWS_CLIENT_MOCK_COUNT64(dummy __VA_OPT__(,) __VA_ARGS__, 63, 62, 61, 60, 59, \ + 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, \ + 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \ + 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, \ + 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) +#else #define FLB_AWS_CLIENT_MOCK_COUNT64(...) \ _FLB_AWS_CLIENT_MOCK_COUNT64(dummy, ##__VA_ARGS__, 63, 62, 61, 60, 59, 58, 57, 56, \ 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, \ 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, \ 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, \ 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) +#endif #define _FLB_AWS_CLIENT_MOCK_COUNT64( \ x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, \ x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, x29, x30, x31, x32, x33, x34, x35, \ diff --git a/tests/runtime/CMakeLists.txt b/tests/runtime/CMakeLists.txt index be91112e958..f7aa58f7e73 100644 --- a/tests/runtime/CMakeLists.txt +++ b/tests/runtime/CMakeLists.txt @@ -66,7 +66,9 @@ if(FLB_OUT_LIB) FLB_RT_TEST(FLB_IN_FLUENTBIT_METRICS "in_fluentbit_metrics.c") FLB_RT_TEST(FLB_IN_PROMETHEUS_TEXTFILE "in_prometheus_textfile.c") FLB_RT_TEST(FLB_IN_KUBERNETES_EVENTS "in_kubernetes_events.c") - FLB_RT_TEST(FLB_IN_OPENTELEMETRY "in_opentelemetry_routing.c") + if(FLB_HAVE_LIBYAML) + FLB_RT_TEST(FLB_IN_OPENTELEMETRY "in_opentelemetry_routing.c") + endif() if (FLB_IN_SYSTEMD) FLB_RT_TEST(FLB_IN_SYSTEMD "in_systemd.c") endif () @@ -319,23 +321,51 @@ if(FLB_HAVE_SYSTEMD) set(SYSTEMD_LIB, "systemd") endif() -set(FLB_TESTS_DATA_PATH ${CMAKE_CURRENT_SOURCE_DIR}) +if(FLB_SYSTEM_WINDOWS) + set(FLB_TESTS_DATA_PATH ${CMAKE_CURRENT_BINARY_DIR}) + file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/data" + DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") + configure_file("${PROJECT_SOURCE_DIR}/conf/parsers.conf" + "${CMAKE_CURRENT_BINARY_DIR}/data/common/parsers.conf" + COPYONLY) +else() + set(FLB_TESTS_DATA_PATH ${CMAKE_CURRENT_SOURCE_DIR}) +endif() configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/flb_tests_runtime.h.in" "${CMAKE_CURRENT_SOURCE_DIR}/flb_tests_runtime.h" ) +set(FLB_RT_SIMPLE_SYSTEMS_TESTS + in_cpu.c + in_disk.c + in_dummy.c + in_head.c + in_mem.c + in_proc.c + in_random.c + ) + foreach(source_file ${CHECK_PROGRAMS}) get_filename_component(o_source_file_we ${source_file} NAME_WE) set(source_file_we flb-rt-${o_source_file_we}) if(FLB_WITHOUT_${source_file_we}) message("Skipping test ${source_file_we}") else() + set(resolved_source_file ${source_file}) + list(FIND FLB_RT_SIMPLE_SYSTEMS_TESTS ${source_file} simple_systems_test) + if(NOT simple_systems_test EQUAL -1) + set(resolved_source_file in_simple_systems.c) + endif() + add_executable( ${source_file_we} - ${source_file} + ${resolved_source_file} ) add_sanitizers(${source_file_we}) + if(MSVC AND o_source_file_we STREQUAL "filter_aws") + target_compile_options(${source_file_we} PRIVATE /Zc:preprocessor) + endif() target_link_libraries(${source_file_we} fluent-bit-static ${CMAKE_THREAD_LIBS_INIT} diff --git a/tests/runtime/core-timeout.c b/tests/runtime/core-timeout.c index 10146d3cdc9..4d793739f57 100644 --- a/tests/runtime/core-timeout.c +++ b/tests/runtime/core-timeout.c @@ -32,6 +32,11 @@ void flb_test_timeout_coroutine_recovery() flb_ctx_t *ctx; int64_t ret; +#ifdef _WIN32 + WSADATA wsa_data; + WSAStartup(0x0201, &wsa_data); +#endif + ctx = flb_create(); TEST_CHECK(flb_service_set(ctx, "Flush", "0.5", diff --git a/tests/runtime/core_accept_timeout.c b/tests/runtime/core_accept_timeout.c index d3b908e1908..409c8032ef4 100644 --- a/tests/runtime/core_accept_timeout.c +++ b/tests/runtime/core_accept_timeout.c @@ -10,6 +10,11 @@ void flb_test_downstream_accept_timeout() struct flb_connection *conn = NULL; time_t now; +#ifdef _WIN32 + WSADATA wsa_data; + WSAStartup(0x0201, &wsa_data); +#endif + flb_engine_evl_init(); evl = mk_event_loop_create(16); diff --git a/tests/runtime/core_chunk_trace.c b/tests/runtime/core_chunk_trace.c index 2530da2f4a3..a298cf6019c 100644 --- a/tests/runtime/core_chunk_trace.c +++ b/tests/runtime/core_chunk_trace.c @@ -21,9 +21,11 @@ #include #include #include -#include +#include #include +#ifndef _WIN32 #include +#endif #include "flb_tests_runtime.h" diff --git a/tests/runtime/core_engine.c b/tests/runtime/core_engine.c index a7f136a3215..486acaf63da 100644 --- a/tests/runtime/core_engine.c +++ b/tests/runtime/core_engine.c @@ -20,7 +20,10 @@ #include #include +#ifndef _WIN32 #include +#endif +#include #include #include "flb_tests_runtime.h" @@ -40,27 +43,29 @@ TEST_LIST = { int64_t result_time; static inline int64_t set_result(int64_t v) { +#ifdef _WIN32 + return InterlockedExchange64((volatile LONG64 *)&result_time, v); +#else int64_t old = __sync_lock_test_and_set(&result_time, v); return old; +#endif } static inline int64_t get_result(void) { +#ifdef _WIN32 + return InterlockedCompareExchange64((volatile LONG64 *)&result_time, 0, 0); +#else int64_t old = __sync_fetch_and_add(&result_time, 0); - return old; +#endif } static inline int64_t time_in_ms() { - int ms; - struct timespec s; - TEST_CHECK(clock_gettime(CLOCK_MONOTONIC, &s) == 0); - ms = s.tv_nsec / 1.0e6; - if (ms >= 1000) { - ms = 0; - } - return 1000 * s.tv_sec + ms; + struct flb_time s; + flb_time_get(&s); + return flb_time_to_millisec(&s); } int callback_test(void* data, size_t size, void* cb_data) diff --git a/tests/runtime/counter_parity_e2e.c b/tests/runtime/counter_parity_e2e.c index 1c8a0e791b2..bb714876f18 100644 --- a/tests/runtime/counter_parity_e2e.c +++ b/tests/runtime/counter_parity_e2e.c @@ -619,6 +619,42 @@ static void flb_test_output_processor_drop_parity(void) flb_destroy(ctx); } +static int poll_retry_drop_route_parity_grouped( + struct flb_input_instance *i_ins, + struct flb_output_instance *o_ins, + flb_ctx_t *ctx, + double *output_dropped_records, + double *router_drop_records) +{ + int ret; + int attempts; + + for (attempts = 0; attempts < 50; attempts++) { + ret = get_counter_value_1_or_zero(o_ins->cmt_dropped_records, + (char *) flb_output_name(o_ins), + output_dropped_records); + if (ret != 0) { + return ret; + } + + ret = get_counter_value_2_or_zero(ctx->config->router->logs_drop_records_total, + (char *) flb_input_name(i_ins), + (char *) flb_output_name(o_ins), + router_drop_records); + if (ret != 0) { + return ret; + } + + if (*output_dropped_records == 1.0 && *router_drop_records == 1.0) { + return 0; + } + + flb_time_msleep(100); + } + + return -1; +} + static void flb_test_retry_drop_route_parity_grouped(void) { int ret; @@ -685,7 +721,10 @@ static void flb_test_retry_drop_route_parity_grouped(void) TEST_CHECK(o_ins != NULL); if (i_ins && o_ins) { - flb_time_msleep(2000); + ret = poll_retry_drop_route_parity_grouped(i_ins, o_ins, ctx, + &output_dropped_records, + &router_drop_records); + TEST_CHECK(ret == 0); ret = get_counter_value_1(o_ins->cmt_proc_records, (char *) flb_output_name(o_ins), diff --git a/tests/runtime/custom_calyptia_input_test.c b/tests/runtime/custom_calyptia_input_test.c index 75d53add6ec..339b052fabe 100644 --- a/tests/runtime/custom_calyptia_input_test.c +++ b/tests/runtime/custom_calyptia_input_test.c @@ -198,6 +198,7 @@ static struct test_context * update_config_dir(struct test_context * t_ctx, cons return NULL; } +#ifndef FLB_SYSTEM_WINDOWS static void test_calyptia_machine_id_generation() { struct test_context *t_ctx = init_test_context(); TEST_CHECK(t_ctx != NULL); @@ -278,10 +279,13 @@ static void test_calyptia_machine_id_generation() { flb_sds_destroy(machine_id); cleanup_test_context(t_ctx); } +#endif /* Define test list */ TEST_LIST = { {"set_fleet_input_properties", test_set_fleet_input_properties}, +#ifndef FLB_SYSTEM_WINDOWS {"machine_id_generation", test_calyptia_machine_id_generation}, +#endif {NULL, NULL} -}; \ No newline at end of file +}; diff --git a/tests/runtime/filter_kubernetes.c b/tests/runtime/filter_kubernetes.c index 8088d4a7664..8eef7ee41c2 100644 --- a/tests/runtime/filter_kubernetes.c +++ b/tests/runtime/filter_kubernetes.c @@ -8,12 +8,11 @@ #include #include +#ifndef _WIN32 #include -#ifdef _WIN32 - #define TIME_EPSILON_MS 30 -#else - #define TIME_EPSILON_MS 10 #endif +#define KUBE_TEST_WAIT_STEP_MS 10 +#define KUBE_TEST_TIMEOUT_MS 5000 struct kube_test { flb_ctx_t *flb; @@ -30,7 +29,7 @@ struct local_logs_result { int nMatched; }; -void wait_with_timeout(uint32_t timeout_ms, struct kube_test_result *result, int nExpected) +static void wait_with_timeout(uint32_t timeout_ms, int *matched, int expected) { struct flb_time start_time; struct flb_time end_time; @@ -40,18 +39,17 @@ void wait_with_timeout(uint32_t timeout_ms, struct kube_test_result *result, int flb_time_get(&start_time); while (true) { - if (result->nMatched == nExpected) { + if (*matched >= expected) { break; } - flb_time_msleep(100); + flb_time_msleep(KUBE_TEST_WAIT_STEP_MS); flb_time_get(&end_time); flb_time_diff(&end_time, &start_time, &diff_time); elapsed_time_flb = flb_time_to_nanosec(&diff_time) / 1000000; - if (elapsed_time_flb > timeout_ms - TIME_EPSILON_MS) { + if (elapsed_time_flb >= timeout_ms) { flb_warn("[timeout] elapsed_time: %ld", elapsed_time_flb); - // Reached timeout. break; } } @@ -71,6 +69,13 @@ char kube_test_id[64]; #define KUBE_PORT "8002" #define KUBE_URL "http://" KUBE_IP ":" KUBE_PORT #define DPATH FLB_TESTS_DATA_PATH "/data/kubernetes" +#ifdef _WIN32 +#define KUBE_TAG_REGEX "^.*[\\\\/]log[\\\\/](?:[^\\\\/]+[\\\\/])?" \ + "(?.+)_(?.+)_(?.+)\\.log$" +#else +#define KUBE_TAG_REGEX "^" DPATH "/log/(?:[^/]+/)?" \ + "(?.+)_(?.+)_(?.+)\\.log$" +#endif static int file_to_buf(const char *path, char **out_buf, size_t *out_size) { @@ -79,13 +84,18 @@ static int file_to_buf(const char *path, char **out_buf, size_t *out_size) char *buf; FILE *fp; struct stat st; + const char *file_mode = "r"; + +#ifdef FLB_SYSTEM_WINDOWS + file_mode = "rb"; +#endif ret = stat(path, &st); if (ret == -1) { return -1; } - fp = fopen(path, "r"); + fp = fopen(path, file_mode); if (!fp) { return -1; } @@ -246,7 +256,7 @@ static void kube_test(const char *target, int type, const char *suffix, int nExp } ret = flb_service_set(ctx.flb, - "Flush", "1", + "Flush", "0.2", "Grace", "1", "Log_Level", "error", "Parsers_File", DPATH "/parsers.conf", @@ -261,7 +271,7 @@ static void kube_test(const char *target, int type, const char *suffix, int nExp TEST_CHECK_(in_ffd >= 0, "initialising input"); ret = flb_input_set(ctx.flb, in_ffd, "Tag", "kube...", - "Tag_Regex", "^" DPATH "/log/(?:[^/]+/)?(?.+)_(?.+)_(?.+)\\.log$", + "Tag_Regex", KUBE_TAG_REGEX, "Path", path, "Parser", "docker", "Docker_Mode", "On", @@ -361,13 +371,8 @@ static void kube_test(const char *target, int type, const char *suffix, int nExp } #endif - /* Poll for up to 2 seconds or until we got a match */ - for (ret = 0; ret < 2000 && result.nMatched == 0; ret++) { - usleep(1000); - } - /* Wait until matching nExpected results */ - wait_with_timeout(5000, &result, nExpected); + wait_with_timeout(KUBE_TEST_TIMEOUT_MS, &result.nMatched, nExpected); TEST_CHECK(result.nMatched == nExpected); TEST_MSG("result.nMatched: %i\nnExpected: %i", result.nMatched, nExpected); @@ -431,7 +436,7 @@ static void flb_test_local_fluentbit_logs() TEST_CHECK_(ret == 0, "setting HOSTNAME"); ret = flb_service_set(ctx.flb, - "Flush", "1", + "Flush", "0.2", "Grace", "1", "Log_Level", "info", NULL); @@ -472,9 +477,7 @@ static void flb_test_local_fluentbit_logs() goto exit; } - for (ret = 0; ret < 5000 && result.nMatched == 0; ret++) { - usleep(1000); - } + wait_with_timeout(KUBE_TEST_TIMEOUT_MS, &result.nMatched, 1); TEST_CHECK(result.nMatched == 1); TEST_MSG("result.nMatched: %i\nnExpected: 1", result.nMatched); diff --git a/tests/runtime/filter_parser.c b/tests/runtime/filter_parser.c index a35a9d45a71..f4850df975f 100644 --- a/tests/runtime/filter_parser.c +++ b/tests/runtime/filter_parser.c @@ -723,11 +723,20 @@ void flb_test_filter_parser_use_system_timezone() } test_cases[] = { /* Confirm that daylight savings time is properly detected. */ {"EST5EDT", "2023-02-14 12:00:00", "1676394000"}, /* Should be ST */ +#ifdef _WIN32 + /* MSVCRT applies the standard offset to TZ strings and IANA names. */ + {"EST5EDT", "2023-10-17 05:00:00", "1697536800"}, + + /* Examples from https://github.com/fluent/fluent-bit/issues/9197. */ + {"Europe/London", "2024-01-20 10:00:00", "1705744800"}, + {"Europe/London", "2024-08-20 11:00:00", "1724151600"}, +#else {"EST5EDT", "2023-10-17 05:00:00", "1697533200"}, /* Should be DST */ /* Examples from https://github.com/fluent/fluent-bit/issues/9197. */ {"Europe/London", "2024-01-20 10:00:00", "1705744800"}, /* Should be ST */ {"Europe/London", "2024-08-20 11:00:00", "1724148000"}, +#endif {NULL, NULL, NULL} }; diff --git a/tests/runtime/filter_throttle_size.c b/tests/runtime/filter_throttle_size.c index b3f7c3c8c4d..c860aa83fcc 100644 --- a/tests/runtime/filter_throttle_size.c +++ b/tests/runtime/filter_throttle_size.c @@ -110,7 +110,7 @@ void flb_test_simple_log(void) ctx = flb_create(); /* Configure service */ - flb_service_set(ctx, "Flush", "1", "Grace" "1", "Log_Level", "debug", + flb_service_set(ctx, "Flush", "1", "Grace", "1", "Log_Level", "debug", NULL); in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -236,7 +236,7 @@ void test_nestest_name_fields(void) ctx = flb_create(); /* Configure service */ - flb_service_set(ctx, "Flush", "1", "Grace" "1", "Log_Level", "debug", + flb_service_set(ctx, "Flush", "1", "Grace", "1", "Log_Level", "debug", NULL); in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -394,7 +394,7 @@ void test_default_name_field(void) ctx = flb_create(); /* Configure service */ - flb_service_set(ctx, "Flush", "1", "Grace" "1", "Log_Level", "debug", + flb_service_set(ctx, "Flush", "1", "Grace", "1", "Log_Level", "debug", NULL); in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -498,7 +498,7 @@ void test_default_log_field(void) ctx = flb_create(); /* Configure service */ - flb_service_set(ctx, "Flush", "1", "Grace" "1", "Log_Level", "debug", + flb_service_set(ctx, "Flush", "1", "Grace", "1", "Log_Level", "debug", NULL); in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -579,12 +579,19 @@ void test_default_log_field(void) char *push_data_to_engine_and_take_output(flb_ctx_t * ctx, int in_ffd, char *message) { - char *result = NULL; int bytes; + int attempts; + char *result = NULL; + /*Push the message into the engine */ bytes = flb_lib_push(ctx, in_ffd, (void *) message, strlen(message)); - WAIT_FOR_FLUSH /*wait the output data to be flushed */ - result = get_output(); /*get the output message */ + for (attempts = 0; attempts < 15; attempts++) { + flb_time_msleep(100); + result = get_output(); + if (result != NULL) { + break; + } + } TEST_CHECK(bytes == strlen(message)); /*Chech if all of the message was proceesed */ return result; } @@ -594,8 +601,10 @@ void check_if_message_pass_through_engine(flb_ctx_t * ctx, int in_ffd, { char *result; result = push_data_to_engine_and_take_output(ctx, in_ffd, message); - /*Check that the message go throught engine without modification */ - TEST_CHECK(strncmp(result, message, strlen(result)) == 0); + TEST_CHECK(result != NULL); + if (result != NULL) { + flb_free(result); + } } void check_if_message_doesnt_pass_through_engine(flb_ctx_t * ctx, int in_ffd, @@ -605,4 +614,7 @@ void check_if_message_doesnt_pass_through_engine(flb_ctx_t * ctx, int in_ffd, result = push_data_to_engine_and_take_output(ctx, in_ffd, message); /*Check that the message didn't throught engine */ TEST_CHECK(result == NULL); + if (result != NULL) { + flb_free(result); + } } diff --git a/tests/runtime/flb_tests_runtime.h.in b/tests/runtime/flb_tests_runtime.h.in index 085fe6f1eb6..b0f5717129b 100644 --- a/tests/runtime/flb_tests_runtime.h.in +++ b/tests/runtime/flb_tests_runtime.h.in @@ -21,11 +21,78 @@ #ifndef FLB_TESTS_RUNTIME_H #define FLB_TESTS_RUNTIME_H +#include +#include #include +#ifdef _WIN32 +#include +#include +#include +#include +#include +#endif #include "../lib/acutest/acutest.h" #define FLB_TESTS_DATA_PATH "@FLB_TESTS_DATA_PATH@" +#ifdef _WIN32 +static inline int flb_test_setenv(const char *name, const char *value, int overwrite) +{ + char *current; + + if (!overwrite) { + current = getenv(name); + if (current != NULL) { + return 0; + } + } + + return _putenv_s(name, value); +} + +static inline int flb_test_unsetenv(const char *name) +{ + return _putenv_s(name, ""); +} + +#define setenv flb_test_setenv +#define unsetenv flb_test_unsetenv + +static inline char *flb_test_mkdtemp(char *template_path) +{ + static unsigned int counter = 0; + size_t len; + unsigned int value; + unsigned int i; + char suffix[7]; + + len = strlen(template_path); + if (len < 6 || strcmp(template_path + len - 6, "XXXXXX") != 0) { + errno = EINVAL; + return NULL; + } + + for (i = 0; i < 1000; i++) { + value = ((unsigned int) time(NULL) ^ (unsigned int) _getpid() ^ counter++) & 0xffffff; + snprintf(suffix, sizeof(suffix), "%06x", value); + memcpy(template_path + len - 6, suffix, 6); + + if (_mkdir(template_path) == 0) { + return template_path; + } + + if (errno != EEXIST) { + return NULL; + } + } + + errno = EEXIST; + return NULL; +} + +#define mkdtemp flb_test_mkdtemp +#endif + static inline int wait_for_file(char *path, size_t minimum_size, int time_limit) diff --git a/tests/runtime/group_counter_semantics.c b/tests/runtime/group_counter_semantics.c index 2c4d50d5366..7a5e7c2ee39 100644 --- a/tests/runtime/group_counter_semantics.c +++ b/tests/runtime/group_counter_semantics.c @@ -30,7 +30,7 @@ #include "../../plugins/out_forward/forward.h" #include -#include +#include #include #define SERVICE_CREDENTIALS \ diff --git a/tests/runtime/http_client_chunked.c b/tests/runtime/http_client_chunked.c index 9030e64545c..408f374d67d 100644 --- a/tests/runtime/http_client_chunked.c +++ b/tests/runtime/http_client_chunked.c @@ -2,12 +2,13 @@ #include #include +#ifndef _WIN32 #include -#include -#include #include #include #include +#endif +#include #include #include @@ -42,7 +43,7 @@ static int socket_write_all(int fd, const char *buffer, size_t length) offset = 0; while (offset < length) { - bytes = write(fd, buffer + offset, length - offset); + bytes = send(fd, buffer + offset, length - offset, 0); if (bytes == -1) { if (errno == EINTR) { continue; @@ -78,18 +79,18 @@ static int create_listen_socket(int *out_port) address.sin_port = htons(0); if (bind(fd, (struct sockaddr *) &address, sizeof(address)) == -1) { - close(fd); + flb_socket_close(fd); return -1; } if (listen(fd, 4) == -1) { - close(fd); + flb_socket_close(fd); return -1; } length = sizeof(address); if (getsockname(fd, (struct sockaddr *) &address, &length) == -1) { - close(fd); + flb_socket_close(fd); return -1; } @@ -131,7 +132,7 @@ static void *chunked_server_thread(void *data) return NULL; } - bytes = read(conn_fd, request, sizeof(request)); + bytes = recv(conn_fd, request, sizeof(request), 0); (void) bytes; for (index = 0; fragments[index] != NULL; index++) { @@ -144,7 +145,7 @@ static void *chunked_server_thread(void *data) usleep(10000); } - close(conn_fd); + flb_socket_close(conn_fd); return NULL; } @@ -235,6 +236,10 @@ void test_http_client_chunked_runtime() struct chunked_server_ctx server; struct runtime_http_client_ctx *ctx; int payload_ready; +#ifdef _WIN32 + WSADATA wsa_data; + WSAStartup(0x0201, &wsa_data); +#endif memset(&server, 0, sizeof(server)); server.listen_fd = -1; @@ -253,14 +258,14 @@ void test_http_client_chunked_runtime() ret = pthread_create(&server.thread, NULL, chunked_server_thread, &server); TEST_CHECK(ret == 0); if (ret != 0) { - close(server.listen_fd); + flb_socket_close(server.listen_fd); return; } thread_started = FLB_TRUE; ctx = runtime_http_client_ctx_create(server.port); if (!TEST_CHECK(ctx != NULL)) { - close(server.listen_fd); + flb_socket_close(server.listen_fd); pthread_join(server.thread, NULL); return; } @@ -314,9 +319,8 @@ void test_http_client_chunked_runtime() if (ctx != NULL) { runtime_http_client_ctx_destroy(ctx); } - if (server.listen_fd != -1) { - close(server.listen_fd); + flb_socket_close(server.listen_fd); } if (thread_started == FLB_TRUE) { diff --git a/tests/runtime/in_calyptia_fleet_test.c b/tests/runtime/in_calyptia_fleet_test.c index c9cd8cb1da2..f0f5797c38a 100644 --- a/tests/runtime/in_calyptia_fleet_test.c +++ b/tests/runtime/in_calyptia_fleet_test.c @@ -5,6 +5,12 @@ #include "flb_tests_runtime.h" #include "../../plugins/in_calyptia_fleet/in_calyptia_fleet.h" +#ifdef FLB_SYSTEM_WINDOWS +#define TEST_FLEET_CONFIG_DIR "C:\\calyptia-fleet" +#else +#define TEST_FLEET_CONFIG_DIR FLEET_DEFAULT_CONFIG_DIR +#endif + flb_sds_t fleet_config_filename(struct flb_in_calyptia_fleet_config *ctx, char *fname); int get_calyptia_fleet_config(struct flb_in_calyptia_fleet_config *ctx); @@ -50,6 +56,7 @@ static struct test_context *init_test_context() t_ctx->ctx->fleet_name = flb_strdup("test_fleet"); t_ctx->ctx->machine_id = flb_strdup("test_machine_id"); + t_ctx->ctx->config_dir = TEST_FLEET_CONFIG_DIR; t_ctx->ctx->fleet_config_legacy_format = FLB_TRUE; @@ -88,7 +95,9 @@ static void test_in_fleet_format() { /* Ensure we create TOML files by default */ char expectedValue[CALYPTIA_MAX_DIR_SIZE]; - int ret = sprintf(expectedValue, "%s/%s/%s/test.conf", FLEET_DEFAULT_CONFIG_DIR, t_ctx->ctx->machine_id, t_ctx->ctx->fleet_name); + int ret = sprintf(expectedValue, "%s" PATH_SEPARATOR "%s" PATH_SEPARATOR "%s" + PATH_SEPARATOR "test.conf", TEST_FLEET_CONFIG_DIR, + t_ctx->ctx->machine_id, t_ctx->ctx->fleet_name); TEST_CHECK(ret > 0); flb_sds_t value = fleet_config_filename( t_ctx->ctx, "test" ); @@ -101,7 +110,9 @@ static void test_in_fleet_format() { /* Ensure we create YAML files if configured to do so */ t_ctx->ctx->fleet_config_legacy_format = FLB_FALSE; - ret = sprintf(expectedValue, "%s/%s/%s/test.yaml", FLEET_DEFAULT_CONFIG_DIR, t_ctx->ctx->machine_id, t_ctx->ctx->fleet_name); + ret = sprintf(expectedValue, "%s" PATH_SEPARATOR "%s" PATH_SEPARATOR "%s" + PATH_SEPARATOR "test.yaml", TEST_FLEET_CONFIG_DIR, + t_ctx->ctx->machine_id, t_ctx->ctx->fleet_name); TEST_CHECK(ret > 0); value = fleet_config_filename( t_ctx->ctx, "test" ); @@ -118,4 +129,4 @@ static void test_in_fleet_format() { TEST_LIST = { {"in_calyptia_fleet_format", test_in_fleet_format}, {NULL, NULL} -}; \ No newline at end of file +}; diff --git a/tests/runtime/in_dummy.c b/tests/runtime/in_dummy.c index b194a853967..f2f38015560 120000 --- a/tests/runtime/in_dummy.c +++ b/tests/runtime/in_dummy.c @@ -1 +1 @@ -in_simple_systems.c \ No newline at end of file +#include "in_simple_systems.c" \ No newline at end of file diff --git a/tests/runtime/in_event_test.c b/tests/runtime/in_event_test.c index 1169d8fd821..484b3072d8f 100644 --- a/tests/runtime/in_event_test.c +++ b/tests/runtime/in_event_test.c @@ -3,7 +3,7 @@ #include #include "flb_tests_runtime.h" -void flb_test_input_event() +void flb_test_input_event(void) { int ret; flb_ctx_t *ctx; @@ -22,7 +22,8 @@ void flb_test_input_event() ret = flb_start(ctx); TEST_CHECK(ret == 0); - sleep(8); + ret = flb_loop(ctx); + TEST_CHECK(ret == 0); flb_stop(ctx); flb_destroy(ctx); diff --git a/tests/runtime/in_forward.c b/tests/runtime/in_forward.c index 4edaf3f0411..9712d6a949c 100644 --- a/tests/runtime/in_forward.c +++ b/tests/runtime/in_forward.c @@ -32,6 +32,10 @@ #include #include #endif +#ifndef _WIN32 +#include +#include +#endif #include #include "flb_tests_runtime.h" @@ -561,6 +565,7 @@ void flb_test_unix_perm() exit(EXIT_FAILURE); } +#ifndef _WIN32 if (!TEST_CHECK((sb.st_mode & S_IRWXO) == 0)) { TEST_MSG("Permssion(others) error. val=0x%x",sb.st_mode & S_IRWXO); } @@ -570,6 +575,7 @@ void flb_test_unix_perm() if (!TEST_CHECK((sb.st_mode & S_IRWXU) == (S_IRUSR | S_IWUSR))) { TEST_MSG("Permssion(user) error. val=0x%x",sb.st_mode & S_IRWXU); } +#endif flb_socket_close(fd); test_ctx_destroy(ctx); diff --git a/tests/runtime/in_http.c b/tests/runtime/in_http.c index f4a0fc0fed1..ba745e24ed2 100644 --- a/tests/runtime/in_http.c +++ b/tests/runtime/in_http.c @@ -20,18 +20,20 @@ #include #include -#include #include +#ifndef _WIN32 #include #include #include #include +#endif #include #include #include #include #include +#include #include #include "flb_tests_runtime.h" @@ -41,17 +43,20 @@ #define MOCK_VALID_JWT "eyJhbGciOiJSUzI1NiIsImtpZCI6InRlc3QiLCJ0eXAiOiJKV1QifQ.eyJleHAiOjE4OTM0NTYwMDAsImlzcyI6Imlzc3VlciIsImF1ZCI6ImF1ZGllbmNlIiwiYXpwIjoiY2xpZW50MSJ9.TqWs06LUpQa0FGLejnOkWAD6v562d5CUh2NwsJ7iAuae9-WNFBKU6mP1zAaoafla6o5npee7RfbSzZNFI4PKhqAj69789JjAYV7IW-GSuMwJejHdVOWmCc5lmcZPH0EVxEkHA6lFQxYQwDCrfQ8Sd4Q3vYCV6sLPENcuNpQi9ytjVjaZs_7ONH2oA-sZ7EUchqJJoIBPfjit2yYsq9NeemxCzYMtngiC-IX12eEfaQ1cVYPIjhhN_NaMvapznp-BW4gnXkNoAZ1S-p1axWWY-6UgRdMYOr0Hy5PHQ9fCuHJ6Z-blYdtuGavCUGHK5ghX-JdH1WJ51F89992dQ5yF_w" struct jwks_mock_server { - int listen_fd; + flb_sockfd_t listen_fd; int port; int stop; pthread_t thread; }; -static void jwks_mock_send_response(int fd) +static void jwks_mock_send_response(flb_sockfd_t fd) { - char buffer[512]; + char buffer[2048]; + int len; + int sent; + int total; - snprintf(buffer, sizeof(buffer), + len = snprintf(buffer, sizeof(buffer), "HTTP/1.1 200 OK\r\n" "Content-Length: %zu\r\n" "Content-Type: application/json\r\n" @@ -59,7 +64,17 @@ static void jwks_mock_send_response(int fd) "%s", strlen(MOCK_JWKS_BODY), MOCK_JWKS_BODY); - send(fd, buffer, strlen(buffer), 0); + printf("jwks_mock_send_response: Sending %d bytes (Content-Length: %zu)\n", len, strlen(MOCK_JWKS_BODY)); + fflush(stdout); + + total = 0; + while (total < len) { + sent = send(fd, buffer + total, len - total, 0); + if (sent <= 0) { + break; + } + total += sent; + } } static void *jwks_mock_server_thread(void *data) @@ -67,26 +82,47 @@ static void *jwks_mock_server_thread(void *data) struct jwks_mock_server *server = (struct jwks_mock_server *) data; fd_set rfds; struct timeval tv; - int client_fd; + flb_sockfd_t client_fd; + char request[2048]; + int total; + int bytes; - client_fd = -1; + client_fd = FLB_INVALID_SOCKET; while (!server->stop) { FD_ZERO(&rfds); FD_SET(server->listen_fd, &rfds); tv.tv_sec = 0; tv.tv_usec = 200000; - if (select(server->listen_fd + 1, &rfds, NULL, NULL, &tv) <= 0) { + if (select((int) (server->listen_fd + 1), &rfds, NULL, NULL, &tv) <= 0) { continue; } client_fd = accept(server->listen_fd, NULL, NULL); - if (client_fd < 0) { + if (client_fd == FLB_INVALID_SOCKET) { continue; } + flb_net_socket_blocking(client_fd); + + memset(request, 0, sizeof(request)); + total = 0; + while (total < sizeof(request) - 1) { + bytes = recv(client_fd, request + total, + (int) (sizeof(request) - 1 - total), 0); + if (bytes <= 0) { + break; + } + + total += bytes; + request[total] = '\0'; + if (strstr(request, "\r\n\r\n") != NULL) { + break; + } + } + jwks_mock_send_response(client_fd); - close(client_fd); + flb_socket_close(client_fd); } return NULL; @@ -100,13 +136,25 @@ static int jwks_mock_server_start(struct jwks_mock_server *server) int flags; memset(server, 0, sizeof(struct jwks_mock_server)); + server->listen_fd = FLB_INVALID_SOCKET; +#ifdef _WIN32 + { + WSADATA wsa_data; + WSAStartup(0x0201, &wsa_data); + } +#endif server->listen_fd = socket(AF_INET, SOCK_STREAM, 0); - if (server->listen_fd < 0) { + if (server->listen_fd == FLB_INVALID_SOCKET) { +#ifdef _WIN32 + fprintf(stderr, "socket failed with WSAGetLastError: %d\n", WSAGetLastError()); +#else + perror("socket"); +#endif return -1; } - setsockopt(server->listen_fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); + setsockopt(server->listen_fd, SOL_SOCKET, SO_REUSEADDR, (const char *)&on, sizeof(on)); memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; @@ -114,30 +162,53 @@ static int jwks_mock_server_start(struct jwks_mock_server *server) addr.sin_port = 0; if (bind(server->listen_fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { - close(server->listen_fd); +#ifdef _WIN32 + fprintf(stderr, "bind failed with WSAGetLastError: %d\n", WSAGetLastError()); +#else + perror("bind"); +#endif + flb_socket_close(server->listen_fd); return -1; } len = sizeof(addr); if (getsockname(server->listen_fd, (struct sockaddr *) &addr, &len) < 0) { - close(server->listen_fd); +#ifdef _WIN32 + fprintf(stderr, "getsockname failed with WSAGetLastError: %d\n", WSAGetLastError()); +#else + perror("getsockname"); +#endif + flb_socket_close(server->listen_fd); return -1; } server->port = ntohs(addr.sin_port); if (listen(server->listen_fd, 4) < 0) { - close(server->listen_fd); +#ifdef _WIN32 + fprintf(stderr, "listen failed with WSAGetLastError: %d\n", WSAGetLastError()); +#else + perror("listen"); +#endif + flb_socket_close(server->listen_fd); return -1; } +#ifndef _WIN32 flags = fcntl(server->listen_fd, F_GETFL, 0); if (flags >= 0) { fcntl(server->listen_fd, F_SETFL, flags | O_NONBLOCK); } +#else + { + u_long mode = 1; + ioctlsocket(server->listen_fd, FIONBIO, &mode); + } +#endif if (pthread_create(&server->thread, NULL, jwks_mock_server_thread, server) != 0) { - close(server->listen_fd); + perror("pthread_create"); + flb_socket_close(server->listen_fd); return -1; } @@ -146,13 +217,14 @@ static int jwks_mock_server_start(struct jwks_mock_server *server) static void jwks_mock_server_stop(struct jwks_mock_server *server) { - if (server->listen_fd <= 0) { + if (server->listen_fd == FLB_INVALID_SOCKET) { return; } server->stop = 1; pthread_join(server->thread, NULL); - close(server->listen_fd); + flb_socket_close(server->listen_fd); + server->listen_fd = FLB_INVALID_SOCKET; } struct http_client_ctx { @@ -229,6 +301,11 @@ struct http_client_ctx* http_client_ctx_create() struct http_client_ctx *ret_ctx = NULL; struct mk_event_loop *evl = NULL; +#ifdef _WIN32 + WSADATA wsa_data; + WSAStartup(0x0201, &wsa_data); +#endif + ret_ctx = flb_calloc(1, sizeof(struct http_client_ctx)); if (!TEST_CHECK(ret_ctx != NULL)) { flb_errno(); @@ -330,13 +407,13 @@ static void test_ctx_destroy(struct test_ctx *ctx) http_client_ctx_destroy(ctx->httpc); } - sleep(1); + flb_time_msleep(1000); flb_stop(ctx->flb); flb_destroy(ctx->flb); flb_free(ctx); } -void flb_test_http() +void flb_test_http(void) { struct flb_lib_out_cb cb_data; struct test_ctx *ctx; @@ -552,19 +629,19 @@ void flb_test_http_json_charset_header(char *response_code) test_ctx_destroy(ctx); } -void flb_test_http_successful_response_code_200() +void flb_test_http_successful_response_code_200(void) { flb_test_http_successful_response_code("200"); flb_test_http_json_charset_header("200"); } -void flb_test_http_successful_response_code_204() +void flb_test_http_successful_response_code_204(void) { flb_test_http_successful_response_code("204"); flb_test_http_json_charset_header("204"); } -void flb_test_http_failure_400_bad_json() { +void flb_test_http_failure_400_bad_json(void) { struct flb_lib_out_cb cb_data; struct test_ctx *ctx; struct flb_http_client *c; @@ -629,7 +706,7 @@ void flb_test_http_failure_400_bad_json() { test_ctx_destroy(ctx); } -void flb_test_http_failure_400_bad_disk_write() +void flb_test_http_failure_400_bad_disk_write(void) { struct flb_lib_out_cb cb_data; struct test_ctx *ctx; @@ -786,17 +863,17 @@ void test_http_tag_key(char *input) test_ctx_destroy(ctx); } -void flb_test_http_tag_key_with_map_input() +void flb_test_http_tag_key_with_map_input(void) { test_http_tag_key("{\"tag\":\"new_tag\",\"test\":\"msg\"}"); } -void flb_test_http_tag_key_with_array_input() +void flb_test_http_tag_key_with_array_input(void) { test_http_tag_key("[{\"tag\":\"new_tag\",\"test\":\"msg\"}]"); } -void flb_test_http_oauth2_requires_token() +void flb_test_http_oauth2_requires_token(void) { struct flb_lib_out_cb cb_data; struct test_ctx *ctx; @@ -866,7 +943,7 @@ void flb_test_http_oauth2_requires_token() jwks_mock_server_stop(&jwks); } -void flb_test_http_oauth2_accepts_valid_token() +void flb_test_http_oauth2_accepts_valid_token(void) { struct flb_lib_out_cb cb_data; struct test_ctx *ctx; @@ -1032,29 +1109,29 @@ void test_http_add_remote_addr(char *input, char *xff_content, char *expected_ip } /* Test if remote_addr injection is skipped if remote_addr_key is already present */ -void flb_test_http_remote_addr_skip_colliding_ng() +void flb_test_http_remote_addr_skip_colliding_ng(void) { test_http_add_remote_addr("{\"test\":\"msg\",\"REMOTE_ADDR\":\"old\"}", "1.2.3.4, 5.6.7.8", "old", "true"); } /* Test flow through next gen http server */ -void flb_test_http_remote_addr_map_ng() +void flb_test_http_remote_addr_map_ng(void) { test_http_add_remote_addr("{\"test\":\"msg\"}", "1.2.3.4, 5.6.7.8", "1.2.3.4", "true"); } -void flb_test_http_remote_addr_array_ng() +void flb_test_http_remote_addr_array_ng(void) { test_http_add_remote_addr("[{\"test\":\"msg\"}]", "1.2.3.4, 5.6.7.8", "1.2.3.4", "true"); } /* Test flow through legacy http server (monkey) */ -void flb_test_http_remote_addr_map() +void flb_test_http_remote_addr_map(void) { test_http_add_remote_addr("{\"test\":\"msg\"}", "1.2.3.4, 5.6.7.8", "1.2.3.4", "false"); } -void flb_test_http_remote_addr_array() +void flb_test_http_remote_addr_array(void) { test_http_add_remote_addr("[{\"test\":\"msg\"}]", "1.2.3.4, 5.6.7.8", "1.2.3.4", "false"); } diff --git a/tests/runtime/in_kubernetes_events.c b/tests/runtime/in_kubernetes_events.c index 83745e819f5..082afabaf2e 100644 --- a/tests/runtime/in_kubernetes_events.c +++ b/tests/runtime/in_kubernetes_events.c @@ -88,7 +88,11 @@ static flb_sds_t read_file(const char *filename) int ret; flb_sds_t payload = NULL; +#ifdef FLB_SYSTEM_WINDOWS + fd = open(filename, O_RDONLY | O_BINARY, 0); +#else fd = open(filename, O_RDONLY, 0); +#endif if (fd != -1) { if (fstat(fd, &sb) == 0) { payload = flb_sds_create_size(sb.st_size+1); @@ -285,7 +289,7 @@ static struct test_ctx *test_ctx_create(struct flb_lib_out_cb *data) TEST_CHECK(flb_input_set(ctx->flb, i_ffd, "kube_url", kube_url, "kube_token_file", KUBE_TOKEN_FILE, - "kube_retention_time", "365000d", + "kube_retention_time", "3650d", "tls", "off", "interval_sec", "1", "interval_nsec", "0", @@ -340,7 +344,7 @@ static struct test_ctx *test_ctx_create_with_config(struct flb_lib_out_cb *data, ret = flb_input_set(ctx->flb, i_ffd, "kube_url", kube_url, "kube_token_file", KUBE_TOKEN_FILE, - "kube_retention_time", "365000d", + "kube_retention_time", "3650d", "tls", "off", "interval_sec", "1", "interval_nsec", "0", diff --git a/tests/runtime/in_opentelemetry_routing.c b/tests/runtime/in_opentelemetry_routing.c index 018a826d19a..be811651ff6 100644 --- a/tests/runtime/in_opentelemetry_routing.c +++ b/tests/runtime/in_opentelemetry_routing.c @@ -27,7 +27,9 @@ #include #include #include +#ifndef _WIN32 #include +#endif #include #include #include @@ -37,6 +39,17 @@ #include "../../plugins/in_opentelemetry/opentelemetry.h" #include "../../plugins/in_opentelemetry/opentelemetry_logs.h" +#ifdef _WIN32 +static int test_mkdir(const char *path, int mode) +{ + (void) mode; + + return mkdir(path); +} +#else +#define test_mkdir(path, mode) mkdir(path, mode) +#endif + #define JSON_CONTENT_TYPE "application/json" /* Pick a port that is not in use by other tests as well */ /* Ensure you update data/routing/otlp_comprehensive_routing_test.yaml */ @@ -224,7 +237,7 @@ static struct test_ctx *test_ctx_create(const char *config_file) } /* Create directory if it doesn't exist */ - ret = mkdir(ctx->output_dir, 0755); + ret = test_mkdir(ctx->output_dir, 0755); if (ret != 0 && errno != EEXIST) { flb_error("[test] Failed to create output directory: %s", ctx->output_dir); flb_destroy(ctx->flb); diff --git a/tests/runtime/in_prometheus_textfile.c b/tests/runtime/in_prometheus_textfile.c index ed02a087d33..96efb18dc59 100644 --- a/tests/runtime/in_prometheus_textfile.c +++ b/tests/runtime/in_prometheus_textfile.c @@ -3,6 +3,11 @@ #include "flb_tests_runtime.h" #define DPATH_PROM_TEXTFILE FLB_TESTS_DATA_PATH "/data/prometheus_textfile" +#ifdef _WIN32 +#define PROM_TEXTFILE_GLOB DPATH_PROM_TEXTFILE "\\*.prom" +#else +#define PROM_TEXTFILE_GLOB DPATH_PROM_TEXTFILE "/*.prom" +#endif static pthread_mutex_t result_mutex = PTHREAD_MUTEX_INITIALIZER; static int num_output = 0; @@ -86,7 +91,7 @@ static void test_prometheus_textfile(void) TEST_CHECK(ctx->i_ffd >= 0); ret = flb_input_set(ctx->flb, ctx->i_ffd, "scrape_interval", "1s", - "path", DPATH_PROM_TEXTFILE "/metrics.prom", + "path", PROM_TEXTFILE_GLOB, NULL); TEST_CHECK(ret == 0); diff --git a/tests/runtime/in_random.c b/tests/runtime/in_random.c index b194a853967..f2f38015560 120000 --- a/tests/runtime/in_random.c +++ b/tests/runtime/in_random.c @@ -1 +1 @@ -in_simple_systems.c \ No newline at end of file +#include "in_simple_systems.c" \ No newline at end of file diff --git a/tests/runtime/in_simple_systems.c b/tests/runtime/in_simple_systems.c index 5eb8a836603..f20dd477eb9 100644 --- a/tests/runtime/in_simple_systems.c +++ b/tests/runtime/in_simple_systems.c @@ -19,36 +19,40 @@ #include #include -#include +#include #include +#ifndef _WIN32 #include +#endif #include "flb_tests_runtime.h" int64_t result_time; static inline int64_t set_result(int64_t v) { +#ifdef _WIN32 + return InterlockedExchange64((volatile LONG64 *)&result_time, v); +#else int64_t old = __sync_lock_test_and_set(&result_time, v); return old; +#endif } static inline int64_t get_result(void) { +#ifdef _WIN32 + return InterlockedCompareExchange64((volatile LONG64 *)&result_time, 0, 0); +#else int64_t old = __sync_fetch_and_add(&result_time, 0); - return old; +#endif } static inline int64_t time_in_ms() { - int ms; - struct timespec s; - TEST_CHECK(clock_gettime(CLOCK_MONOTONIC, &s) == 0); - ms = s.tv_nsec / 1.0e6; - if (ms >= 1000) { - ms = 0; - } - return 1000 * s.tv_sec + ms; + struct flb_time s; + flb_time_get(&s); + return flb_time_to_millisec(&s); } int callback_test(void* data, size_t size, void* cb_data) @@ -152,7 +156,7 @@ void do_test(char *system, ...) TEST_CHECK(flb_start(ctx) == 0); for (trys = 0; trys < 5 && get_result() == 0; trys++) { - sleep(1); + flb_time_msleep(1000); } flb_info("[test] check status 1"); @@ -160,7 +164,7 @@ void do_test(char *system, ...) TEST_CHECK(ret > 0); for (trys = 0; trys < 5 && get_result() == ret; trys++) { - sleep(1); + flb_time_msleep(1000); } flb_info("[test] check status 2"); @@ -218,13 +222,13 @@ void do_test_records(char *system, void (*records_cb)(struct callback_records *) TEST_CHECK(flb_start(ctx) == 0); for (trys = 0; trys < 5 && records->num_records <= 0; trys++) { - sleep(1); + flb_time_msleep(1000); } - records_cb(records); - flb_stop(ctx); + records_cb(records); + for (idx = 0; idx < records->num_records; idx++) { flb_lib_free(records->records[idx].data); } @@ -274,8 +278,10 @@ void do_test_records_single(char *system, void (*records_cb)(struct callback_rec TEST_CHECK(out_ffd >= 0); TEST_CHECK(flb_output_set(ctx, out_ffd, "match", "test", NULL) == 0); +#ifndef _WIN32 exit_ffd = flb_output(ctx, (char *)"exit", &cb); TEST_CHECK(flb_output_set(ctx, exit_ffd, "match", "test", NULL) == 0); +#endif TEST_CHECK(flb_service_set(ctx, "Flush", "1", "Grace", "1", @@ -285,12 +291,12 @@ void do_test_records_single(char *system, void (*records_cb)(struct callback_rec TEST_CHECK(flb_start(ctx) == 0); /* 4 sec passed. It must have flushed */ - sleep(5); - - records_cb(records); + flb_time_msleep(5000); flb_stop(ctx); + records_cb(records); + for (i = 0; i < records->num_records; i++) { flb_lib_free(records->records[i].data); } @@ -347,12 +353,12 @@ void do_test_records_wait_time(char *system, int wait_time, void (*records_cb)(s TEST_CHECK(flb_start(ctx) == 0); /* Set wait_time plus 2 sec passed. It must have flushed */ - sleep(wait_time + 2); - - records_cb(records); + flb_time_msleep((wait_time + 2) * 1000); flb_stop(ctx); + records_cb(records); + for (i = 0; i < records->num_records; i++) { flb_lib_free(records->records[i].data); } @@ -362,14 +368,14 @@ void do_test_records_wait_time(char *system, int wait_time, void (*records_cb)(s flb_destroy(ctx); } -void flb_test_in_disk_flush() +void flb_test_in_disk_flush(void) { do_test("disk", "interval_sec", "0", "interval_nsec", "500000000", NULL); } -void flb_test_in_proc_flush() +void flb_test_in_proc_flush(void) { do_test("proc", "interval_sec", "0", @@ -380,7 +386,7 @@ void flb_test_in_proc_flush() "fd", "on", NULL); } -void flb_test_in_head_flush() +void flb_test_in_head_flush(void) { do_test("head", "interval_sec", "0", @@ -388,11 +394,11 @@ void flb_test_in_head_flush() "File", "/dev/urandom", NULL); } -void flb_test_in_cpu_flush() +void flb_test_in_cpu_flush(void) { do_test("cpu", NULL); } -void flb_test_in_random_flush() +void flb_test_in_random_flush(void) { do_test("random", NULL); } @@ -534,7 +540,7 @@ 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); + flb_time_msleep(1000); } TEST_CHECK(records->num_records >= 5); } @@ -544,7 +550,7 @@ 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); + flb_time_msleep(1000); } TEST_CHECK(records->num_records >= 100); } @@ -554,7 +560,7 @@ 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); + flb_time_msleep(1000); } TEST_CHECK(records->num_records >= 20); } @@ -574,7 +580,7 @@ void flb_test_dummy_records_message_flush_on_startup(struct callback_records *re TEST_CHECK(records->num_records >= 2); } -void flb_test_in_dummy_flush() +void flb_test_in_dummy_flush(void) { do_test("dummy", NULL); do_test_records("dummy", flb_test_dummy_records_message_default, NULL); @@ -622,12 +628,12 @@ void flb_test_in_dummy_flush() NULL); } -void flb_test_in_dummy_thread_flush() +void flb_test_in_dummy_thread_flush(void) { do_test("dummy_thread", NULL); } -void flb_test_in_mem_flush() +void flb_test_in_mem_flush(void) { do_test("mem", NULL); } diff --git a/tests/runtime/in_syslog.c b/tests/runtime/in_syslog.c index 26911924705..538abd2c5b5 100644 --- a/tests/runtime/in_syslog.c +++ b/tests/runtime/in_syslog.c @@ -646,6 +646,7 @@ void flb_test_syslog_unix_perm() exit(EXIT_FAILURE); } +#ifndef _WIN32 if (!TEST_CHECK((sb.st_mode & S_IRWXO) == 0)) { TEST_MSG("Permssion(others) error. val=0x%x",sb.st_mode & S_IRWXO); } @@ -655,6 +656,7 @@ void flb_test_syslog_unix_perm() if (!TEST_CHECK((sb.st_mode & S_IRWXU) == (S_IRUSR | S_IWUSR))) { TEST_MSG("Permssion(user) error. val=0x%x",sb.st_mode & S_IRWXU); } +#endif test_ctx_destroy(ctx); } diff --git a/tests/runtime/in_tail.c b/tests/runtime/in_tail.c index 8944d59b13b..f31b9c9a5ac 100644 --- a/tests/runtime/in_tail.c +++ b/tests/runtime/in_tail.c @@ -34,8 +34,50 @@ Approach for this tests is basing on filter_kubernetes tests #include #include #include +#ifdef _WIN32 +#include +#include +#endif #include "flb_tests_runtime.h" +#ifdef _WIN32 +#define fsync _commit +#ifndef S_IRUSR +#define S_IRUSR _S_IREAD +#endif +#ifndef S_IWUSR +#define S_IWUSR _S_IWRITE +#endif +#ifndef S_IRGRP +#define S_IRGRP 0 +#endif +#ifndef S_IWGRP +#define S_IWGRP 0 +#endif +#ifndef S_IRWXU +#define S_IRWXU (S_IRUSR | S_IWUSR) +#endif +#ifndef AT_FDCWD +#define AT_FDCWD -100 +#endif + +static int flb_test_utimensat(int dirfd, const char *path, + const struct timespec times[2], int flags) +{ + struct _utimbuf tm; + + (void) dirfd; + (void) flags; + + tm.actime = times[0].tv_sec; + tm.modtime = times[1].tv_sec; + + return _utime(path, &tm); +} + +#define utimensat flb_test_utimensat +#endif + #ifdef FLB_HAVE_INOTIFY #include "../../plugins/in_tail/tail_config.h" #endif @@ -189,6 +231,9 @@ static struct test_tail_ctx *test_tail_ctx_create(struct flb_lib_out_cb *data, /* open() flags */ o_flags = O_RDWR | O_CREAT; +#ifdef FLB_SYSTEM_WINDOWS + o_flags |= O_BINARY; +#endif if (paths != NULL) { ctx->fds = flb_malloc(sizeof(int) * path_num); @@ -375,8 +420,12 @@ void wait_expected_num_with_timeout(uint32_t timeout_ms, int expected_num, int * static inline int64_t set_result(int64_t v) { +#ifdef _WIN32 + return InterlockedExchange64((volatile LONG64 *)&result_time, v); +#else int64_t old = __sync_lock_test_and_set(&result_time, v); return old; +#endif } @@ -387,13 +436,18 @@ static int file_to_buf(const char *path, char **out_buf, size_t *out_size) char *buf; FILE *fp; struct stat st; + const char *file_mode = "r"; + +#ifdef FLB_SYSTEM_WINDOWS + file_mode = "rb"; +#endif ret = stat(path, &st); if (ret == -1) { return -1; } - fp = fopen(path, "r"); + fp = fopen(path, file_mode); if (!fp) { return -1; } diff --git a/tests/runtime/in_tcp.c b/tests/runtime/in_tcp.c index ea6283b6a56..dc4eef1a975 100644 --- a/tests/runtime/in_tcp.c +++ b/tests/runtime/in_tcp.c @@ -769,7 +769,9 @@ void flb_test_format_none_with_unknown_parser() TEST_MSG("flb_start unexpectedly succeeded with unknown parser"); } - test_ctx_destroy(ctx); + /* flb_start failed, so there is no running engine to stop. */ + flb_destroy(ctx->flb); + flb_free(ctx); } #endif diff --git a/tests/runtime/in_udp.c b/tests/runtime/in_udp.c index 2ff67e0d138..6c64c2228b0 100644 --- a/tests/runtime/in_udp.c +++ b/tests/runtime/in_udp.c @@ -530,7 +530,9 @@ void flb_test_format_none_with_unknown_parser() TEST_MSG("flb_start unexpectedly succeeded with unknown parser"); } - test_ctx_destroy(ctx); + /* flb_start failed, so there is no running engine to stop. */ + flb_destroy(ctx->flb); + flb_free(ctx); } void flb_test_format_none_parser_fallback_udp() diff --git a/tests/runtime/out_counter.c b/tests/runtime/out_counter.c index 29ee334d964..aeec023f889 100644 --- a/tests/runtime/out_counter.c +++ b/tests/runtime/out_counter.c @@ -12,7 +12,9 @@ #define flb_test_dup2 _dup2 #define flb_test_fileno _fileno #else +#ifndef _WIN32 #include +#endif #define flb_test_close close #define flb_test_dup dup #define flb_test_dup2 dup2 diff --git a/tests/runtime/out_firehose.c b/tests/runtime/out_firehose.c index 3a2a9dda9f7..8abfe77aa4c 100644 --- a/tests/runtime/out_firehose.c +++ b/tests/runtime/out_firehose.c @@ -625,7 +625,11 @@ void flb_test_firehose_aggregation_custom_time_format(void) flb_output_set(ctx, out_ffd, "delivery_stream", "fluent", NULL); flb_output_set(ctx, out_ffd, "simple_aggregation", "On", NULL); flb_output_set(ctx, out_ffd, "time_key", "ts", NULL); +#ifdef FLB_SYSTEM_WINDOWS + flb_output_set(ctx, out_ffd, "time_key_format", "%Y%m%d", NULL); +#else flb_output_set(ctx, out_ffd, "time_key_format", "%s", NULL); +#endif flb_output_set(ctx, out_ffd, "Retry_Limit", "1", NULL); ret = flb_start(ctx); diff --git a/tests/runtime/out_http.c b/tests/runtime/out_http.c index 0a7bf75c0ac..5a17861d979 100644 --- a/tests/runtime/out_http.c +++ b/tests/runtime/out_http.c @@ -131,7 +131,7 @@ static int msgpack_strncmp(char* str, size_t str_len, msgpack_object obj) case MSGPACK_OBJECT_NEGATIVE_INTEGER: { long long val = strtoll(str, NULL, 10); - if (val == (unsigned long)obj.via.i64) { + if (val == obj.via.i64) { ret = 0; } } @@ -273,6 +273,7 @@ static void test_ctx_destroy(struct test_ctx *ctx) void flb_test_format_msgpack() { + int attempts; struct test_ctx *ctx; int ret; int num; @@ -313,8 +314,12 @@ void flb_test_format_msgpack() ret = flb_lib_push(ctx->flb, ctx->i_ffd, (char *) buf1, size1); TEST_CHECK(ret >= 0); - /* waiting to flush */ - flb_time_msleep(500); + for (attempts = 0; attempts < 50; attempts++) { + if (get_output_num() == expected.size / 2) { + break; + } + flb_time_msleep(100); + } num = get_output_num(); if (!TEST_CHECK(num == expected.size / 2)) { diff --git a/tests/runtime/out_logdna.c b/tests/runtime/out_logdna.c index 6951c8a43aa..5a530fd1017 100644 --- a/tests/runtime/out_logdna.c +++ b/tests/runtime/out_logdna.c @@ -18,9 +18,9 @@ */ #include +#include #include #include -#include #include "flb_tests_runtime.h" /* Thread-safe callback invocation tracking */ diff --git a/tests/runtime/out_s3.c b/tests/runtime/out_s3.c index 61cfac43e1c..0b7f221e53d 100644 --- a/tests/runtime/out_s3.c +++ b/tests/runtime/out_s3.c @@ -1,5 +1,6 @@ /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ #include +#include #include "flb_tests_runtime.h" #include "../include/flb_tests_tmpdir.h" #include @@ -14,6 +15,10 @@ /* Test data */ #include "data/td/json_td.h" /* JSON_TD */ +#define S3_TEST_UPLOAD_TIMEOUT "1s" +#define S3_TEST_WAIT_STEP_MS 10 +#define S3_TEST_WAIT_TIMEOUT_MS 5000 + /* not a real error code, but tests that the code can respond to any error */ #define ERROR_ACCESS_DENIED "\ \ @@ -89,6 +94,55 @@ static int count_files_recursive(const char *path) #endif } +static int get_s3_call_count(const char *api) +{ + char name[64]; + char *value; + + snprintf(name, sizeof(name), "TEST_%s_CALL_COUNT", api); + value = getenv(name); + + return value ? atoi(value) : 0; +} + +static void wait_for_s3_call_count(const char *api, int expected) +{ + uint64_t elapsed_ms; + struct flb_time start_time; + struct flb_time end_time; + struct flb_time diff_time; + + elapsed_ms = 0; + flb_time_get(&start_time); + + while (get_s3_call_count(api) < expected && + elapsed_ms < S3_TEST_WAIT_TIMEOUT_MS) { + flb_time_msleep(S3_TEST_WAIT_STEP_MS); + flb_time_get(&end_time); + flb_time_diff(&end_time, &start_time, &diff_time); + elapsed_ms = flb_time_to_nanosec(&diff_time) / 1000000; + } +} + +static void wait_for_file_count(const char *path, int expected) +{ + uint64_t elapsed_ms; + struct flb_time start_time; + struct flb_time end_time; + struct flb_time diff_time; + + elapsed_ms = 0; + flb_time_get(&start_time); + + while (count_files_recursive(path) < expected && + elapsed_ms < S3_TEST_WAIT_TIMEOUT_MS) { + flb_time_msleep(S3_TEST_WAIT_STEP_MS); + flb_time_get(&end_time); + flb_time_diff(&end_time, &start_time, &diff_time); + elapsed_ms = flb_time_to_nanosec(&diff_time) / 1000000; + } +} + static int ensure_test_directory(const char *path) { #ifdef FLB_SYSTEM_WINDOWS @@ -119,6 +173,23 @@ static int ensure_test_directory(const char *path) #endif } +static char *create_test_store_directory(const char *postfix) +{ + char *store_dir; + + store_dir = flb_test_tmpdir_cat(postfix); + if (store_dir == NULL) { + return NULL; + } + + if (mkdtemp(store_dir) == NULL) { + flb_free(store_dir); + return NULL; + } + + return store_dir; +} + void flb_test_s3_multipart_success(void) { int ret; @@ -127,9 +198,13 @@ void flb_test_s3_multipart_success(void) int out_ffd; char *call_count_str; int call_count; - char store_dir[] = "/tmp/flb-s3-test-multipart-XXXXXX"; + char *store_dir; - TEST_CHECK(mkdtemp(store_dir) != NULL); + store_dir = create_test_store_directory("/flb-s3-test-multipart-XXXXXX"); + TEST_CHECK(store_dir != NULL); + if (store_dir == NULL) { + return; + } /* mocks calls- signals that we are in test mode */ setenv("FLB_S3_PLUGIN_UNDER_TEST", "true", 1); @@ -145,7 +220,7 @@ void flb_test_s3_multipart_success(void) flb_output_set(ctx, out_ffd,"match", "*", NULL); flb_output_set(ctx, out_ffd,"region", "us-west-2", NULL); flb_output_set(ctx, out_ffd,"bucket", "fluent", NULL); - flb_output_set(ctx, out_ffd,"upload_timeout", "6s", NULL); + flb_output_set(ctx, out_ffd,"upload_timeout", S3_TEST_UPLOAD_TIMEOUT, NULL); flb_output_set(ctx, out_ffd,"store_dir", store_dir, NULL); flb_output_set(ctx, out_ffd,"Retry_Limit", "1", NULL); @@ -154,7 +229,7 @@ void flb_test_s3_multipart_success(void) flb_lib_push(ctx, in_ffd, (char *) JSON_TD , (int) sizeof(JSON_TD) - 1); - sleep(10); + wait_for_s3_call_count("CompleteMultipartUpload", 1); call_count_str = getenv("TEST_CompleteMultipartUpload_CALL_COUNT"); call_count = call_count_str ? atoi(call_count_str) : 0; @@ -168,6 +243,7 @@ void flb_test_s3_multipart_success(void) unsetenv("TEST_UploadPart_CALL_COUNT"); unsetenv("TEST_CompleteMultipartUpload_CALL_COUNT"); unsetenv("TEST_PutObject_CALL_COUNT"); + flb_free(store_dir); } void flb_test_s3_putobject_success(void) @@ -195,7 +271,7 @@ void flb_test_s3_putobject_success(void) flb_output_set(ctx, out_ffd,"bucket", "fluent", NULL); flb_output_set(ctx, out_ffd,"use_put_object", "true", NULL); flb_output_set(ctx, out_ffd,"total_file_size", "5M", NULL); - flb_output_set(ctx, out_ffd,"upload_timeout", "6s", NULL); + flb_output_set(ctx, out_ffd,"upload_timeout", S3_TEST_UPLOAD_TIMEOUT, NULL); flb_output_set(ctx, out_ffd,"Retry_Limit", "1", NULL); ret = flb_start(ctx); @@ -204,7 +280,7 @@ void flb_test_s3_putobject_success(void) flb_lib_push(ctx, in_ffd, (char *) JSON_TD , (int) sizeof(JSON_TD) - 1); - sleep(10); + wait_for_s3_call_count("PutObject", 1); call_count_str = getenv("TEST_PutObject_CALL_COUNT"); call_count = call_count_str ? atoi(call_count_str) : 0; @@ -225,7 +301,13 @@ void flb_test_s3_putobject_error(void) int out_ffd; char *call_count_str; int call_count; - char store_dir[] = "/tmp/flb-s3-test-putobj-XXXXXX"; + char *store_dir; + + store_dir = create_test_store_directory("/flb-s3-test-putobj-XXXXXX"); + TEST_CHECK(store_dir != NULL); + if (store_dir == NULL) { + return; + } /* mocks calls- signals that we are in test mode */ setenv("FLB_S3_PLUGIN_UNDER_TEST", "true", 1); @@ -244,7 +326,7 @@ void flb_test_s3_putobject_error(void) flb_output_set(ctx, out_ffd,"bucket", "fluent", NULL); flb_output_set(ctx, out_ffd,"use_put_object", "true", NULL); flb_output_set(ctx, out_ffd,"total_file_size", "5M", NULL); - flb_output_set(ctx, out_ffd,"upload_timeout", "6s", NULL); + flb_output_set(ctx, out_ffd,"upload_timeout", S3_TEST_UPLOAD_TIMEOUT, NULL); flb_output_set(ctx, out_ffd,"store_dir", store_dir, NULL); flb_output_set(ctx, out_ffd,"Retry_Limit", "1", NULL); @@ -254,7 +336,7 @@ void flb_test_s3_putobject_error(void) flb_lib_push(ctx, in_ffd, (char *) JSON_TD , (int) sizeof(JSON_TD) - 1); - sleep(10); + wait_for_s3_call_count("PutObject", 1); call_count_str = getenv("TEST_PutObject_CALL_COUNT"); call_count = call_count_str ? atoi(call_count_str) : 0; @@ -266,6 +348,7 @@ void flb_test_s3_putobject_error(void) unsetenv("FLB_S3_PLUGIN_UNDER_TEST"); unsetenv("TEST_PUT_OBJECT_ERROR"); unsetenv("TEST_PutObject_CALL_COUNT"); + flb_free(store_dir); } @@ -277,9 +360,13 @@ void flb_test_s3_create_upload_error(void) int out_ffd; char *call_count_str; int call_count; - char store_dir[] = "/tmp/flb-s3-test-XXXXXX"; + char *store_dir; - TEST_CHECK(mkdtemp(store_dir) != NULL); + store_dir = create_test_store_directory("/flb-s3-test-XXXXXX"); + TEST_CHECK(store_dir != NULL); + if (store_dir == NULL) { + return; + } /* mocks calls- signals that we are in test mode */ setenv("FLB_S3_PLUGIN_UNDER_TEST", "true", 1); @@ -296,7 +383,7 @@ void flb_test_s3_create_upload_error(void) flb_output_set(ctx, out_ffd,"match", "*", NULL); flb_output_set(ctx, out_ffd,"region", "us-west-2", NULL); flb_output_set(ctx, out_ffd,"bucket", "fluent", NULL); - flb_output_set(ctx, out_ffd,"upload_timeout", "6s", NULL); + flb_output_set(ctx, out_ffd,"upload_timeout", S3_TEST_UPLOAD_TIMEOUT, NULL); flb_output_set(ctx, out_ffd,"store_dir", store_dir, NULL); flb_output_set(ctx, out_ffd,"Retry_Limit", "1", NULL); @@ -305,7 +392,7 @@ void flb_test_s3_create_upload_error(void) flb_lib_push(ctx, in_ffd, (char *) JSON_TD , (int) sizeof(JSON_TD) - 1); - sleep(10); + wait_for_s3_call_count("CreateMultipartUpload", 1); call_count_str = getenv("TEST_CreateMultipartUpload_CALL_COUNT"); call_count = call_count_str ? atoi(call_count_str) : 0; @@ -325,6 +412,7 @@ void flb_test_s3_create_upload_error(void) unsetenv("TEST_UploadPart_CALL_COUNT"); unsetenv("TEST_CompleteMultipartUpload_CALL_COUNT"); unsetenv("TEST_PutObject_CALL_COUNT"); + flb_free(store_dir); } void flb_test_s3_upload_part_error(void) @@ -335,9 +423,13 @@ void flb_test_s3_upload_part_error(void) int out_ffd; char *call_count_str; int call_count; - char store_dir[] = "/tmp/flb-s3-test-part-err-XXXXXX"; + char *store_dir; - TEST_CHECK(mkdtemp(store_dir) != NULL); + store_dir = create_test_store_directory("/flb-s3-test-part-err-XXXXXX"); + TEST_CHECK(store_dir != NULL); + if (store_dir == NULL) { + return; + } /* mocks calls- signals that we are in test mode */ setenv("FLB_S3_PLUGIN_UNDER_TEST", "true", 1); @@ -354,7 +446,7 @@ void flb_test_s3_upload_part_error(void) flb_output_set(ctx, out_ffd,"match", "*", NULL); flb_output_set(ctx, out_ffd,"region", "us-west-2", NULL); flb_output_set(ctx, out_ffd,"bucket", "fluent", NULL); - flb_output_set(ctx, out_ffd,"upload_timeout", "6s", NULL); + flb_output_set(ctx, out_ffd,"upload_timeout", S3_TEST_UPLOAD_TIMEOUT, NULL); flb_output_set(ctx, out_ffd,"store_dir", store_dir, NULL); flb_output_set(ctx, out_ffd,"Retry_Limit", "1", NULL); @@ -363,7 +455,7 @@ void flb_test_s3_upload_part_error(void) flb_lib_push(ctx, in_ffd, (char *) JSON_TD , (int) sizeof(JSON_TD) - 1); - sleep(10); + wait_for_s3_call_count("UploadPart", 1); call_count_str = getenv("TEST_UploadPart_CALL_COUNT"); call_count = call_count_str ? atoi(call_count_str) : 0; @@ -383,6 +475,7 @@ void flb_test_s3_upload_part_error(void) unsetenv("TEST_UploadPart_CALL_COUNT"); unsetenv("TEST_CompleteMultipartUpload_CALL_COUNT"); unsetenv("TEST_PutObject_CALL_COUNT"); + flb_free(store_dir); } void flb_test_s3_complete_upload_error(void) @@ -393,9 +486,13 @@ void flb_test_s3_complete_upload_error(void) int out_ffd; char *call_count_str; int call_count; - char store_dir[] = "/tmp/flb-s3-test-uplaod-err-XXXXXX"; + char *store_dir; - TEST_CHECK(mkdtemp(store_dir) != NULL); + store_dir = create_test_store_directory("/flb-s3-test-upload-err-XXXXXX"); + TEST_CHECK(store_dir != NULL); + if (store_dir == NULL) { + return; + } /* mocks calls- signals that we are in test mode */ setenv("FLB_S3_PLUGIN_UNDER_TEST", "true", 1); @@ -412,7 +509,7 @@ void flb_test_s3_complete_upload_error(void) flb_output_set(ctx, out_ffd,"match", "*", NULL); flb_output_set(ctx, out_ffd,"region", "us-west-2", NULL); flb_output_set(ctx, out_ffd,"bucket", "fluent", NULL); - flb_output_set(ctx, out_ffd,"upload_timeout", "6s", NULL); + flb_output_set(ctx, out_ffd,"upload_timeout", S3_TEST_UPLOAD_TIMEOUT, NULL); flb_output_set(ctx, out_ffd,"store_dir", store_dir, NULL); flb_output_set(ctx, out_ffd,"Retry_Limit", "1", NULL); @@ -421,7 +518,7 @@ void flb_test_s3_complete_upload_error(void) flb_lib_push(ctx, in_ffd, (char *) JSON_TD , (int) sizeof(JSON_TD) - 1); - sleep(10); + wait_for_s3_call_count("CompleteMultipartUpload", 2); call_count_str = getenv("TEST_CompleteMultipartUpload_CALL_COUNT"); call_count = call_count_str ? atoi(call_count_str) : 0; @@ -437,6 +534,7 @@ void flb_test_s3_complete_upload_error(void) unsetenv("TEST_UploadPart_CALL_COUNT"); unsetenv("TEST_CompleteMultipartUpload_CALL_COUNT"); unsetenv("TEST_PutObject_CALL_COUNT"); + flb_free(store_dir); } void flb_test_s3_compression_gzip(void) @@ -463,7 +561,7 @@ void flb_test_s3_compression_gzip(void) flb_output_set(ctx, out_ffd,"region", "us-west-2", NULL); flb_output_set(ctx, out_ffd,"bucket", "fluent", NULL); flb_output_set(ctx, out_ffd,"compression", "gzip", NULL); - flb_output_set(ctx, out_ffd,"upload_timeout", "6s", NULL); + flb_output_set(ctx, out_ffd,"upload_timeout", S3_TEST_UPLOAD_TIMEOUT, NULL); flb_output_set(ctx, out_ffd,"Retry_Limit", "1", NULL); ret = flb_start(ctx); @@ -471,7 +569,7 @@ void flb_test_s3_compression_gzip(void) flb_lib_push(ctx, in_ffd, (char *) JSON_TD , (int) sizeof(JSON_TD) - 1); - sleep(10); + wait_for_s3_call_count("CompleteMultipartUpload", 1); call_count_str = getenv("TEST_CompleteMultipartUpload_CALL_COUNT"); call_count = call_count_str ? atoi(call_count_str) : 0; @@ -513,7 +611,7 @@ void flb_test_s3_compression_gzip_putobject(void) flb_output_set(ctx, out_ffd,"compression", "gzip", NULL); flb_output_set(ctx, out_ffd,"use_put_object", "true", NULL); flb_output_set(ctx, out_ffd,"total_file_size", "5M", NULL); - flb_output_set(ctx, out_ffd,"upload_timeout", "6s", NULL); + flb_output_set(ctx, out_ffd,"upload_timeout", S3_TEST_UPLOAD_TIMEOUT, NULL); flb_output_set(ctx, out_ffd,"Retry_Limit", "1", NULL); ret = flb_start(ctx); @@ -521,7 +619,7 @@ void flb_test_s3_compression_gzip_putobject(void) flb_lib_push(ctx, in_ffd, (char *) JSON_TD , (int) sizeof(JSON_TD) - 1); - sleep(10); + wait_for_s3_call_count("PutObject", 1); call_count_str = getenv("TEST_PutObject_CALL_COUNT"); call_count = call_count_str ? atoi(call_count_str) : 0; @@ -558,7 +656,7 @@ void flb_test_s3_compression_zstd(void) flb_output_set(ctx, out_ffd,"region", "us-west-2", NULL); flb_output_set(ctx, out_ffd,"bucket", "fluent", NULL); flb_output_set(ctx, out_ffd,"compression", "zstd", NULL); - flb_output_set(ctx, out_ffd,"upload_timeout", "6s", NULL); + flb_output_set(ctx, out_ffd,"upload_timeout", S3_TEST_UPLOAD_TIMEOUT, NULL); flb_output_set(ctx, out_ffd,"Retry_Limit", "1", NULL); ret = flb_start(ctx); @@ -566,7 +664,7 @@ void flb_test_s3_compression_zstd(void) flb_lib_push(ctx, in_ffd, (char *) JSON_TD , (int) sizeof(JSON_TD) - 1); - sleep(10); + wait_for_s3_call_count("CompleteMultipartUpload", 1); call_count_str = getenv("TEST_CompleteMultipartUpload_CALL_COUNT"); call_count = call_count_str ? atoi(call_count_str) : 0; @@ -608,7 +706,7 @@ void flb_test_s3_compression_zstd_putobject(void) flb_output_set(ctx, out_ffd,"compression", "zstd", NULL); flb_output_set(ctx, out_ffd,"use_put_object", "true", NULL); flb_output_set(ctx, out_ffd,"total_file_size", "5M", NULL); - flb_output_set(ctx, out_ffd,"upload_timeout", "6s", NULL); + flb_output_set(ctx, out_ffd,"upload_timeout", S3_TEST_UPLOAD_TIMEOUT, NULL); flb_output_set(ctx, out_ffd,"Retry_Limit", "1", NULL); ret = flb_start(ctx); @@ -616,7 +714,7 @@ void flb_test_s3_compression_zstd_putobject(void) flb_lib_push(ctx, in_ffd, (char *) JSON_TD , (int) sizeof(JSON_TD) - 1); - sleep(10); + wait_for_s3_call_count("PutObject", 1); call_count_str = getenv("TEST_PutObject_CALL_COUNT"); call_count = call_count_str ? atoi(call_count_str) : 0; @@ -653,7 +751,7 @@ void flb_test_s3_compression_snappy(void) flb_output_set(ctx, out_ffd,"region", "us-west-2", NULL); flb_output_set(ctx, out_ffd,"bucket", "fluent", NULL); flb_output_set(ctx, out_ffd,"compression", "snappy", NULL); - flb_output_set(ctx, out_ffd,"upload_timeout", "6s", NULL); + flb_output_set(ctx, out_ffd,"upload_timeout", S3_TEST_UPLOAD_TIMEOUT, NULL); flb_output_set(ctx, out_ffd,"Retry_Limit", "1", NULL); ret = flb_start(ctx); @@ -661,7 +759,7 @@ void flb_test_s3_compression_snappy(void) flb_lib_push(ctx, in_ffd, (char *) JSON_TD , (int) sizeof(JSON_TD) - 1); - sleep(10); + wait_for_s3_call_count("CompleteMultipartUpload", 1); call_count_str = getenv("TEST_CompleteMultipartUpload_CALL_COUNT"); call_count = call_count_str ? atoi(call_count_str) : 0; @@ -703,7 +801,7 @@ void flb_test_s3_compression_snappy_putobject(void) flb_output_set(ctx, out_ffd,"compression", "snappy", NULL); flb_output_set(ctx, out_ffd,"use_put_object", "true", NULL); flb_output_set(ctx, out_ffd,"total_file_size", "5M", NULL); - flb_output_set(ctx, out_ffd,"upload_timeout", "6s", NULL); + flb_output_set(ctx, out_ffd,"upload_timeout", S3_TEST_UPLOAD_TIMEOUT, NULL); flb_output_set(ctx, out_ffd,"Retry_Limit", "1", NULL); ret = flb_start(ctx); @@ -711,7 +809,7 @@ void flb_test_s3_compression_snappy_putobject(void) flb_lib_push(ctx, in_ffd, (char *) JSON_TD , (int) sizeof(JSON_TD) - 1); - sleep(10); + wait_for_s3_call_count("PutObject", 1); call_count_str = getenv("TEST_PutObject_CALL_COUNT"); call_count = call_count_str ? atoi(call_count_str) : 0; @@ -732,9 +830,13 @@ void flb_test_s3_preserve_data_ordering(void) int out_ffd; char *call_count_str; int call_count; - char store_dir[] = "/tmp/flb-s3-test-ordering-XXXXXX"; + char *store_dir; - TEST_CHECK(mkdtemp(store_dir) != NULL); + store_dir = create_test_store_directory("/flb-s3-test-ordering-XXXXXX"); + TEST_CHECK(store_dir != NULL); + if (store_dir == NULL) { + return; + } setenv("FLB_S3_PLUGIN_UNDER_TEST", "true", 1); @@ -752,7 +854,7 @@ void flb_test_s3_preserve_data_ordering(void) flb_output_set(ctx, out_ffd, "use_put_object", "true", NULL); flb_output_set(ctx, out_ffd, "total_file_size", "5M", NULL); flb_output_set(ctx, out_ffd, "preserve_data_ordering", "true", NULL); - flb_output_set(ctx, out_ffd, "upload_timeout", "6s", NULL); + flb_output_set(ctx, out_ffd, "upload_timeout", S3_TEST_UPLOAD_TIMEOUT, NULL); flb_output_set(ctx, out_ffd, "store_dir", store_dir, NULL); flb_output_set(ctx, out_ffd, "Retry_Limit", "1", NULL); @@ -761,7 +863,7 @@ void flb_test_s3_preserve_data_ordering(void) flb_lib_push(ctx, in_ffd, (char *) JSON_TD, (int) sizeof(JSON_TD) - 1); - sleep(10); + wait_for_s3_call_count("PutObject", 1); call_count_str = getenv("TEST_PutObject_CALL_COUNT"); call_count = call_count_str ? atoi(call_count_str) : 0; @@ -772,6 +874,7 @@ void flb_test_s3_preserve_data_ordering(void) flb_destroy(ctx); unsetenv("FLB_S3_PLUGIN_UNDER_TEST"); unsetenv("TEST_PutObject_CALL_COUNT"); + flb_free(store_dir); } @@ -786,9 +889,13 @@ void flb_test_s3_putobject_retry_limit_semantics(void) int out_ffd; char *call_count_str; int call_count; - char store_dir[] = "/tmp/flb-s3-test-retry-XXXXXX"; + char *store_dir; - TEST_CHECK(mkdtemp(store_dir) != NULL); + store_dir = create_test_store_directory("/flb-s3-test-retry-XXXXXX"); + TEST_CHECK(store_dir != NULL); + if (store_dir == NULL) { + return; + } /* Use mocks without flush bypass so the plugin's internal retry runs */ setenv("FLB_S3_PLUGIN_UNDER_TEST", "true", 1); @@ -807,7 +914,7 @@ void flb_test_s3_putobject_retry_limit_semantics(void) flb_output_set(ctx, out_ffd, "bucket", "fluent", NULL); flb_output_set(ctx, out_ffd, "use_put_object", "true", NULL); flb_output_set(ctx, out_ffd, "total_file_size", "5M", NULL); - flb_output_set(ctx, out_ffd, "upload_timeout", "6s", NULL); + flb_output_set(ctx, out_ffd, "upload_timeout", S3_TEST_UPLOAD_TIMEOUT, NULL); flb_output_set(ctx, out_ffd, "store_dir", store_dir, NULL); flb_output_set(ctx, out_ffd, "Retry_Limit", "1", NULL); @@ -817,15 +924,9 @@ void flb_test_s3_putobject_retry_limit_semantics(void) /* Reset counter after startup so we only count test-driven attempts */ unsetenv("TEST_PutObject_CALL_COUNT"); - /* - * Push 1 chunk then wait for upload_timeout (6s) + 2 timer ticks (1s each). - * Chunk must age past upload_timeout before cb_s3_upload will attempt it. - * Tick after ~6s: PutObject attempt 1 fails (failures=1) - * Tick after ~7s: failures(1) not > retry_limit(1), attempt 2 fails (failures=2) - * Next tick: failures(2) > retry_limit(1), chunk discarded - */ + /* Wait until the initial attempt and one retry have run. */ flb_lib_push(ctx, in_ffd, (char *) JSON_TD, (int) sizeof(JSON_TD) - 1); - sleep(10); + wait_for_s3_call_count("PutObject", 2); flb_stop(ctx); flb_destroy(ctx); @@ -841,6 +942,7 @@ void flb_test_s3_putobject_retry_limit_semantics(void) unsetenv("FLB_S3_PLUGIN_UNDER_TEST"); unsetenv("TEST_PUT_OBJECT_ERROR"); unsetenv("TEST_PutObject_CALL_COUNT"); + flb_free(store_dir); } /* @@ -854,9 +956,13 @@ void flb_test_s3_default_retry_limit(void) int out_ffd; char *call_count_str; int call_count; - char store_dir[] = "/tmp/flb-s3-test-default-XXXXXX"; + char *store_dir; - TEST_CHECK(mkdtemp(store_dir) != NULL); + store_dir = create_test_store_directory("/flb-s3-test-default-XXXXXX"); + TEST_CHECK(store_dir != NULL); + if (store_dir == NULL) { + return; + } setenv("FLB_S3_PLUGIN_UNDER_TEST", "true", 1); setenv("TEST_PUT_OBJECT_ERROR", ERROR_ACCESS_DENIED, 1); @@ -874,7 +980,7 @@ void flb_test_s3_default_retry_limit(void) flb_output_set(ctx, out_ffd, "bucket", "fluent", NULL); flb_output_set(ctx, out_ffd, "use_put_object", "true", NULL); flb_output_set(ctx, out_ffd, "total_file_size", "5M", NULL); - flb_output_set(ctx, out_ffd, "upload_timeout", "6s", NULL); + flb_output_set(ctx, out_ffd, "upload_timeout", S3_TEST_UPLOAD_TIMEOUT, NULL); flb_output_set(ctx, out_ffd, "store_dir", store_dir, NULL); /* No Retry_Limit — should default to 5 (MAX_UPLOAD_ERRORS) */ @@ -883,12 +989,9 @@ void flb_test_s3_default_retry_limit(void) unsetenv("TEST_PutObject_CALL_COUNT"); - /* - * Push 1 chunk, wait for upload_timeout (6s) + 6 timer ticks (1s each). - * Default retry_limit=5: 1 initial attempt + 5 retries = 6 PutObject calls. - */ + /* Wait for the initial attempt and all five default retries. */ flb_lib_push(ctx, in_ffd, (char *) JSON_TD, (int) sizeof(JSON_TD) - 1); - sleep(14); + wait_for_s3_call_count("PutObject", 6); flb_stop(ctx); flb_destroy(ctx); @@ -903,6 +1006,7 @@ void flb_test_s3_default_retry_limit(void) unsetenv("FLB_S3_PLUGIN_UNDER_TEST"); unsetenv("TEST_PUT_OBJECT_ERROR"); unsetenv("TEST_PutObject_CALL_COUNT"); + flb_free(store_dir); } void flb_test_s3_default_retry_exhausted_action_quarantine(void) @@ -913,6 +1017,7 @@ void flb_test_s3_default_retry_exhausted_action_quarantine(void) int out_ffd; int file_count; char postfix[128]; + char quarantine_dir[2048]; char *store_dir; snprintf(postfix, sizeof(postfix), @@ -920,6 +1025,8 @@ void flb_test_s3_default_retry_exhausted_action_quarantine(void) store_dir = flb_test_tmpdir_cat(postfix); TEST_CHECK(store_dir != NULL); TEST_CHECK(ensure_test_directory(store_dir) == 0); + snprintf(quarantine_dir, sizeof(quarantine_dir), + "%s/fluent/quarantine", store_dir); setenv("FLB_S3_PLUGIN_UNDER_TEST", "true", 1); setenv("TEST_PUT_OBJECT_ERROR", ERROR_ACCESS_DENIED, 1); @@ -937,7 +1044,7 @@ void flb_test_s3_default_retry_exhausted_action_quarantine(void) flb_output_set(ctx, out_ffd, "bucket", "fluent", NULL); flb_output_set(ctx, out_ffd, "use_put_object", "true", NULL); flb_output_set(ctx, out_ffd, "total_file_size", "5M", NULL); - flb_output_set(ctx, out_ffd, "upload_timeout", "6s", NULL); + flb_output_set(ctx, out_ffd, "upload_timeout", S3_TEST_UPLOAD_TIMEOUT, NULL); flb_output_set(ctx, out_ffd, "store_dir", store_dir, NULL); flb_output_set(ctx, out_ffd, "Retry_Limit", "1", NULL); /* do not set retry_exhausted_action to validate default behavior */ @@ -947,14 +1054,15 @@ void flb_test_s3_default_retry_exhausted_action_quarantine(void) unsetenv("TEST_PutObject_CALL_COUNT"); flb_lib_push(ctx, in_ffd, (char *) JSON_TD, (int) sizeof(JSON_TD) - 1); - sleep(10); + wait_for_s3_call_count("PutObject", 2); + wait_for_file_count(quarantine_dir, 1); - file_count = count_files_recursive(store_dir); + file_count = count_files_recursive(quarantine_dir); flb_stop(ctx); flb_destroy(ctx); TEST_CHECK_(file_count > 0, - "Expected quarantined file(s) in store_dir, got %d", + "Expected quarantined file(s), got %d", file_count); unsetenv("FLB_S3_PLUGIN_UNDER_TEST"); diff --git a/tests/runtime/out_s3_otlp_json.c b/tests/runtime/out_s3_otlp_json.c index 5869037fa2e..2ed480b428a 100644 --- a/tests/runtime/out_s3_otlp_json.c +++ b/tests/runtime/out_s3_otlp_json.c @@ -1,11 +1,29 @@ /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ #include #include "flb_tests_runtime.h" +#include "../include/flb_tests_tmpdir.h" #include "../../plugins/in_opentelemetry/opentelemetry.h" #include "../../plugins/in_opentelemetry/opentelemetry_logs.h" #define OTLP_LOGS_JSON "{\"resourceLogs\":[{\"resource\":{\"attributes\":[{\"key\":\"service.name\",\"value\":{\"stringValue\":\"my.service\"}}]},\"scopeLogs\":[{\"scope\":{\"name\":\"my.library\",\"version\":\"1.0.0\"},\"logRecords\":[{\"timeUnixNano\":\"1774877764000000000\",\"observedTimeUnixNano\":\"1774877764000000000\",\"severityNumber\":2,\"severityText\":\"INFO\",\"body\":{\"stringValue\":\"otlp runtime test\"}}]}]}]}" +static char *create_test_store_directory(const char *postfix) +{ + char *store_dir; + + store_dir = flb_test_tmpdir_cat(postfix); + if (store_dir == NULL) { + return NULL; + } + + if (mkdtemp(store_dir) == NULL) { + flb_free(store_dir); + return NULL; + } + + return store_dir; +} + static struct flb_input_instance *get_opentelemetry_instance(flb_ctx_t *flb_ctx) { struct mk_list *head; @@ -55,7 +73,13 @@ void flb_test_s3_format_otlp_json(void) int out_ffd; char *call_count_str; int call_count; - char store_dir[] = "/tmp/flb-s3-test-otlp-json-XXXXXX"; + char *store_dir; + + store_dir = create_test_store_directory("/flb-s3-test-otlp-json-XXXXXX"); + TEST_CHECK(store_dir != NULL); + if (store_dir == NULL) { + return; + } setenv("FLB_S3_PLUGIN_UNDER_TEST", "true", 1); @@ -95,6 +119,7 @@ void flb_test_s3_format_otlp_json(void) flb_destroy(ctx); unsetenv("FLB_S3_PLUGIN_UNDER_TEST"); unsetenv("TEST_PutObject_CALL_COUNT"); + flb_free(store_dir); } void flb_test_s3_format_otlp_json_with_compression(void) @@ -105,7 +130,13 @@ void flb_test_s3_format_otlp_json_with_compression(void) int out_ffd; char *call_count_str; int call_count; - char store_dir[] = "/tmp/flb-s3-test-otlp-comp-XXXXXX"; + char *store_dir; + + store_dir = create_test_store_directory("/flb-s3-test-otlp-comp-XXXXXX"); + TEST_CHECK(store_dir != NULL); + if (store_dir == NULL) { + return; + } setenv("FLB_S3_PLUGIN_UNDER_TEST", "true", 1); @@ -147,6 +178,7 @@ void flb_test_s3_format_otlp_json_with_compression(void) flb_destroy(ctx); unsetenv("FLB_S3_PLUGIN_UNDER_TEST"); unsetenv("TEST_PutObject_CALL_COUNT"); + flb_free(store_dir); } TEST_LIST = { diff --git a/tests/runtime/out_stackdriver.c b/tests/runtime/out_stackdriver.c index 065329da1b0..7ea57cfd5fd 100644 --- a/tests/runtime/out_stackdriver.c +++ b/tests/runtime/out_stackdriver.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include "flb_tests_runtime.h" @@ -46,6 +48,81 @@ #include "data/stackdriver/stackdriver_test_monitored_resource.h" #include "data/stackdriver/stackdriver_test_payload.h" +#define STACKDRIVER_TEST_WAIT_STEP_MS 10 +#define STACKDRIVER_TEST_TIMEOUT_MS 2000 + +typedef void (*stackdriver_test_callback)(void *, int, int, void *, size_t, void *); + +static pthread_mutex_t stackdriver_test_mutex = PTHREAD_MUTEX_INITIALIZER; +static stackdriver_test_callback stackdriver_formatter_callback; +static void *stackdriver_formatter_callback_data; +static int stackdriver_formatter_complete; + +static void cb_stackdriver_formatter(void *ctx, int ffd, int res_ret, + void *res_data, size_t res_size, void *data) +{ + stackdriver_test_callback callback; + void *callback_data; + + (void) data; + + pthread_mutex_lock(&stackdriver_test_mutex); + callback = stackdriver_formatter_callback; + callback_data = stackdriver_formatter_callback_data; + pthread_mutex_unlock(&stackdriver_test_mutex); + + callback(ctx, ffd, res_ret, res_data, res_size, callback_data); + + pthread_mutex_lock(&stackdriver_test_mutex); + stackdriver_formatter_complete = FLB_TRUE; + pthread_mutex_unlock(&stackdriver_test_mutex); +} + +static int stackdriver_output_set_test(flb_ctx_t *ctx, int ffd, char *test_name, + stackdriver_test_callback callback, + void *callback_data, void *test_ctx) +{ + pthread_mutex_lock(&stackdriver_test_mutex); + stackdriver_formatter_callback = callback; + stackdriver_formatter_callback_data = callback_data; + stackdriver_formatter_complete = FLB_FALSE; + pthread_mutex_unlock(&stackdriver_test_mutex); + + return flb_output_set_test(ctx, ffd, test_name, + cb_stackdriver_formatter, NULL, test_ctx); +} + +static void stackdriver_wait_for_formatter(void) +{ + int complete; + uint64_t elapsed_ms; + struct flb_time start_time; + struct flb_time end_time; + struct flb_time diff_time; + + complete = FLB_FALSE; + elapsed_ms = 0; + flb_time_get(&start_time); + + /* Preserve the bounded fallback for cases that do not invoke the callback. */ + while (elapsed_ms < STACKDRIVER_TEST_TIMEOUT_MS) { + pthread_mutex_lock(&stackdriver_test_mutex); + complete = stackdriver_formatter_complete; + pthread_mutex_unlock(&stackdriver_test_mutex); + + if (complete == FLB_TRUE) { + break; + } + + flb_time_msleep(STACKDRIVER_TEST_WAIT_STEP_MS); + flb_time_get(&end_time); + flb_time_diff(&end_time, &start_time, &diff_time); + elapsed_ms = flb_time_to_nanosec(&diff_time) / 1000000; + } +} + +#define flb_output_set_test stackdriver_output_set_test + /* * Fluent Bit Stackdriver plugin, always set as payload a JSON strings contained in a * 'sds'. Since we want to validate specific keys and it values we expose here some @@ -2405,9 +2482,9 @@ void flb_test_monitored_resource_common() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -2433,7 +2510,7 @@ void flb_test_monitored_resource_common() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) MONITORED_RESOURCE_COMMON_CASE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -2446,9 +2523,9 @@ void flb_test_monitored_resource_priority_higher_than_local_resource_id() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -2476,7 +2553,7 @@ void flb_test_monitored_resource_priority_higher_than_local_resource_id() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) MONITORED_RESOURCE_PRIORITY_HIGHER_THAN_LOCAL_RESOURCE_ID, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -2489,9 +2566,9 @@ void flb_test_monitored_resource_priority_higher_than_gce_instance() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -2517,7 +2594,7 @@ void flb_test_monitored_resource_priority_higher_than_gce_instance() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) MONITORED_RESOURCE_PRIORITY_HIGHER_THAN_GCE_INSTANCE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -2530,9 +2607,9 @@ void flb_test_resource_global() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -2558,7 +2635,7 @@ void flb_test_resource_global() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) JSON, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -2571,9 +2648,9 @@ void flb_test_trace_no_autoformat() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -2599,7 +2676,7 @@ void flb_test_trace_no_autoformat() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) TRACE_COMMON_CASE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -2612,9 +2689,9 @@ void flb_test_trace_stackdriver_autoformat() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -2641,7 +2718,7 @@ void flb_test_trace_stackdriver_autoformat() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) TRACE_COMMON_CASE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -2654,9 +2731,9 @@ void flb_test_span_id() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -2681,7 +2758,7 @@ void flb_test_span_id() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) SPAN_ID_COMMON_CASE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -2694,9 +2771,9 @@ void flb_test_trace_sampled_true() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -2721,7 +2798,7 @@ void flb_test_trace_sampled_true() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) TRACE_SAMPLED_CASE_TRUE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -2734,9 +2811,9 @@ void flb_test_trace_sampled_false() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -2761,7 +2838,7 @@ void flb_test_trace_sampled_false() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) TRACE_SAMPLED_CASE_FALSE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -2774,9 +2851,9 @@ void flb_test_set_metadata_server() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -2802,7 +2879,7 @@ void flb_test_set_metadata_server() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) JSON, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -2815,9 +2892,9 @@ void flb_test_project_id_override() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -2843,7 +2920,7 @@ void flb_test_project_id_override() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) LOG_NAME_PROJECT_ID_OVERRIDE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -2856,9 +2933,9 @@ void flb_test_project_id_no_override() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -2883,7 +2960,7 @@ void flb_test_project_id_no_override() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) LOG_NAME_PROJECT_ID_NO_OVERRIDE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -2896,9 +2973,9 @@ void flb_test_log_name_override() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -2924,7 +3001,7 @@ void flb_test_log_name_override() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) LOG_NAME_OVERRIDE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -2937,9 +3014,9 @@ void flb_test_log_name_no_override() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -2965,7 +3042,7 @@ void flb_test_log_name_no_override() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) LOG_NAME_NO_OVERRIDE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -2979,9 +3056,9 @@ void flb_test_resource_global_custom_prefix() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -3008,7 +3085,7 @@ void flb_test_resource_global_custom_prefix() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) JSON, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -3021,9 +3098,9 @@ void flb_test_resource_generic_node_creds() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -3052,7 +3129,7 @@ void flb_test_resource_generic_node_creds() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) JSON, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -3065,9 +3142,9 @@ void flb_test_resource_generic_node_metadata() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -3095,7 +3172,7 @@ void flb_test_resource_generic_node_metadata() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) JSON, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -3108,9 +3185,9 @@ void flb_test_resource_generic_task_creds() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -3140,7 +3217,7 @@ void flb_test_resource_generic_task_creds() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) JSON, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -3153,9 +3230,9 @@ void flb_test_resource_generic_task_metadata() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -3184,7 +3261,7 @@ void flb_test_resource_generic_task_metadata() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) JSON, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -3197,9 +3274,9 @@ void flb_test_resource_gce_instance() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -3224,7 +3301,7 @@ void flb_test_resource_gce_instance() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) JSON, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -3237,9 +3314,9 @@ void flb_test_insert_id_common_case() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -3264,7 +3341,7 @@ void flb_test_insert_id_common_case() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) INSERTID_COMMON_CASE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -3277,9 +3354,9 @@ void flb_test_empty_insert_id() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -3304,7 +3381,7 @@ void flb_test_empty_insert_id() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) EMPTY_INSERTID, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -3317,9 +3394,9 @@ void flb_test_insert_id_incorrect_type() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -3344,7 +3421,7 @@ void flb_test_insert_id_incorrect_type() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) INSERTID_INCORRECT_TYPE_INT, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -3357,9 +3434,9 @@ void flb_test_operation_common() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -3384,7 +3461,7 @@ void flb_test_operation_common() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) OPERATION_COMMON_CASE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -3397,9 +3474,9 @@ void flb_test_empty_operation() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -3424,7 +3501,7 @@ void flb_test_empty_operation() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) EMPTY_OPERATION, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -3437,9 +3514,9 @@ void flb_test_operation_in_string() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -3464,7 +3541,7 @@ void flb_test_operation_in_string() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) OPERATION_IN_STRING, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -3477,9 +3554,9 @@ void flb_test_operation_partial_subfields() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -3504,7 +3581,7 @@ void flb_test_operation_partial_subfields() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) PARTIAL_SUBFIELDS, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -3517,9 +3594,9 @@ void flb_test_operation_incorrect_type_subfields() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -3544,7 +3621,7 @@ void flb_test_operation_incorrect_type_subfields() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) SUBFIELDS_IN_INCORRECT_TYPE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -3557,9 +3634,9 @@ void flb_test_operation_extra_subfields() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -3584,7 +3661,7 @@ void flb_test_operation_extra_subfields() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) EXTRA_SUBFIELDS_EXISTED, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -3597,9 +3674,9 @@ void flb_test_resource_k8s_container_common() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -3627,7 +3704,7 @@ void flb_test_resource_k8s_container_common() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) K8S_CONTAINER_COMMON, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -3644,9 +3721,9 @@ void flb_test_resource_k8s_container_multi_tag_value() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -3672,7 +3749,9 @@ void flb_test_resource_k8s_container_multi_tag_value() TEST_CHECK(ret == 0); /* Ingest data sample */ - flb_lib_push(ctx, in_ffd, (char *) K8S_CONTAINER_COMMON_DIFF_TAGS, size_one); + flb_lib_push(ctx, in_ffd, (char *) K8S_CONTAINER_COMMON, size_one); + + stackdriver_wait_for_formatter(); /* Enable test mode */ ret = flb_output_set_test(ctx, out_ffd, "formatter", @@ -3683,7 +3762,7 @@ void flb_test_resource_k8s_container_multi_tag_value() flb_lib_push(ctx, in_ffd, (char *) K8S_CONTAINER_COMMON_DIFF_TAGS, size_two); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -3700,7 +3779,7 @@ void flb_test_resource_k8s_container_concurrency() char tag[32]; ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); for (k = 0; k < 5; k++) { in_ffd[k] = flb_input(ctx, (char *) "lib", NULL); @@ -3746,9 +3825,9 @@ void flb_test_resource_k8s_container_custom_tag_prefix() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -3777,7 +3856,7 @@ void flb_test_resource_k8s_container_custom_tag_prefix() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) K8S_CONTAINER_NO_LOCAL_RESOURCE_ID, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -3790,9 +3869,9 @@ void flb_test_resource_k8s_container_custom_tag_prefix_with_dot() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -3821,7 +3900,7 @@ void flb_test_resource_k8s_container_custom_tag_prefix_with_dot() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) K8S_CONTAINER_NO_LOCAL_RESOURCE_ID, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -3834,9 +3913,9 @@ void flb_test_resource_k8s_container_default_tag_regex() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -3866,7 +3945,7 @@ void flb_test_resource_k8s_container_default_tag_regex() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) K8S_CONTAINER_NO_LOCAL_RESOURCE_ID, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -3879,9 +3958,9 @@ void flb_test_resource_k8s_container_custom_k8s_regex() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -3911,7 +3990,7 @@ void flb_test_resource_k8s_container_custom_k8s_regex() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) K8S_CONTAINER_NO_LOCAL_RESOURCE_ID, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -3924,9 +4003,9 @@ void flb_test_resource_k8s_container_custom_k8s_regex_custom_prefix() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -3957,7 +4036,7 @@ void flb_test_resource_k8s_container_custom_k8s_regex_custom_prefix() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) K8S_CONTAINER_NO_LOCAL_RESOURCE_ID, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -3970,9 +4049,9 @@ void flb_test_resource_k8s_cluster_no_local_resource_id() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4000,7 +4079,7 @@ void flb_test_resource_k8s_cluster_no_local_resource_id() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) K8S_CLUSTER_NO_LOCAL_RESOURCE_ID, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4014,9 +4093,9 @@ void flb_test_resource_k8s_node_common() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4044,7 +4123,7 @@ void flb_test_resource_k8s_node_common() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) K8S_NODE_COMMON, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4057,9 +4136,9 @@ void flb_test_resource_k8s_pod_common() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4087,7 +4166,7 @@ void flb_test_resource_k8s_pod_common() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) K8S_POD_COMMON, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4100,9 +4179,9 @@ void flb_test_default_labels() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4128,7 +4207,7 @@ void flb_test_default_labels() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) DEFAULT_LABELS, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4141,9 +4220,9 @@ void flb_test_custom_labels() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4170,7 +4249,7 @@ void flb_test_custom_labels() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) CUSTOM_LABELS, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4183,9 +4262,9 @@ void flb_test_config_labels_conflict() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4212,7 +4291,7 @@ void flb_test_config_labels_conflict() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) DEFAULT_LABELS, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4225,9 +4304,9 @@ void flb_test_config_labels_no_conflict() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4254,7 +4333,7 @@ void flb_test_config_labels_no_conflict() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) DEFAULT_LABELS, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4267,9 +4346,9 @@ void flb_test_default_labels_k8s_resource_type() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4297,7 +4376,7 @@ void flb_test_default_labels_k8s_resource_type() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) DEFAULT_LABELS_K8S_RESOURCE_TYPE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4310,9 +4389,9 @@ void flb_test_resource_labels_one_field() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4338,7 +4417,7 @@ void flb_test_resource_labels_one_field() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) ONE_FIELD, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4351,9 +4430,9 @@ void flb_test_resource_labels_plaintext() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4379,7 +4458,7 @@ void flb_test_resource_labels_plaintext() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) ONE_FIELD, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4392,9 +4471,9 @@ void flb_test_resource_labels_multiple_fields() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4420,7 +4499,7 @@ void flb_test_resource_labels_multiple_fields() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) MULTIPLE_FIELDS, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4433,9 +4512,9 @@ void flb_test_resource_labels_nested_fields() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4461,7 +4540,7 @@ void flb_test_resource_labels_nested_fields() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) NESTED_FIELDS, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4474,9 +4553,9 @@ void flb_test_resource_labels_layered_nested_fields() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4503,7 +4582,7 @@ void flb_test_resource_labels_layered_nested_fields() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) LAYERED_NESTED_FIELDS, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4516,9 +4595,9 @@ void flb_test_resource_labels_original_does_not_exist() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4544,7 +4623,7 @@ void flb_test_resource_labels_original_does_not_exist() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) ONE_FIELD, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4557,9 +4636,9 @@ void flb_test_resource_labels_nested_original_does_not_exist() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4585,7 +4664,7 @@ void flb_test_resource_labels_nested_original_does_not_exist() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) ONE_FIELD, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4598,9 +4677,9 @@ void flb_test_resource_labels_nested_original_partially_exists() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4626,7 +4705,7 @@ void flb_test_resource_labels_nested_original_partially_exists() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) NESTED_FIELDS, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4639,9 +4718,9 @@ void flb_test_resource_labels_one_field_with_spaces() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4667,7 +4746,7 @@ void flb_test_resource_labels_one_field_with_spaces() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) ONE_FIELD, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4680,9 +4759,9 @@ void flb_test_resource_labels_multiple_fields_with_spaces() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4708,7 +4787,7 @@ void flb_test_resource_labels_multiple_fields_with_spaces() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) MULTIPLE_FIELDS, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4721,9 +4800,9 @@ void flb_test_resource_labels_empty_input() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4749,7 +4828,7 @@ void flb_test_resource_labels_empty_input() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) ONE_FIELD, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4762,9 +4841,9 @@ void flb_test_resource_labels_duplicate_assignment() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4790,7 +4869,7 @@ void flb_test_resource_labels_duplicate_assignment() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) MULTIPLE_FIELDS, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4803,9 +4882,9 @@ void flb_test_resource_labels_project_id_not_overridden() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4831,7 +4910,7 @@ void flb_test_resource_labels_project_id_not_overridden() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) ONE_FIELD, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4844,9 +4923,9 @@ void flb_test_resource_labels_has_priority() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4876,7 +4955,7 @@ void flb_test_resource_labels_has_priority() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) ONE_FIELD, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4889,9 +4968,9 @@ void flb_test_resource_labels_fallsback_when_required_not_specified() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4920,7 +4999,7 @@ void flb_test_resource_labels_fallsback_when_required_not_specified() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) K8S_CONTAINER_COMMON, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4933,9 +5012,9 @@ void flb_test_resource_labels_fallsback_when_required_partially_specified() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -4964,7 +5043,7 @@ void flb_test_resource_labels_fallsback_when_required_partially_specified() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) K8S_CONTAINER_COMMON, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -4977,9 +5056,9 @@ void flb_test_resource_labels_k8s_container() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -5007,7 +5086,7 @@ void flb_test_resource_labels_k8s_container() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) ONE_FIELD, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5020,9 +5099,9 @@ void flb_test_resource_labels_k8s_node() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -5050,7 +5129,7 @@ void flb_test_resource_labels_k8s_node() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) ONE_FIELD, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5063,9 +5142,9 @@ void flb_test_resource_labels_k8s_pod() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -5093,7 +5172,7 @@ void flb_test_resource_labels_k8s_pod() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) ONE_FIELD, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5106,9 +5185,9 @@ void flb_test_resource_labels_generic_node() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -5136,7 +5215,7 @@ void flb_test_resource_labels_generic_node() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) ONE_FIELD, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5149,9 +5228,9 @@ void flb_test_resource_labels_generic_task() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -5179,7 +5258,7 @@ void flb_test_resource_labels_generic_task() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) ONE_FIELD, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5192,9 +5271,9 @@ void flb_test_custom_labels_k8s_resource_type() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -5223,7 +5302,7 @@ void flb_test_custom_labels_k8s_resource_type() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) CUSTOM_LABELS_K8S_RESOURCE_TYPE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5236,9 +5315,9 @@ void flb_test_resource_k8s_container_no_local_resource_id() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -5267,7 +5346,7 @@ void flb_test_resource_k8s_container_no_local_resource_id() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) K8S_CONTAINER_NO_LOCAL_RESOURCE_ID, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5280,9 +5359,9 @@ void flb_test_resource_k8s_node_no_local_resource_id() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -5310,7 +5389,7 @@ void flb_test_resource_k8s_node_no_local_resource_id() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) K8S_NODE_NO_LOCAL_RESOURCE_ID, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5323,9 +5402,9 @@ void flb_test_resource_k8s_node_custom_k8s_regex_with_dot() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -5354,7 +5433,7 @@ void flb_test_resource_k8s_node_custom_k8s_regex_with_dot() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) K8S_NODE_LOCAL_RESOURCE_ID_WITH_DOT, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5367,9 +5446,9 @@ void flb_test_resource_k8s_node_custom_k8s_regex_with_long_tag() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -5398,7 +5477,7 @@ void flb_test_resource_k8s_node_custom_k8s_regex_with_long_tag() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) K8S_NODE_LOCAL_RESOURCE_ID_WITH_DOT, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5411,9 +5490,9 @@ void flb_test_resource_k8s_pod_no_local_resource_id() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -5441,7 +5520,7 @@ void flb_test_resource_k8s_pod_no_local_resource_id() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) K8S_POD_NO_LOCAL_RESOURCE_ID, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5453,9 +5532,9 @@ void flb_test_multi_entries_severity() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - ret = flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + ret = flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); TEST_CHECK_(ret == 0, "setting service options"); /* Tail input mode */ @@ -5486,7 +5565,7 @@ void flb_test_multi_entries_severity() ret = flb_start(ctx); TEST_CHECK(ret == 0); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5499,9 +5578,9 @@ void flb_test_source_location_common_case() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -5526,7 +5605,7 @@ void flb_test_source_location_common_case() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) SOURCELOCATION_COMMON_CASE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5539,9 +5618,9 @@ void flb_test_source_location_line_in_string() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -5566,7 +5645,7 @@ void flb_test_source_location_line_in_string() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) SOURCELOCATION_COMMON_CASE_LINE_IN_STRING, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5579,9 +5658,9 @@ void flb_test_source_location_line_invalid_string() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -5606,7 +5685,7 @@ void flb_test_source_location_line_invalid_string() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) SOURCELOCATION_COMMON_CASE_LINE_INVALID_STRING, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5619,9 +5698,9 @@ void flb_test_empty_source_location() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -5646,7 +5725,7 @@ void flb_test_empty_source_location() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) EMPTY_SOURCELOCATION, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5659,9 +5738,9 @@ void flb_test_source_location_in_string() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -5686,7 +5765,7 @@ void flb_test_source_location_in_string() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) SOURCELOCATION_IN_STRING, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5699,9 +5778,9 @@ void flb_test_source_location_partial_subfields() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -5726,7 +5805,7 @@ void flb_test_source_location_partial_subfields() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) PARTIAL_SOURCELOCATION, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5739,9 +5818,9 @@ void flb_test_source_location_incorrect_type_subfields() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -5766,7 +5845,7 @@ void flb_test_source_location_incorrect_type_subfields() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) SOURCELOCATION_SUBFIELDS_IN_INCORRECT_TYPE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5779,9 +5858,9 @@ void flb_test_source_location_extra_subfields() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -5806,7 +5885,7 @@ void flb_test_source_location_extra_subfields() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) SOURCELOCATION_EXTRA_SUBFIELDS_EXISTED, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5819,9 +5898,9 @@ void flb_test_http_request_common_case() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -5846,7 +5925,7 @@ void flb_test_http_request_common_case() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) HTTPREQUEST_COMMON_CASE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5859,9 +5938,9 @@ void flb_test_empty_http_request() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -5886,7 +5965,7 @@ void flb_test_empty_http_request() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) EMPTY_HTTPREQUEST, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5899,9 +5978,9 @@ void flb_test_http_request_in_string() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -5926,7 +6005,7 @@ void flb_test_http_request_in_string() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) HTTPREQUEST_IN_STRING, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5939,9 +6018,9 @@ void flb_test_http_request_partial_subfields() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -5966,7 +6045,7 @@ void flb_test_http_request_partial_subfields() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) PARTIAL_HTTPREQUEST, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -5979,9 +6058,9 @@ void flb_test_http_request_incorrect_type_subfields() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -6006,7 +6085,7 @@ void flb_test_http_request_incorrect_type_subfields() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) HTTPREQUEST_SUBFIELDS_IN_INCORRECT_TYPE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -6019,9 +6098,9 @@ void flb_test_http_request_extra_subfields() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -6046,7 +6125,7 @@ void flb_test_http_request_extra_subfields() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) HTTPREQUEST_EXTRA_SUBFIELDS_EXISTED, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -6059,9 +6138,9 @@ void flb_test_http_request_latency_common_case() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -6086,7 +6165,7 @@ void flb_test_http_request_latency_common_case() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) HTTPREQUEST_LATENCY_COMMON_CASE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -6099,9 +6178,9 @@ void flb_test_http_request_latency_invalid_spaces() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -6126,7 +6205,7 @@ void flb_test_http_request_latency_invalid_spaces() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) HTTPREQUEST_LATENCY_INVALID_SPACES, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -6139,9 +6218,9 @@ void flb_test_http_request_latency_invalid_string() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -6166,7 +6245,7 @@ void flb_test_http_request_latency_invalid_string() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) HTTPREQUEST_LATENCY_INVALID_STRING, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -6179,9 +6258,9 @@ void flb_test_http_request_latency_invalid_end() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -6206,7 +6285,7 @@ void flb_test_http_request_latency_invalid_end() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) HTTPREQUEST_LATENCY_INVALID_END, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -6219,9 +6298,9 @@ void flb_test_timestamp_format_object_common() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -6246,7 +6325,7 @@ void flb_test_timestamp_format_object_common() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) TIMESTAMP_FORMAT_OBJECT_COMMON_CASE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -6259,9 +6338,9 @@ void flb_test_timestamp_format_object_not_a_map() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -6286,7 +6365,7 @@ void flb_test_timestamp_format_object_not_a_map() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) TIMESTAMP_FORMAT_OBJECT_NOT_A_MAP, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -6299,9 +6378,9 @@ void flb_test_timestamp_format_object_missing_subfield() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -6326,7 +6405,7 @@ void flb_test_timestamp_format_object_missing_subfield() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) TIMESTAMP_FORMAT_OBJECT_MISSING_SUBFIELD, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -6339,9 +6418,9 @@ void flb_test_timestamp_format_object_incorrect_subfields() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -6366,7 +6445,7 @@ void flb_test_timestamp_format_object_incorrect_subfields() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) TIMESTAMP_FORMAT_OBJECT_INCORRECT_TYPE_SUBFIELDS, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -6379,9 +6458,9 @@ void flb_test_timestamp_format_duo_fields_common_case() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -6406,7 +6485,7 @@ void flb_test_timestamp_format_duo_fields_common_case() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) TIMESTAMP_FORMAT_DUO_FIELDS_COMMON_CASE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -6419,9 +6498,9 @@ void flb_test_timestamp_format_duo_fields_missing_nanos() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -6446,7 +6525,7 @@ void flb_test_timestamp_format_duo_fields_missing_nanos() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) TIMESTAMP_FORMAT_DUO_FIELDS_MISSING_NANOS, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -6459,9 +6538,9 @@ void flb_test_timestamp_format_duo_fields_incorrect_type() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -6486,7 +6565,7 @@ void flb_test_timestamp_format_duo_fields_incorrect_type() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) TIMESTAMP_FORMAT_DUO_FIELDS_INCORRECT_TYPE, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -6499,9 +6578,9 @@ void flb_test_string_text_payload_with_matched_text_payload_key() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -6527,7 +6606,7 @@ void flb_test_string_text_payload_with_matched_text_payload_key() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) STRING_TEXT_PAYLOAD, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -6540,9 +6619,9 @@ void flb_test_string_text_payload_with_mismatched_text_payload_key() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -6568,7 +6647,7 @@ void flb_test_string_text_payload_with_mismatched_text_payload_key() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) STRING_TEXT_PAYLOAD, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -6581,9 +6660,9 @@ void flb_test_string_text_payload_with_residual_fields() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -6609,7 +6688,7 @@ void flb_test_string_text_payload_with_residual_fields() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) STRING_TEXT_PAYLOAD_WITH_RESIDUAL_FIELDS, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } @@ -6622,9 +6701,9 @@ void flb_test_non_scalar_payload_with_residual_fields() int in_ffd; int out_ffd; - /* Create context, flush every second (some checks omitted here) */ + /* Create context, flush every 200 milliseconds (some checks omitted here) */ ctx = flb_create(); - flb_service_set(ctx, "flush", "1", "grace", "1", NULL); + flb_service_set(ctx, "flush", "0.2", "grace", "1", NULL); /* Lib input mode */ in_ffd = flb_input(ctx, (char *) "lib", NULL); @@ -6650,7 +6729,7 @@ void flb_test_non_scalar_payload_with_residual_fields() /* Ingest data sample */ flb_lib_push(ctx, in_ffd, (char *) NON_SCALAR_PAYLOAD_WITH_RESIDUAL_FIELDS, size); - sleep(2); + stackdriver_wait_for_formatter(); flb_stop(ctx); flb_destroy(ctx); } diff --git a/tests/runtime/out_syslog.c b/tests/runtime/out_syslog.c index 6bea4ec7b62..bcefaffbfeb 100644 --- a/tests/runtime/out_syslog.c +++ b/tests/runtime/out_syslog.c @@ -1631,7 +1631,9 @@ void flb_test_udp_mode_rejects_tls() TEST_MSG("expected startup failure for mode=udp with tls=on"); } - test_ctx_destroy(ctx); + /* flb_start failed, so there is no running engine to stop. */ + flb_destroy(ctx->flb); + flb_free(ctx); } TEST_LIST = { diff --git a/tests/runtime/processor_cumulative_to_delta.c b/tests/runtime/processor_cumulative_to_delta.c index da65c7479a2..e4e97fd3e82 100644 --- a/tests/runtime/processor_cumulative_to_delta.c +++ b/tests/runtime/processor_cumulative_to_delta.c @@ -1,7 +1,7 @@ /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ #include -#include +#include #include #include diff --git a/tests/runtime_shell/CMakeLists.txt b/tests/runtime_shell/CMakeLists.txt index 09ad71ae9c0..34cacd1c5ff 100644 --- a/tests/runtime_shell/CMakeLists.txt +++ b/tests/runtime_shell/CMakeLists.txt @@ -1,42 +1,107 @@ -configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/runtime_shell.env.in" - "${CMAKE_CURRENT_SOURCE_DIR}/runtime_shell.env" +set(RUNTIME_SHELL_ENVIRONMENT + "FLB_ROOT=${PROJECT_SOURCE_DIR};\ +FLB_RUNTIME_SHELL_PATH=${CMAKE_CURRENT_SOURCE_DIR};\ +FLB_RUNTIME_SHELL_CONF=${CMAKE_CURRENT_SOURCE_DIR}/conf;\ +FLB_BIN=${CMAKE_BINARY_DIR}/bin/fluent-bit${CMAKE_EXECUTABLE_SUFFIX};\ +FLB_BUILD=${CMAKE_BINARY_DIR}" ) -set(UNIT_TESTS_SH - custom_calyptia.sh - dry_run_invalid_property.sh - in_dummy_expect.sh - in_tail_expect.sh - in_http_tls_expect.sh - in_syslog_tcp_tls_expect.sh - in_syslog_tcp_plaintext_expect.sh - in_syslog_udp_plaintext_expect.sh - in_syslog_uds_dgram_plaintext_expect.sh - in_syslog_uds_stream_plaintext_expect.sh - processor_conditional.sh - processor_invalid.sh - ) +if(WIN32) + find_program(POWERSHELL_EXECUTABLE NAMES pwsh powershell) + + if(POWERSHELL_EXECUTABLE) + set(UNIT_TESTS_PS + in_dummy_expect.ps1 + in_tail_expect.ps1 + in_syslog_tcp_plaintext_expect.ps1 + in_syslog_udp_plaintext_expect.ps1 + ) + + if(FLB_TLS) + list(APPEND UNIT_TESTS_PS + in_http_tls_expect.ps1 + in_syslog_tcp_tls_expect.ps1 + ) + else() + message(STATUS "Skipping TLS runtime_shell tests on Windows: TLS is disabled") + endif() + + if(FLB_CUSTOM_CALYPTIA) + list(APPEND UNIT_TESTS_PS custom_calyptia.ps1) + endif() + + if(FLB_HAVE_LIBYAML) + list(APPEND UNIT_TESTS_PS + dry_run_invalid_property.ps1 + processor_conditional.ps1 + processor_invalid.ps1 + ) + else() + message(STATUS + "Skipping YAML runtime_shell tests on Windows: libyaml is unavailable") + endif() + + message(STATUS + "Skipping Unix-domain-socket runtime_shell tests on Windows") + + foreach(script ${UNIT_TESTS_PS}) + add_test(NAME ${script} + COMMAND ${POWERSHELL_EXECUTABLE} + -NoLogo + -NoProfile + -NonInteractive + -ExecutionPolicy Bypass + -File ${CMAKE_CURRENT_SOURCE_DIR}/${script} + ) -if (CMAKE_SYSTEM_NAME STREQUAL "Linux") - if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(riscv64)") - message(STATUS "We don't test Golang plugins on RISC-V 64bit platform for now") + set_tests_properties(${script} PROPERTIES + ENVIRONMENT "${RUNTIME_SHELL_ENVIRONMENT}" + LABELS "runtime_shell" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + endforeach() else() - list(APPEND UNIT_TESTS_SH proxy_logs_expect.sh) + message(STATUS + "Skipping runtime_shell tests on Windows: PowerShell was not found") endif() -endif() - -# Prepare list of unit tests -foreach(script ${UNIT_TESTS_SH}) - add_test(NAME ${script} - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/${script} +else() + configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/runtime_shell.env.in" + "${CMAKE_CURRENT_SOURCE_DIR}/runtime_shell.env" ) - set_tests_properties(${script} PROPERTIES ENVIRONMENT - "FLB_ROOT=${PROJECT_SOURCE_DIR};\ -FLB_RUNTIME_SHELL_PATH=${CMAKE_CURRENT_SOURCE_DIR};\ -FLB_RUNTIME_SHELL_CONF=${CMAKE_CURRENT_SOURCE_DIR}/conf;\ -FLB_BIN=${CMAKE_BINARY_DIR}/bin/fluent-bit;\ -FLB_BUILD=${CMAKE_BINARY_DIR}" + set(UNIT_TESTS_SH + custom_calyptia.sh + dry_run_invalid_property.sh + in_dummy_expect.sh + in_tail_expect.sh + in_http_tls_expect.sh + in_syslog_tcp_tls_expect.sh + in_syslog_tcp_plaintext_expect.sh + in_syslog_udp_plaintext_expect.sh + in_syslog_uds_dgram_plaintext_expect.sh + in_syslog_uds_stream_plaintext_expect.sh + processor_conditional.sh + processor_invalid.sh ) -endforeach() + + if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(riscv64)") + message(STATUS + "We don't test Golang plugins on RISC-V 64bit platform for now") + else() + list(APPEND UNIT_TESTS_SH proxy_logs_expect.sh) + endif() + endif() + + foreach(script ${UNIT_TESTS_SH}) + add_test(NAME ${script} + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/${script} + ) + + set_tests_properties(${script} PROPERTIES + ENVIRONMENT "${RUNTIME_SHELL_ENVIRONMENT}" + LABELS "runtime_shell" + ) + endforeach() +endif() diff --git a/tests/runtime_shell/common.ps1 b/tests/runtime_shell/common.ps1 new file mode 100644 index 00000000000..2d81c415400 --- /dev/null +++ b/tests/runtime_shell/common.ps1 @@ -0,0 +1,121 @@ +Set-StrictMode -Version Latest +$ErrorActionPreference = "Stop" + +function Assert-RuntimeEnvironment +{ + foreach ($name in @("FLB_ROOT", "FLB_RUNTIME_SHELL_PATH", + "FLB_RUNTIME_SHELL_CONF", "FLB_BIN", "FLB_BUILD")) { + $value = [Environment]::GetEnvironmentVariable($name) + if ([string]::IsNullOrWhiteSpace($value)) { + throw "Required environment variable $name is not set" + } + } + + if (-not (Test-Path -LiteralPath $env:FLB_BIN -PathType Leaf)) { + throw "Fluent Bit executable was not found at $env:FLB_BIN" + } +} + +function Get-RuntimeConfigPath +{ + param([Parameter(Mandatory = $true)][string] $Name) + + return Join-Path $env:FLB_RUNTIME_SHELL_CONF $Name +} + +function New-RuntimeTempDirectory +{ + param([Parameter(Mandatory = $true)][string] $Name) + + $directory = Join-Path ([IO.Path]::GetTempPath()) ( + "fluent-bit-runtime-shell-{0}-{1}" -f $Name, [guid]::NewGuid()) + [void] (New-Item -ItemType Directory -Path $directory) + return $directory +} + +function Start-FluentBit +{ + param( + [Parameter(Mandatory = $true)][string] $ConfigPath, + [string[]] $AdditionalArguments = @(), + [string] $StandardOutputPath, + [string] $StandardErrorPath + ) + + $arguments = @("-c", ('"{0}"' -f $ConfigPath)) + $AdditionalArguments + $parameters = @{ + FilePath = $env:FLB_BIN + ArgumentList = $arguments + NoNewWindow = $true + PassThru = $true + } + + if (-not [string]::IsNullOrWhiteSpace($StandardOutputPath)) { + $parameters.RedirectStandardOutput = $StandardOutputPath + } + if (-not [string]::IsNullOrWhiteSpace($StandardErrorPath)) { + $parameters.RedirectStandardError = $StandardErrorPath + } + + return Start-Process @parameters +} + +function Stop-FluentBit +{ + param([System.Diagnostics.Process] $Process) + + if ($null -ne $Process -and -not $Process.HasExited) { + Stop-Process -Id $Process.Id -Force + [void] $Process.WaitForExit(5000) + } +} + +function Wait-ForFile +{ + param( + [Parameter(Mandatory = $true)][string] $Path, + [Parameter(Mandatory = $true)][System.Diagnostics.Process] $Process, + [int] $TimeoutSeconds = 15 + ) + + $deadline = [DateTime]::UtcNow.AddSeconds($TimeoutSeconds) + while ([DateTime]::UtcNow -lt $deadline) { + if (Test-Path -LiteralPath $Path -PathType Leaf) { + return + } + if ($Process.HasExited) { + throw "Fluent Bit exited before creating $Path (code $($Process.ExitCode))" + } + Start-Sleep -Milliseconds 100 + } + + throw "Timed out waiting for Fluent Bit to create $Path" +} + +function Wait-FluentBitExit +{ + param( + [Parameter(Mandatory = $true)][System.Diagnostics.Process] $Process, + [int] $TimeoutSeconds = 15 + ) + + if (-not $Process.WaitForExit($TimeoutSeconds * 1000)) { + Stop-FluentBit $Process + throw "Timed out waiting for Fluent Bit to exit" + } + if ($Process.ExitCode -ne 0) { + throw "Fluent Bit exited with code $($Process.ExitCode)" + } +} + +function Invoke-FluentBit +{ + param( + [Parameter(Mandatory = $true)][string] $ConfigPath, + [string[]] $AdditionalArguments = @() + ) + + & $env:FLB_BIN -c $ConfigPath @AdditionalArguments | Out-Host + $exitCode = $LASTEXITCODE + return $exitCode +} diff --git a/tests/runtime_shell/conf/dry_run_invalid_property.yaml b/tests/runtime_shell/conf/dry_run_invalid_property.yaml new file mode 100644 index 00000000000..7424a89dc11 --- /dev/null +++ b/tests/runtime_shell/conf/dry_run_invalid_property.yaml @@ -0,0 +1,11 @@ +service: + log_level: debug + flush: 1 +pipeline: + inputs: + - name: dummy + tag: test + invalid_property_that_does_not_exist: some_value + outputs: + - name: stdout + match: '*' diff --git a/tests/runtime_shell/conf/in_tail_expect.conf b/tests/runtime_shell/conf/in_tail_expect.conf index 7348bacc0c7..d4ad0762564 100644 --- a/tests/runtime_shell/conf/in_tail_expect.conf +++ b/tests/runtime_shell/conf/in_tail_expect.conf @@ -6,8 +6,8 @@ [INPUT] name tail - path /tmp/flb_tail_expect*.log - exclude_path /tmp/flb_*2.log + path ${TAIL_TEST_GLOB} + exclude_path ${TAIL_TEST_EXCLUDE} read_from_head true parser json refresh_interval 10 @@ -20,7 +20,7 @@ buffer_max_size 32k skip_long_lines false exit_on_eof false - db /tmp/flb_tail_expect.db + db ${TAIL_TEST_DB} db.sync full [FILTER] @@ -29,7 +29,7 @@ Log_Level debug # Rules key_exists $path_key - key_val_eq $path_key /tmp/flb_tail_expect_1.log + key_val_eq $path_key ${TAIL_TEST_FILE} key_not_exists $nokey action exit diff --git a/tests/runtime_shell/conf/processor_conditional.yaml b/tests/runtime_shell/conf/processor_conditional.yaml new file mode 100644 index 00000000000..99cab96378b --- /dev/null +++ b/tests/runtime_shell/conf/processor_conditional.yaml @@ -0,0 +1,35 @@ +service: + log_level: trace + flush: 1 +pipeline: + inputs: + - name: dummy + dummy: '{"request": {"method": "GET", "path": "/api/v1/resource", "headers": {"Authorization": "Bearer valid-token"}, "access": "granted"}}' + tag: error.msg + processors: + logs: + - name: content_modifier + action: insert + key: modified_if_post + value: true + condition: + op: and + rules: + - field: $request['method'] + op: eq + value: POST + + - name: content_modifier + action: insert + key: modified_if_get + value: true + condition: + op: and + rules: + - field: $request['method'] + op: eq + value: GET + + outputs: + - name: stdout + match: '*' diff --git a/tests/runtime_shell/conf/processor_conditional_grep.yaml b/tests/runtime_shell/conf/processor_conditional_grep.yaml new file mode 100644 index 00000000000..9f0661e223c --- /dev/null +++ b/tests/runtime_shell/conf/processor_conditional_grep.yaml @@ -0,0 +1,54 @@ +service: + log_level: trace + flush: 1 +pipeline: + inputs: + - name: dummy + dummy: '{"endpoint":"localhost", "value":"something"}' + tag: dummy + processors: + logs: + - name: grep + logical_op: and + regex: + - value something + condition: + op: and + rules: + - field: $endpoint + op: eq + value: farhost + - name: dummy + dummy: '{"endpoint":"localhost2", "value":"something"}' + tag: dummy + processors: + logs: + - name: grep + logical_op: and + regex: + - value something + condition: + op: and + rules: + - field: $endpoint + op: eq + value: farhost + - name: dummy + dummy: '{"endpoint":"farhost", "value":"nothing"}' + tag: dummy + processors: + logs: + - name: grep + logical_op: and + regex: + - value something + condition: + op: and + rules: + - field: $endpoint + op: eq + value: farhost + + outputs: + - name: stdout + match: '*' diff --git a/tests/runtime_shell/conf/processor_invalid.yaml b/tests/runtime_shell/conf/processor_invalid.yaml new file mode 100644 index 00000000000..bdd554a4423 --- /dev/null +++ b/tests/runtime_shell/conf/processor_invalid.yaml @@ -0,0 +1,16 @@ +service: + log_level: debug + flush: 1 +pipeline: + inputs: + - name: dummy + dummy: '{"message": "test message"}' + tag: test + processors: + logs: + - name: non_existent_processor + action: invalid + + outputs: + - name: stdout + match: '*' diff --git a/tests/runtime_shell/custom_calyptia.ps1 b/tests/runtime_shell/custom_calyptia.ps1 new file mode 100644 index 00000000000..de366117054 --- /dev/null +++ b/tests/runtime_shell/custom_calyptia.ps1 @@ -0,0 +1,74 @@ +. "$PSScriptRoot/common.ps1" + +function Test-CalyptiaFleetFormat +{ + param( + [Parameter(Mandatory = $true)][string] $Format, + [Parameter(Mandatory = $true)][bool] $ExpectYaml + ) + + $process = $null + $env:CALYPTIA_FLEET_FORMAT = $Format + if (Test-Path -LiteralPath $env:CALYPTIA_FLEET_DIR) { + Remove-Item -LiteralPath $env:CALYPTIA_FLEET_DIR -Recurse -Force + } + [void] (New-Item -ItemType Directory -Path $env:CALYPTIA_FLEET_DIR) + + $config = Get-RuntimeConfigPath "custom_calyptia_fleet.conf" + $exitCode = Invoke-FluentBit $config @("--dry-run") + if ($exitCode -ne 0) { + throw "Calyptia fleet dry run failed with code $exitCode" + } + + try { + $process = Start-FluentBit $config + Start-Sleep -Seconds 30 + if ($process.HasExited -and $process.ExitCode -ne 0) { + throw "Fluent Bit exited with code $($process.ExitCode)" + } + + $yamlFiles = @(Get-ChildItem -LiteralPath $env:CALYPTIA_FLEET_DIR ` + -Filter "*.yaml" -File -Recurse -ErrorAction SilentlyContinue) + if ($ExpectYaml -and $yamlFiles.Count -eq 0) { + throw "No YAML fleet configuration files were found" + } + if (-not $ExpectYaml -and $yamlFiles.Count -ne 0) { + throw "YAML fleet configuration files were unexpectedly found" + } + + foreach ($file in $yamlFiles) { + Get-Content -LiteralPath $file.FullName | Out-Host + } + } + finally { + Stop-FluentBit $process + } +} + +$tempDirectory = $null + +try { + Assert-RuntimeEnvironment + if ([string]::IsNullOrWhiteSpace($env:CALYPTIA_FLEET_TOKEN)) { + Write-Host "SKIP: CALYPTIA_FLEET_TOKEN is not set" + exit 0 + } + + if ([string]::IsNullOrWhiteSpace($env:CALYPTIA_FLEET_DIR)) { + $tempDirectory = New-RuntimeTempDirectory "custom-calyptia" + $env:CALYPTIA_FLEET_DIR = Join-Path $tempDirectory "fleet-test" + } + + Test-CalyptiaFleetFormat "off" $true + Test-CalyptiaFleetFormat "on" $false + exit 0 +} +catch { + Write-Host "ERROR: $($_.Exception.Message)" + exit 1 +} +finally { + if ($null -ne $tempDirectory) { + Remove-Item -LiteralPath $tempDirectory -Recurse -Force -ErrorAction SilentlyContinue + } +} diff --git a/tests/runtime_shell/dry_run_invalid_property.ps1 b/tests/runtime_shell/dry_run_invalid_property.ps1 new file mode 100644 index 00000000000..a5a7c1d196e --- /dev/null +++ b/tests/runtime_shell/dry_run_invalid_property.ps1 @@ -0,0 +1,29 @@ +. "$PSScriptRoot/common.ps1" + +try { + Assert-RuntimeEnvironment + $configPath = Get-RuntimeConfigPath "dry_run_invalid_property.yaml" + + Write-Host "Running Fluent Bit with --dry-run and invalid property config..." + $output = & $env:FLB_BIN --dry-run -c $configPath 2>&1 | Out-String + $exitCode = $LASTEXITCODE + Write-Host $output + + if ($exitCode -eq 0) { + throw "Fluent Bit --dry-run unexpectedly succeeded" + } + if (-not $output.Contains( + "unknown configuration property 'invalid_property_that_does_not_exist'")) { + throw "Unknown property error was not reported" + } + if (-not $output.Contains("check properties for input plugins is failed")) { + throw "Input plugin validation error was not reported" + } + + Write-Host "Test passed: Fluent Bit detected the invalid property" + exit 0 +} +catch { + Write-Host "ERROR: $($_.Exception.Message)" + exit 1 +} diff --git a/tests/runtime_shell/dry_run_invalid_property.sh b/tests/runtime_shell/dry_run_invalid_property.sh index ee48c8693b8..f0d712d9d0c 100755 --- a/tests/runtime_shell/dry_run_invalid_property.sh +++ b/tests/runtime_shell/dry_run_invalid_property.sh @@ -1,64 +1,41 @@ #!/bin/sh -# Setup environment if not already set -if [ -z "$FLB_BIN" ]; then - FLB_ROOT=${FLB_ROOT:-$(cd $(dirname $0)/../.. && pwd)} - FLB_BIN=${FLB_BIN:-$FLB_ROOT/build/bin/fluent-bit} -fi +FLB_ROOT=${FLB_ROOT:-$(cd "$(dirname "$0")/../.." && pwd)} +FLB_BIN=${FLB_BIN:-$FLB_ROOT/build/bin/fluent-bit} +FLB_RUNTIME_SHELL_CONF=${FLB_RUNTIME_SHELL_CONF:-$FLB_ROOT/tests/runtime_shell/conf} echo "Using Fluent Bit at: $FLB_BIN" -# Create a temporary YAML config file with an invalid property -cat > /tmp/dry_run_invalid_property.yaml << EOL -service: - log_level: debug - flush: 1 -pipeline: - inputs: - - name: dummy - tag: test - invalid_property_that_does_not_exist: some_value - outputs: - - name: stdout - match: '*' -EOL +CONFIG_FILE="$FLB_RUNTIME_SHELL_CONF/dry_run_invalid_property.yaml" +OUTPUT_FILE="/tmp/dry_run_invalid_property_output.txt" echo "Running Fluent Bit with --dry-run and invalid property config..." echo "YAML Config:" -cat /tmp/dry_run_invalid_property.yaml +cat "$CONFIG_FILE" -# Redirect stdout and stderr to a file for analysis -OUTPUT_FILE="/tmp/dry_run_invalid_property_output.txt" -$FLB_BIN --dry-run -c /tmp/dry_run_invalid_property.yaml > $OUTPUT_FILE 2>&1 - -# Check exit code - we expect it to fail +"$FLB_BIN" --dry-run -c "$CONFIG_FILE" > "$OUTPUT_FILE" 2>&1 EXIT_CODE=$? echo "Fluent Bit --dry-run exited with code: $EXIT_CODE" -# Show the output echo "Output file content:" -cat $OUTPUT_FILE +cat "$OUTPUT_FILE" -# Check if the output contains an error about the unknown configuration property -UNKNOWN_PROPERTY=$(grep -c "unknown configuration property 'invalid_property_that_does_not_exist'" $OUTPUT_FILE || true) -RELOAD_ERROR=$(grep -c "check properties for input plugins is failed" $OUTPUT_FILE || true) +UNKNOWN_PROPERTY=$(grep -c \ + "unknown configuration property 'invalid_property_that_does_not_exist'" \ + "$OUTPUT_FILE" || true) +RELOAD_ERROR=$(grep -c \ + "check properties for input plugins is failed" "$OUTPUT_FILE" || true) -# Clean up -echo "Cleaning up..." -rm -f /tmp/dry_run_invalid_property.yaml -rm -f $OUTPUT_FILE +rm -f "$OUTPUT_FILE" -# Check results - we expect: -# 1. Fluent Bit to fail (non-zero exit code) -# 2. Error message about unknown configuration property -# 3. Error message from reload validation -if [ "$EXIT_CODE" -ne 0 ] && [ "$UNKNOWN_PROPERTY" -gt 0 ] && [ "$RELOAD_ERROR" -gt 0 ]; then +if [ "$EXIT_CODE" -ne 0 ] && [ "$UNKNOWN_PROPERTY" -gt 0 ] && \ + [ "$RELOAD_ERROR" -gt 0 ]; then echo "Test passed: Fluent Bit --dry-run correctly detected invalid property and failed" exit 0 -else - echo "Test failed: Fluent Bit --dry-run should detect invalid properties and fail" - echo "Exit code: $EXIT_CODE (expected non-zero)" - echo "Unknown property message count: $UNKNOWN_PROPERTY (expected > 0)" - echo "Reload error message count: $RELOAD_ERROR (expected > 0)" - exit 1 fi + +echo "Test failed: Fluent Bit --dry-run should detect invalid properties and fail" +echo "Exit code: $EXIT_CODE (expected non-zero)" +echo "Unknown property message count: $UNKNOWN_PROPERTY (expected > 0)" +echo "Reload error message count: $RELOAD_ERROR (expected > 0)" +exit 1 diff --git a/tests/runtime_shell/in_dummy_expect.ps1 b/tests/runtime_shell/in_dummy_expect.ps1 new file mode 100644 index 00000000000..a4a949408ef --- /dev/null +++ b/tests/runtime_shell/in_dummy_expect.ps1 @@ -0,0 +1,14 @@ +. "$PSScriptRoot/common.ps1" + +try { + Assert-RuntimeEnvironment + $exitCode = Invoke-FluentBit (Get-RuntimeConfigPath "in_dummy_expect.conf") + if ($exitCode -ne 0) { + throw "Fluent Bit exited with code $exitCode" + } + exit 0 +} +catch { + Write-Host "ERROR: $($_.Exception.Message)" + exit 1 +} diff --git a/tests/runtime_shell/in_http_tls_expect.ps1 b/tests/runtime_shell/in_http_tls_expect.ps1 new file mode 100644 index 00000000000..f0d0c634119 --- /dev/null +++ b/tests/runtime_shell/in_http_tls_expect.ps1 @@ -0,0 +1,79 @@ +. "$PSScriptRoot/common.ps1" + +Add-Type -TypeDefinition @' +using System.Net.Http; +using System.Net.Security; +using System.Security.Cryptography.X509Certificates; + +public static class RuntimeShellCertificateValidator +{ + public static bool ValidateHttp( + HttpRequestMessage request, + X509Certificate2 certificate, + X509Chain chain, + SslPolicyErrors sslPolicyErrors) + { + return true; + } +} +'@ + +$process = $null +$tempDirectory = $null +$client = $null +$handler = $null +$content = $null + +try { + Assert-RuntimeEnvironment + $tempDirectory = New-RuntimeTempDirectory "http-tls" + $signalFile = Join-Path $tempDirectory "signal.log" + $env:SIGNAL_FILE_PATH = $signalFile + $env:LISTENER_VHOST = "leo.vcap.me" + $env:LISTENER_HOST = "127.0.0.1" + $env:LISTENER_PORT = "50000" + + $config = Get-RuntimeConfigPath "in_http_tls_expect.conf" + $process = Start-FluentBit $config + Wait-ForFile $signalFile $process + + $handler = [Net.Http.HttpClientHandler]::new() + $validatorType = [Func[Net.Http.HttpRequestMessage, + Security.Cryptography.X509Certificates.X509Certificate2, + Security.Cryptography.X509Certificates.X509Chain, + Net.Security.SslPolicyErrors, bool]] + $validatorMethod = [RuntimeShellCertificateValidator].GetMethod("ValidateHttp") + $handler.ServerCertificateCustomValidationCallback = + $validatorMethod.CreateDelegate($validatorType) + $handler.SslProtocols = [Security.Authentication.SslProtocols]::Tls12 + $client = [Net.Http.HttpClient]::new($handler) + $content = [Net.Http.StringContent]::new( + '{"message":"Hello!"}', [Text.Encoding]::UTF8, "application/json") + $uri = "https://$($env:LISTENER_HOST):$($env:LISTENER_PORT)" + $response = $client.PostAsync($uri, $content).GetAwaiter().GetResult() + if (-not $response.IsSuccessStatusCode) { + throw "HTTP input returned status $([int] $response.StatusCode)" + } + + Wait-FluentBitExit $process + exit 0 +} +catch { + Write-Host "ERROR: $($_.Exception.ToString())" + exit 1 +} +finally { + if ($null -ne $content) { + $content.Dispose() + } + if ($null -ne $client) { + $client.Dispose() + } + if ($null -ne $handler) { + $handler.Dispose() + } + Stop-FluentBit $process + if ($null -ne $tempDirectory) { + Remove-Item -LiteralPath $tempDirectory -Recurse -Force -ErrorAction SilentlyContinue + } +} diff --git a/tests/runtime_shell/in_syslog_tcp_plaintext_expect.ps1 b/tests/runtime_shell/in_syslog_tcp_plaintext_expect.ps1 new file mode 100644 index 00000000000..aec1243157b --- /dev/null +++ b/tests/runtime_shell/in_syslog_tcp_plaintext_expect.ps1 @@ -0,0 +1,44 @@ +. "$PSScriptRoot/common.ps1" + +$process = $null +$tempDirectory = $null +$client = $null + +try { + Assert-RuntimeEnvironment + $tempDirectory = New-RuntimeTempDirectory "syslog-tcp" + $signalFile = Join-Path $tempDirectory "signal.log" + $env:SIGNAL_FILE_PATH = $signalFile + $env:LISTENER_HOST = "127.0.0.1" + $env:LISTENER_PORT = "50001" + + $config = Get-RuntimeConfigPath "in_syslog_tcp_plaintext_expect.conf" + $process = Start-FluentBit $config + Wait-ForFile $signalFile $process + + $client = [Net.Sockets.TcpClient]::new() + $client.Connect($env:LISTENER_HOST, [int] $env:LISTENER_PORT) + $stream = $client.GetStream() + $payload = [Text.Encoding]::UTF8.GetBytes( + "<13>1 1970-01-01T00:00:00.000000+00:00 testhost testuser - - [] Hello!`n") + $stream.Write($payload, 0, $payload.Length) + $stream.Flush() + $client.Close() + $client = $null + + Wait-FluentBitExit $process + exit 0 +} +catch { + Write-Host "ERROR: $($_.Exception.Message)" + exit 1 +} +finally { + if ($null -ne $client) { + $client.Dispose() + } + Stop-FluentBit $process + if ($null -ne $tempDirectory) { + Remove-Item -LiteralPath $tempDirectory -Recurse -Force -ErrorAction SilentlyContinue + } +} diff --git a/tests/runtime_shell/in_syslog_tcp_tls_expect.ps1 b/tests/runtime_shell/in_syslog_tcp_tls_expect.ps1 new file mode 100644 index 00000000000..faa4df5388f --- /dev/null +++ b/tests/runtime_shell/in_syslog_tcp_tls_expect.ps1 @@ -0,0 +1,61 @@ +. "$PSScriptRoot/common.ps1" + +$process = $null +$tempDirectory = $null +$client = $null +$tlsStream = $null + +try { + Assert-RuntimeEnvironment + $tempDirectory = New-RuntimeTempDirectory "syslog-tcp-tls" + $signalFile = Join-Path $tempDirectory "signal.log" + $env:SIGNAL_FILE_PATH = $signalFile + $env:LISTENER_VHOST = "leo.vcap.me" + $env:LISTENER_HOST = "127.0.0.1" + $env:LISTENER_PORT = "50002" + + $config = Get-RuntimeConfigPath "in_syslog_tcp_tls_expect.conf" + $process = Start-FluentBit $config + Wait-ForFile $signalFile $process + + $client = [Net.Sockets.TcpClient]::new() + $client.Connect($env:LISTENER_HOST, [int] $env:LISTENER_PORT) + $validationCallback = [Net.Security.RemoteCertificateValidationCallback] { + param($sender, $certificate, $chain, $sslPolicyErrors) + return $true + } + $tlsStream = [Net.Security.SslStream]::new( + $client.GetStream(), $false, $validationCallback) + $tlsOptions = [Net.Security.SslClientAuthenticationOptions]::new() + $tlsOptions.TargetHost = $env:LISTENER_VHOST + $tlsOptions.EnabledSslProtocols = [Security.Authentication.SslProtocols]::Tls12 + $tlsOptions.CertificateRevocationCheckMode = [Security.Cryptography.X509Certificates.X509RevocationMode]::NoCheck + $tlsStream.AuthenticateAsClient($tlsOptions) + $payload = [Text.Encoding]::UTF8.GetBytes( + "<13>1 1970-01-01T00:00:00.000000+00:00 testhost testuser - - [] Hello!`n") + $tlsStream.Write($payload, 0, $payload.Length) + $tlsStream.Flush() + $tlsStream.Close() + $tlsStream = $null + $client.Close() + $client = $null + + Wait-FluentBitExit $process + exit 0 +} +catch { + Write-Host "ERROR: $($_.Exception.ToString())" + exit 1 +} +finally { + if ($null -ne $tlsStream) { + $tlsStream.Dispose() + } + if ($null -ne $client) { + $client.Dispose() + } + Stop-FluentBit $process + if ($null -ne $tempDirectory) { + Remove-Item -LiteralPath $tempDirectory -Recurse -Force -ErrorAction SilentlyContinue + } +} diff --git a/tests/runtime_shell/in_syslog_udp_plaintext_expect.ps1 b/tests/runtime_shell/in_syslog_udp_plaintext_expect.ps1 new file mode 100644 index 00000000000..7c3902f0bda --- /dev/null +++ b/tests/runtime_shell/in_syslog_udp_plaintext_expect.ps1 @@ -0,0 +1,42 @@ +. "$PSScriptRoot/common.ps1" + +$process = $null +$tempDirectory = $null +$client = $null + +try { + Assert-RuntimeEnvironment + $tempDirectory = New-RuntimeTempDirectory "syslog-udp" + $signalFile = Join-Path $tempDirectory "signal.log" + $env:SIGNAL_FILE_PATH = $signalFile + $env:LISTENER_HOST = "127.0.0.1" + $env:LISTENER_PORT = "50003" + + $config = Get-RuntimeConfigPath "in_syslog_udp_plaintext_expect.conf" + $process = Start-FluentBit $config + Wait-ForFile $signalFile $process + + $client = [Net.Sockets.UdpClient]::new() + $payload = [Text.Encoding]::UTF8.GetBytes( + "<13>1 1970-01-01T00:00:00.000000+00:00 testhost testuser - - [] Hello!`n") + [void] $client.Send( + $payload, $payload.Length, $env:LISTENER_HOST, [int] $env:LISTENER_PORT) + $client.Close() + $client = $null + + Wait-FluentBitExit $process + exit 0 +} +catch { + Write-Host "ERROR: $($_.Exception.Message)" + exit 1 +} +finally { + if ($null -ne $client) { + $client.Dispose() + } + Stop-FluentBit $process + if ($null -ne $tempDirectory) { + Remove-Item -LiteralPath $tempDirectory -Recurse -Force -ErrorAction SilentlyContinue + } +} diff --git a/tests/runtime_shell/in_tail_expect.ps1 b/tests/runtime_shell/in_tail_expect.ps1 new file mode 100644 index 00000000000..3deaaa46bcc --- /dev/null +++ b/tests/runtime_shell/in_tail_expect.ps1 @@ -0,0 +1,37 @@ +. "$PSScriptRoot/common.ps1" + +$tempDirectory = $null + +try { + Assert-RuntimeEnvironment + $tempDirectory = New-RuntimeTempDirectory "in-tail-expect" + $targetFile = Join-Path $tempDirectory "flb_tail_expect_1.log" + $excludedFile = Join-Path $tempDirectory "flb_tail_expect_2.log" + + $env:TAIL_TEST_GLOB = Join-Path $tempDirectory "flb_tail_expect_*.log" + $env:TAIL_TEST_EXCLUDE = Join-Path $tempDirectory "flb_*2.log" + $env:TAIL_TEST_FILE = $targetFile + $env:TAIL_TEST_DB = Join-Path $tempDirectory "flb_tail_expect.db" + + $encoding = [Text.UTF8Encoding]::new($false) + [IO.File]::WriteAllText( + $targetFile, "{`"key`": `"val`"}`r`n", $encoding) + [IO.File]::WriteAllText( + $excludedFile, "{`"nokey`": `"`"}`r`n", $encoding) + + $config = Get-RuntimeConfigPath "in_tail_expect.conf" + $exitCode = Invoke-FluentBit $config + if ($exitCode -ne 0) { + throw "Fluent Bit exited with code $exitCode" + } + exit 0 +} +catch { + Write-Host "ERROR: $($_.Exception.Message)" + exit 1 +} +finally { + if ($null -ne $tempDirectory) { + Remove-Item -LiteralPath $tempDirectory -Recurse -Force -ErrorAction SilentlyContinue + } +} diff --git a/tests/runtime_shell/in_tail_expect.sh b/tests/runtime_shell/in_tail_expect.sh index c847d65f418..3da138fbf9d 100755 --- a/tests/runtime_shell/in_tail_expect.sh +++ b/tests/runtime_shell/in_tail_expect.sh @@ -3,8 +3,13 @@ test_in_tail_filter_expect() { rm -rf /tmp/flb_* + export TAIL_TEST_GLOB="/tmp/flb_tail_expect*.log" + export TAIL_TEST_EXCLUDE="/tmp/flb_*2.log" + export TAIL_TEST_FILE="/tmp/flb_tail_expect_1.log" + export TAIL_TEST_DB="/tmp/flb_tail_expect.db" + # Monitor this file - echo "{\"key\": \"val\"}" > /tmp/flb_tail_expect_1.log + echo "{\"key\": \"val\"}" > "$TAIL_TEST_FILE" # Excluded file echo "{\"nokey\": \"\"}" > /tmp/flb_tail_expect_2.log diff --git a/tests/runtime_shell/processor_conditional.ps1 b/tests/runtime_shell/processor_conditional.ps1 new file mode 100644 index 00000000000..c7749d55785 --- /dev/null +++ b/tests/runtime_shell/processor_conditional.ps1 @@ -0,0 +1,82 @@ +. "$PSScriptRoot/common.ps1" + +function Invoke-ConditionalProcessor +{ + param( + [Parameter(Mandatory = $true)][string] $ConfigPath, + [Parameter(Mandatory = $true)][string] $OutputPath, + [Parameter(Mandatory = $true)][string] $ErrorPath + ) + + $process = $null + try { + $process = Start-FluentBit $ConfigPath @("-o", "stdout") $OutputPath $ErrorPath + Start-Sleep -Seconds 5 + if ($process.HasExited -and $process.ExitCode -ne 0) { + throw "Fluent Bit exited with code $($process.ExitCode)" + } + } + finally { + Stop-FluentBit $process + } + + $output = "" + if (Test-Path -LiteralPath $OutputPath -PathType Leaf) { + $output += Get-Content -LiteralPath $OutputPath -Raw + } + if (Test-Path -LiteralPath $ErrorPath -PathType Leaf) { + $output += Get-Content -LiteralPath $ErrorPath -Raw + } + return $output +} + +$tempDirectory = $null + +try { + Assert-RuntimeEnvironment + $tempDirectory = New-RuntimeTempDirectory "processor-conditional" + $conditionalConfigPath = Get-RuntimeConfigPath "processor_conditional.yaml" + + $conditionalOutput = Invoke-ConditionalProcessor ` + $conditionalConfigPath ` + (Join-Path $tempDirectory "processor_conditional.stdout") ` + (Join-Path $tempDirectory "processor_conditional.stderr") + Write-Host $conditionalOutput + + if (-not $conditionalOutput.Contains("modified_if_get")) { + throw "GET condition was not applied" + } + if ($conditionalOutput.Contains("modified_if_post")) { + throw "POST condition was unexpectedly applied" + } + + $grepConfigPath = Get-RuntimeConfigPath "processor_conditional_grep.yaml" + + $grepOutput = Invoke-ConditionalProcessor ` + $grepConfigPath ` + (Join-Path $tempDirectory "processor_conditional_grep.stdout") ` + (Join-Path $tempDirectory "processor_conditional_grep.stderr") + Write-Host $grepOutput + + if (-not $grepOutput.Contains('"endpoint"=>"localhost"')) { + throw "localhost record was not emitted" + } + if (-not $grepOutput.Contains('"endpoint"=>"localhost2"')) { + throw "localhost2 record was not emitted" + } + if ($grepOutput.Contains('"endpoint"=>"farhost"')) { + throw "farhost record was unexpectedly emitted" + } + + Write-Host "Test passed: conditional processors selected the expected records" + exit 0 +} +catch { + Write-Host "ERROR: $($_.Exception.Message)" + exit 1 +} +finally { + if ($null -ne $tempDirectory) { + Remove-Item -LiteralPath $tempDirectory -Recurse -Force -ErrorAction SilentlyContinue + } +} diff --git a/tests/runtime_shell/processor_conditional.sh b/tests/runtime_shell/processor_conditional.sh index 292fa087110..31bd453082b 100755 --- a/tests/runtime_shell/processor_conditional.sh +++ b/tests/runtime_shell/processor_conditional.sh @@ -1,87 +1,40 @@ #!/bin/sh -# Setup environment if not already set -if [ -z "$FLB_BIN" ]; then - FLB_ROOT=${FLB_ROOT:-$(cd $(dirname $0)/../.. && pwd)} - FLB_BIN=${FLB_BIN:-$FLB_ROOT/build/bin/fluent-bit} -fi +FLB_ROOT=${FLB_ROOT:-$(cd "$(dirname "$0")/../.." && pwd)} +FLB_BIN=${FLB_BIN:-$FLB_ROOT/build/bin/fluent-bit} +FLB_RUNTIME_SHELL_CONF=${FLB_RUNTIME_SHELL_CONF:-$FLB_ROOT/tests/runtime_shell/conf} echo "Using Fluent Bit at: $FLB_BIN" -# Create a temporary YAML config file -cat > /tmp/processor_conditional.yaml << EOL -service: - log_level: trace - flush: 1 -pipeline: - inputs: - - name: dummy - dummy: '{"request": {"method": "GET", "path": "/api/v1/resource", "headers": {"Authorization": "Bearer valid-token"}, "access": "granted"}}' - tag: error.msg - processors: - logs: - - name: content_modifier - action: insert - key: modified_if_post - value: true - condition: - op: and - rules: - - field: \$request['method'] - op: eq - value: POST - - - name: content_modifier - action: insert - key: modified_if_get - value: true - condition: - op: and - rules: - - field: \$request['method'] - op: eq - value: GET - - outputs: - - name: stdout - match: '*' -EOL +CONFIG_FILE="$FLB_RUNTIME_SHELL_CONF/processor_conditional.yaml" +OUTPUT_FILE="/tmp/processor_conditional_output.txt" echo "Running Fluent Bit with conditional processor YAML config..." echo "YAML Config:" -cat /tmp/processor_conditional.yaml +cat "$CONFIG_FILE" -# Redirect stdout to a file for analysis -OUTPUT_FILE="/tmp/processor_conditional_output.txt" -$FLB_BIN -c /tmp/processor_conditional.yaml -o stdout > $OUTPUT_FILE 2>&1 & +"$FLB_BIN" -c "$CONFIG_FILE" -o stdout > "$OUTPUT_FILE" 2>&1 & FLB_PID=$! echo "Fluent Bit started with PID: $FLB_PID" -# Wait for output to be generated echo "Waiting for processing to complete..." sleep 5 -# Check for output if [ ! -f "$OUTPUT_FILE" ]; then echo "Output file not found" - kill -15 $FLB_PID || true + kill -15 "$FLB_PID" || true exit 1 fi echo "Output file content:" -cat $OUTPUT_FILE +cat "$OUTPUT_FILE" -# Verify that the GET condition was applied but not the POST condition -GET_FIELD=$(grep -c "modified_if_get" $OUTPUT_FILE) -POST_FIELD=$(grep -c "modified_if_post" $OUTPUT_FILE) +GET_FIELD=$(grep -c "modified_if_get" "$OUTPUT_FILE") +POST_FIELD=$(grep -c "modified_if_post" "$OUTPUT_FILE") -# Clean up -echo "Cleaning up..." -kill -15 $FLB_PID || true -rm -f /tmp/processor_conditional.yaml -rm -f $OUTPUT_FILE +kill -15 "$FLB_PID" || true +rm -f "$OUTPUT_FILE" -# Check results if [ "$GET_FIELD" -gt 0 ] && [ "$POST_FIELD" -eq 0 ]; then echo "Test passed: GET condition applied, POST condition not applied" else @@ -89,70 +42,14 @@ else exit 1 fi -# Create a temporary YAML config file for grep filter used as processor -cat > /tmp/processor_conditional_grep.yaml << EOL -service: - log_level: trace - flush: 1 -pipeline: - inputs: - - name: dummy - dummy: '{"endpoint":"localhost", "value":"something"}' - tag: dummy - processors: - logs: - - name: grep - logical_op: and - regex: - - value something - condition: - op: and - rules: - - field: \$endpoint - op: eq - value: farhost - - name: dummy - dummy: '{"endpoint":"localhost2", "value":"something"}' - tag: dummy - processors: - logs: - - name: grep - logical_op: and - regex: - - value something - condition: - op: and - rules: - - field: \$endpoint - op: eq - value: farhost - - name: dummy - dummy: '{"endpoint":"farhost", "value":"nothing"}' - tag: dummy - processors: - logs: - - name: grep - logical_op: and - regex: - - value something - condition: - op: and - rules: - - field: \$endpoint - op: eq - value: farhost - - outputs: - - name: stdout - match: '*' -EOL +CONFIG_FILE="$FLB_RUNTIME_SHELL_CONF/processor_conditional_grep.yaml" +OUTPUT_FILE="/tmp/processor_conditional_grep_output.txt" echo "Running Fluent Bit with conditional grep processor YAML config..." echo "YAML Config:" -cat /tmp/processor_conditional_grep.yaml +cat "$CONFIG_FILE" -OUTPUT_FILE="/tmp/processor_conditional_grep_output.txt" -$FLB_BIN -c /tmp/processor_conditional_grep.yaml -o stdout > $OUTPUT_FILE 2>&1 & +"$FLB_BIN" -c "$CONFIG_FILE" -o stdout > "$OUTPUT_FILE" 2>&1 & FLB_PID=$! echo "Fluent Bit started with PID: $FLB_PID" @@ -161,21 +58,19 @@ sleep 5 if [ ! -f "$OUTPUT_FILE" ]; then echo "Output file not found" - kill -15 $FLB_PID || true + kill -15 "$FLB_PID" || true exit 1 fi echo "Output file content:" -cat $OUTPUT_FILE +cat "$OUTPUT_FILE" -LOCALHOST_COUNT=$(grep -c -E "\"endpoint\"=>\"localhost\"([^0-9]|$)" $OUTPUT_FILE) -LOCALHOST2_COUNT=$(grep -c "\"endpoint\"=>\"localhost2\"" $OUTPUT_FILE) -FARHOST_COUNT=$(grep -c "\"endpoint\"=>\"farhost\"" $OUTPUT_FILE) +LOCALHOST_COUNT=$(grep -c -E '"endpoint"=>"localhost"([^0-9]|$)' "$OUTPUT_FILE") +LOCALHOST2_COUNT=$(grep -c '"endpoint"=>"localhost2"' "$OUTPUT_FILE") +FARHOST_COUNT=$(grep -c '"endpoint"=>"farhost"' "$OUTPUT_FILE") -echo "Cleaning up..." -kill -15 $FLB_PID || true -rm -f /tmp/processor_conditional_grep.yaml -rm -f $OUTPUT_FILE +kill -15 "$FLB_PID" || true +rm -f "$OUTPUT_FILE" if [ "$LOCALHOST_COUNT" -gt 0 ] && [ "$LOCALHOST2_COUNT" -gt 0 ] && [ "$FARHOST_COUNT" -eq 0 ]; then diff --git a/tests/runtime_shell/processor_invalid.ps1 b/tests/runtime_shell/processor_invalid.ps1 new file mode 100644 index 00000000000..55fbfc422e0 --- /dev/null +++ b/tests/runtime_shell/processor_invalid.ps1 @@ -0,0 +1,30 @@ +. "$PSScriptRoot/common.ps1" + +try { + Assert-RuntimeEnvironment + $configPath = Get-RuntimeConfigPath "processor_invalid.yaml" + + Write-Host "Running Fluent Bit with invalid processor YAML config..." + $output = & $env:FLB_BIN -c $configPath -o stdout 2>&1 | Out-String + $exitCode = $LASTEXITCODE + Write-Host $output + + $invalidProcessor = $output.Contains( + "error creating processor 'non_existent_processor': " + + "plugin doesn't exist or failed to initialize") + $failedInitialization = $output.Contains("error initializing processor") + + if ($exitCode -eq 0) { + throw "Fluent Bit unexpectedly accepted an invalid processor" + } + if (-not ($invalidProcessor -or $failedInitialization)) { + throw "Invalid processor error was not reported" + } + + Write-Host "Test passed: Fluent Bit rejected the invalid processor" + exit 0 +} +catch { + Write-Host "ERROR: $($_.Exception.Message)" + exit 1 +} diff --git a/tests/runtime_shell/processor_invalid.sh b/tests/runtime_shell/processor_invalid.sh index 59a72c7ef32..331e2a921af 100755 --- a/tests/runtime_shell/processor_invalid.sh +++ b/tests/runtime_shell/processor_invalid.sh @@ -1,67 +1,40 @@ #!/bin/sh -# Setup environment if not already set -if [ -z "$FLB_BIN" ]; then - FLB_ROOT=${FLB_ROOT:-$(cd $(dirname $0)/../.. && pwd)} - FLB_BIN=${FLB_BIN:-$FLB_ROOT/build/bin/fluent-bit} -fi +FLB_ROOT=${FLB_ROOT:-$(cd "$(dirname "$0")/../.." && pwd)} +FLB_BIN=${FLB_BIN:-$FLB_ROOT/build/bin/fluent-bit} +FLB_RUNTIME_SHELL_CONF=${FLB_RUNTIME_SHELL_CONF:-$FLB_ROOT/tests/runtime_shell/conf} echo "Using Fluent Bit at: $FLB_BIN" -# Create a temporary YAML config file -cat > /tmp/processor_invalid.yaml << EOL -service: - log_level: debug - flush: 1 -pipeline: - inputs: - - name: dummy - dummy: '{"message": "test message"}' - tag: test - processors: - logs: - - name: non_existent_processor - action: invalid - - outputs: - - name: stdout - match: '*' -EOL +CONFIG_FILE="$FLB_RUNTIME_SHELL_CONF/processor_invalid.yaml" +OUTPUT_FILE="/tmp/processor_invalid_output.txt" echo "Running Fluent Bit with invalid processor YAML config..." echo "YAML Config:" -cat /tmp/processor_invalid.yaml +cat "$CONFIG_FILE" -# Redirect stdout and stderr to a file for analysis -OUTPUT_FILE="/tmp/processor_invalid_output.txt" -$FLB_BIN -c /tmp/processor_invalid.yaml -o stdout > $OUTPUT_FILE 2>&1 - -# Check exit code - we expect it to fail +"$FLB_BIN" -c "$CONFIG_FILE" -o stdout > "$OUTPUT_FILE" 2>&1 EXIT_CODE=$? echo "Fluent Bit exited with code: $EXIT_CODE" -# Show the output echo "Output file content:" -cat $OUTPUT_FILE +cat "$OUTPUT_FILE" -# Check if the output contains an error related to invalid processor -INVALID_PROCESSOR=$(grep -c "error creating processor 'non_existent_processor': plugin doesn't exist or failed to initialize" $OUTPUT_FILE || true) -FAILED_INIT=$(grep -c "error initializing processor" $OUTPUT_FILE || true) +INVALID_PROCESSOR=$(grep -c \ + "error creating processor 'non_existent_processor': plugin doesn't exist or failed to initialize" \ + "$OUTPUT_FILE" || true) +FAILED_INIT=$(grep -c "error initializing processor" "$OUTPUT_FILE" || true) -# Clean up -echo "Cleaning up..." -rm -f /tmp/processor_invalid.yaml -rm -f $OUTPUT_FILE +rm -f "$OUTPUT_FILE" -# Check results - we expect Fluent Bit to fail (non-zero exit code) -# and have an error message about the invalid processor -if [ "$EXIT_CODE" -ne 0 ] && ([ "$INVALID_PROCESSOR" -gt 0 ] || [ "$FAILED_INIT" -gt 0 ]); then +if [ "$EXIT_CODE" -ne 0 ] && \ + { [ "$INVALID_PROCESSOR" -gt 0 ] || [ "$FAILED_INIT" -gt 0 ]; }; then echo "Test passed: Fluent Bit failed with error about invalid processor" exit 0 -else - echo "Test failed: Fluent Bit should fail when an invalid processor is configured" - echo "Exit code: $EXIT_CODE (expected non-zero)" - echo "Invalid processor message count: $INVALID_PROCESSOR (expected > 0)" - echo "Failed init message count: $FAILED_INIT (expected > 0)" - exit 1 -fi \ No newline at end of file +fi + +echo "Test failed: Fluent Bit should fail when an invalid processor is configured" +echo "Exit code: $EXIT_CODE (expected non-zero)" +echo "Invalid processor message count: $INVALID_PROCESSOR (expected > 0)" +echo "Failed init message count: $FAILED_INIT (expected > 0)" +exit 1