aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/iomgr
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2017-05-24 14:02:36 -0700
committerGravatar Craig Tiller <ctiller@google.com>2017-05-24 14:02:36 -0700
commitbb29c724dde15cbcc1d0496918e4bee43886045f (patch)
treedcb24dfc3bda30a1c0c15959dd33a6c23b7ce6fc /test/core/iomgr
parent55a8213041c88be5385289a6f340f10e49f18cc5 (diff)
Fix combiner test
Diffstat (limited to 'test/core/iomgr')
-rw-r--r--test/core/iomgr/combiner_test.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/test/core/iomgr/combiner_test.c b/test/core/iomgr/combiner_test.c
index 92935ca017..beb5c47623 100644
--- a/test/core/iomgr/combiner_test.c
+++ b/test/core/iomgr/combiner_test.c
@@ -48,23 +48,25 @@ static void test_no_op(void) {
grpc_exec_ctx_finish(&exec_ctx);
}
-static void set_bool_to_true(grpc_exec_ctx *exec_ctx, void *value,
- grpc_error *error) {
- *(bool *)value = true;
+static void set_event_to_true(grpc_exec_ctx *exec_ctx, void *value,
+ grpc_error *error) {
+ gpr_event_set(value, (void *)1);
}
static void test_execute_one(void) {
gpr_log(GPR_DEBUG, "test_execute_one");
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_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_ERROR_NONE);
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_exec_ctx_finish(&exec_ctx);
}
@@ -72,6 +74,7 @@ static void test_execute_one(void) {
typedef struct {
size_t ctr;
grpc_combiner *lock;
+ gpr_event done;
} thd_args;
typedef struct {
@@ -105,6 +108,10 @@ static void execute_many_loop(void *a) {
// picking it up
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);
}
@@ -119,9 +126,12 @@ static void test_execute_many(void) {
gpr_thd_options_set_joinable(&options);
ta[i].ctr = 0;
ta[i].lock = lock;
+ gpr_event_init(&ta[i].done);
GPR_ASSERT(gpr_thd_new(&thds[i], execute_many_loop, &ta[i], &options));
}
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]);
}
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
@@ -129,15 +139,15 @@ static void test_execute_many(void) {
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) {
- 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) {
grpc_closure_sched(exec_ctx,
- grpc_closure_create(in_finally, NULL,
+ grpc_closure_create(in_finally, arg,
grpc_combiner_finally_scheduler(arg)),
GRPC_ERROR_NONE);
}
@@ -147,12 +157,14 @@ static void test_execute_finally(void) {
grpc_combiner *lock = grpc_combiner_create();
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ gpr_event_init(&got_in_finally);
grpc_closure_sched(
&exec_ctx,
grpc_closure_create(add_finally, lock, grpc_combiner_scheduler(lock)),
GRPC_ERROR_NONE);
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_exec_ctx_finish(&exec_ctx);
}