Skip to content
Snippets Groups Projects
Commit bb29c724 authored by Craig Tiller's avatar Craig Tiller
Browse files

Fix combiner test

parent 55a82130
No related branches found
No related tags found
No related merge requests found
...@@ -48,23 +48,25 @@ static void test_no_op(void) { ...@@ -48,23 +48,25 @@ static void test_no_op(void) {
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
} }
static void set_bool_to_true(grpc_exec_ctx *exec_ctx, void *value, static void set_event_to_true(grpc_exec_ctx *exec_ctx, void *value,
grpc_error *error) { grpc_error *error) {
*(bool *)value = true; gpr_event_set(value, (void *)1);
} }
static void test_execute_one(void) { static void test_execute_one(void) {
gpr_log(GPR_DEBUG, "test_execute_one"); gpr_log(GPR_DEBUG, "test_execute_one");
grpc_combiner *lock = grpc_combiner_create(); grpc_combiner *lock = grpc_combiner_create();
bool done = false; gpr_event done;
gpr_event_init(&done);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_closure_sched(&exec_ctx, grpc_closure_sched(&exec_ctx,
grpc_closure_create(set_bool_to_true, &done, grpc_closure_create(set_event_to_true, &done,
grpc_combiner_scheduler(lock)), grpc_combiner_scheduler(lock)),
GRPC_ERROR_NONE); GRPC_ERROR_NONE);
grpc_exec_ctx_flush(&exec_ctx); grpc_exec_ctx_flush(&exec_ctx);
GPR_ASSERT(done); GPR_ASSERT(gpr_event_wait(&done, grpc_timeout_seconds_to_deadline(5)) !=
NULL);
GRPC_COMBINER_UNREF(&exec_ctx, lock, "test_execute_one"); GRPC_COMBINER_UNREF(&exec_ctx, lock, "test_execute_one");
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
} }
...@@ -72,6 +74,7 @@ static void test_execute_one(void) { ...@@ -72,6 +74,7 @@ static void test_execute_one(void) {
typedef struct { typedef struct {
size_t ctr; size_t ctr;
grpc_combiner *lock; grpc_combiner *lock;
gpr_event done;
} thd_args; } thd_args;
typedef struct { typedef struct {
...@@ -105,6 +108,10 @@ static void execute_many_loop(void *a) { ...@@ -105,6 +108,10 @@ static void execute_many_loop(void *a) {
// picking it up // picking it up
gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(100)); gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(100));
} }
grpc_closure_sched(&exec_ctx,
grpc_closure_create(set_event_to_true, &args->done,
grpc_combiner_scheduler(args->lock)),
GRPC_ERROR_NONE);
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
} }
...@@ -119,9 +126,12 @@ static void test_execute_many(void) { ...@@ -119,9 +126,12 @@ static void test_execute_many(void) {
gpr_thd_options_set_joinable(&options); gpr_thd_options_set_joinable(&options);
ta[i].ctr = 0; ta[i].ctr = 0;
ta[i].lock = lock; ta[i].lock = lock;
gpr_event_init(&ta[i].done);
GPR_ASSERT(gpr_thd_new(&thds[i], execute_many_loop, &ta[i], &options)); GPR_ASSERT(gpr_thd_new(&thds[i], execute_many_loop, &ta[i], &options));
} }
for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) { for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) {
GPR_ASSERT(gpr_event_wait(&ta[i].done,
gpr_inf_future(GPR_CLOCK_REALTIME)) != NULL);
gpr_thd_join(thds[i]); gpr_thd_join(thds[i]);
} }
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
...@@ -129,15 +139,15 @@ static void test_execute_many(void) { ...@@ -129,15 +139,15 @@ static void test_execute_many(void) {
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
} }
static bool got_in_finally = false; static gpr_event got_in_finally;
static void in_finally(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { static void in_finally(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
got_in_finally = true; gpr_event_set(&got_in_finally, (void *)1);
} }
static void add_finally(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { static void add_finally(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
grpc_closure_sched(exec_ctx, grpc_closure_sched(exec_ctx,
grpc_closure_create(in_finally, NULL, grpc_closure_create(in_finally, arg,
grpc_combiner_finally_scheduler(arg)), grpc_combiner_finally_scheduler(arg)),
GRPC_ERROR_NONE); GRPC_ERROR_NONE);
} }
...@@ -147,12 +157,14 @@ static void test_execute_finally(void) { ...@@ -147,12 +157,14 @@ static void test_execute_finally(void) {
grpc_combiner *lock = grpc_combiner_create(); grpc_combiner *lock = grpc_combiner_create();
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_event_init(&got_in_finally);
grpc_closure_sched( grpc_closure_sched(
&exec_ctx, &exec_ctx,
grpc_closure_create(add_finally, lock, grpc_combiner_scheduler(lock)), grpc_closure_create(add_finally, lock, grpc_combiner_scheduler(lock)),
GRPC_ERROR_NONE); GRPC_ERROR_NONE);
grpc_exec_ctx_flush(&exec_ctx); grpc_exec_ctx_flush(&exec_ctx);
GPR_ASSERT(got_in_finally); GPR_ASSERT(gpr_event_wait(&got_in_finally,
grpc_timeout_seconds_to_deadline(5)) != NULL);
GRPC_COMBINER_UNREF(&exec_ctx, lock, "test_execute_finally"); GRPC_COMBINER_UNREF(&exec_ctx, lock, "test_execute_finally");
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment