test: runtime: in_fluentbit_metric: macos: Wait for enough time to
obtain the testing result
@@ -61,6 +61,35 @@ struct str_list {
char **lists;
};
+void wait_with_timeout(uint32_t timeout_ms, int *output_num)
+{
+ struct flb_time start_time;
+ struct flb_time end_time;
+ struct flb_time diff_time;
+ uint64_t elapsed_time_flb = 0;
+
+ flb_time_get(&start_time);
+
+ while (true) {
+ *output_num = get_output_num();
+
+ if (*output_num > 0) {
+ break;
+ }
+
+ flb_time_msleep(100);
+ 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) {
+ flb_warn("[timeout] elapsed_time: %ld", elapsed_time_flb);
+ // Reached timeout.
+ break;
+ }
+ }
+}
+
/* Callback to check expected results */
static int cb_check_json_str_list(void *record, size_t size, void *data)
{
@@ -179,9 +208,8 @@ static void test_basic(void)
TEST_CHECK(ret == 0);
/* waiting to flush */
- flb_time_msleep(1500);
+ wait_with_timeout(3000, &num);
- num = get_output_num();
if (!TEST_CHECK(num > 0)) {
TEST_MSG("no outputs");
}
