Skip to content

Commit d411694

Browse files
committed
tests: core_routes: Handle limit of rlimit's soft limit
By default, macOS's soft limit of rlimit is up to 256. SO, just eating up 256 of output instances could cause too many open errors. Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
1 parent 405fed0 commit d411694

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

tests/runtime/core_routes.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
#include <fluent-bit.h>
44
#include <fluent-bit/flb_time.h>
5+
#ifdef FLB_SYSTEM_MACOS
6+
#include <stdio.h>
7+
#include <string.h>
8+
#include <errno.h>
9+
#include <sys/resource.h>
10+
#endif
511
#include "flb_tests_runtime.h"
612

713
pthread_mutex_t result_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -44,7 +50,11 @@ void flb_test_basic_functionality_test(void)
4450
int result;
4551
size_t index;
4652
flb_ctx_t *ctx;
47-
53+
size_t olimit = 257;
54+
#ifdef FLB_SYSTEM_MACOS
55+
struct rlimit rlim;
56+
int rlimit_rc;
57+
#endif
4858
cb_context = 0;
4959

5060
/* Prepare output callback with expected result */
@@ -56,9 +66,20 @@ void flb_test_basic_functionality_test(void)
5666
input_instance = flb_input(ctx, (char *) "lib", NULL);
5767
TEST_CHECK(input_instance >= 0);
5868

69+
#ifdef FLB_SYSTEM_MACOS
70+
rlimit_rc = getrlimit(RLIMIT_NOFILE, &rlim);
71+
TEST_CHECK(rlimit_rc == 0);
72+
if (rlimit_rc == 0 && rlim.rlim_cur < 257) {
73+
olimit = (size_t) (rlim.rlim_cur / 2.5);
74+
if (olimit == 0) {
75+
olimit = 1;
76+
}
77+
}
78+
#endif
79+
5980
flb_input_set(ctx, input_instance, "tag", "test", NULL);
6081

61-
for (index = 0 ; index < 257 ; index++) {
82+
for (index = 0 ; index < olimit ; index++) {
6283
output_instances[index] = flb_output(ctx, (char *) "lib", &cb_data);
6384
TEST_CHECK(output_instances[index] >= 0);
6485

@@ -82,14 +103,14 @@ void flb_test_basic_functionality_test(void)
82103
delivery_counter = get_output_num();
83104

84105
for (index = 0 ;
85-
index < 100 && delivery_counter < 257 ;
106+
index < 100 && delivery_counter < olimit ;
86107
index++) {
87108
flb_time_msleep(100);
88109

89110
delivery_counter = get_output_num();
90111
}
91112

92-
TEST_CHECK(delivery_counter == 257);
113+
TEST_CHECK(delivery_counter == olimit);
93114

94115
flb_stop(ctx);
95116
flb_destroy(ctx);

0 commit comments

Comments
 (0)