Skip to content

Commit a32e4ab

Browse files
committed
tests: cover parent stack callback dispatch
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
1 parent eb5ba27 commit a32e4ab

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

tests/internal/network.c

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <fluent-bit/flb_network.h>
88
#include <fluent-bit/flb_socket.h>
99
#include <fluent-bit/flb_time.h>
10+
#include <fluent-bit/flb_coro.h>
11+
#include <fluent-bit/flb_downstream.h>
1012

1113
#include <time.h>
1214
#include "flb_tests_internal.h"
@@ -19,6 +21,43 @@
1921
#define TEST_EV_CLIENT MK_EVENT_NOTIFICATION
2022
#define TEST_EV_SERVER MK_EVENT_CUSTOM
2123

24+
struct parent_callback_context {
25+
struct flb_connection connection;
26+
struct flb_coro *parent_coro;
27+
int callback_on_parent;
28+
int callback_result;
29+
int coroutine_done;
30+
};
31+
32+
static int parent_callback(void *data)
33+
{
34+
struct parent_callback_context *context;
35+
36+
context = data;
37+
context->callback_on_parent = flb_coro_get() == context->parent_coro;
38+
39+
return 73;
40+
}
41+
42+
static void parent_callback_coro(void)
43+
{
44+
struct flb_coro *coro;
45+
struct parent_callback_context *context;
46+
47+
coro = flb_coro_get();
48+
context = coro->data;
49+
50+
context->callback_result = flb_downstream_conn_event_call_parent(
51+
&context->connection,
52+
parent_callback,
53+
context);
54+
context->coroutine_done = FLB_TRUE;
55+
56+
while (FLB_TRUE) {
57+
flb_coro_yield(coro, FLB_FALSE);
58+
}
59+
}
60+
2261
static int socket_check_ok(flb_sockfd_t fd)
2362
{
2463
int ret;
@@ -201,10 +240,55 @@ void test_accept_empty_nonblocking_listener()
201240
flb_socket_close(fd_server);
202241
}
203242

243+
void test_downstream_event_callback_runs_on_parent_stack()
244+
{
245+
size_t stack_size;
246+
struct flb_coro *coro;
247+
struct parent_callback_context context;
248+
249+
memset(&context, 0, sizeof(context));
250+
251+
flb_coro_thread_init();
252+
253+
coro = flb_coro_create(&context);
254+
if (!TEST_CHECK(coro != NULL)) {
255+
return;
256+
}
257+
258+
coro->caller = co_active();
259+
coro->callee = co_create(test_env_config->coro_stack_size,
260+
parent_callback_coro,
261+
&stack_size);
262+
if (!TEST_CHECK(coro->callee != NULL)) {
263+
flb_coro_destroy(coro);
264+
return;
265+
}
266+
267+
#ifdef FLB_HAVE_VALGRIND
268+
coro->valgrind_stack_id = VALGRIND_STACK_REGISTER(
269+
coro->callee,
270+
((char *) coro->callee) + stack_size);
271+
#endif
272+
273+
context.parent_coro = flb_coro_get();
274+
context.connection.event_coroutine = coro;
275+
276+
flb_downstream_conn_event_resume(&context.connection);
277+
278+
TEST_CHECK(context.callback_on_parent == FLB_TRUE);
279+
TEST_CHECK(context.callback_result == 73);
280+
TEST_CHECK(context.coroutine_done == FLB_TRUE);
281+
282+
context.connection.event_coroutine = NULL;
283+
flb_coro_destroy(coro);
284+
}
285+
204286
TEST_LIST = {
205287
{ "ipv4_client_server", test_ipv4_client_server},
206288
{ "ipv6_client_server", test_ipv6_client_server},
207289
{ "ipv6_bracketed_listen", test_ipv6_bracketed_listen},
208290
{ "accept_empty_nonblocking_listener", test_accept_empty_nonblocking_listener},
291+
{ "downstream_event_callback_runs_on_parent_stack",
292+
test_downstream_event_callback_runs_on_parent_stack },
209293
{ 0 }
210294
};

0 commit comments

Comments
 (0)