|
|
|
@ -100,7 +100,8 @@ static void test_shutdown_then_next_polling(void) { |
|
|
|
|
|
|
|
|
|
cc = grpc_completion_queue_create(); |
|
|
|
|
grpc_completion_queue_shutdown(cc); |
|
|
|
|
GPR_ASSERT(grpc_completion_queue_next(cc, gpr_inf_past).type == GRPC_QUEUE_SHUTDOWN); |
|
|
|
|
GPR_ASSERT(grpc_completion_queue_next(cc, gpr_inf_past).type == |
|
|
|
|
GRPC_QUEUE_SHUTDOWN); |
|
|
|
|
grpc_completion_queue_destroy(cc); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -110,7 +111,8 @@ static void test_shutdown_then_next_with_timeout(void) { |
|
|
|
|
|
|
|
|
|
cc = grpc_completion_queue_create(); |
|
|
|
|
grpc_completion_queue_shutdown(cc); |
|
|
|
|
GPR_ASSERT(grpc_completion_queue_next(cc, gpr_inf_future).type == GRPC_QUEUE_SHUTDOWN); |
|
|
|
|
GPR_ASSERT(grpc_completion_queue_next(cc, gpr_inf_future).type == |
|
|
|
|
GRPC_QUEUE_SHUTDOWN); |
|
|
|
|
grpc_completion_queue_destroy(cc); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -177,7 +179,7 @@ static void producer_thread(void *arg) { |
|
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
gpr_log(GPR_INFO, "producer %d started", opt->id); |
|
|
|
|
gpr_event_set(&opt->on_started, (void *)(gpr_intptr) 1); |
|
|
|
|
gpr_event_set(&opt->on_started, (void *)(gpr_intptr)1); |
|
|
|
|
GPR_ASSERT(gpr_event_wait(opt->phase1, ten_seconds_time())); |
|
|
|
|
|
|
|
|
|
gpr_log(GPR_INFO, "producer %d phase 1", opt->id); |
|
|
|
@ -186,7 +188,7 @@ static void producer_thread(void *arg) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gpr_log(GPR_INFO, "producer %d phase 1 done", opt->id); |
|
|
|
|
gpr_event_set(&opt->on_phase1_done, (void *)(gpr_intptr) 1); |
|
|
|
|
gpr_event_set(&opt->on_phase1_done, (void *)(gpr_intptr)1); |
|
|
|
|
GPR_ASSERT(gpr_event_wait(opt->phase2, ten_seconds_time())); |
|
|
|
|
|
|
|
|
|
gpr_log(GPR_INFO, "producer %d phase 2", opt->id); |
|
|
|
@ -196,7 +198,7 @@ static void producer_thread(void *arg) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gpr_log(GPR_INFO, "producer %d phase 2 done", opt->id); |
|
|
|
|
gpr_event_set(&opt->on_finished, (void *)(gpr_intptr) 1); |
|
|
|
|
gpr_event_set(&opt->on_finished, (void *)(gpr_intptr)1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void consumer_thread(void *arg) { |
|
|
|
@ -204,13 +206,13 @@ static void consumer_thread(void *arg) { |
|
|
|
|
grpc_event ev; |
|
|
|
|
|
|
|
|
|
gpr_log(GPR_INFO, "consumer %d started", opt->id); |
|
|
|
|
gpr_event_set(&opt->on_started, (void *)(gpr_intptr) 1); |
|
|
|
|
gpr_event_set(&opt->on_started, (void *)(gpr_intptr)1); |
|
|
|
|
GPR_ASSERT(gpr_event_wait(opt->phase1, ten_seconds_time())); |
|
|
|
|
|
|
|
|
|
gpr_log(GPR_INFO, "consumer %d phase 1", opt->id); |
|
|
|
|
|
|
|
|
|
gpr_log(GPR_INFO, "consumer %d phase 1 done", opt->id); |
|
|
|
|
gpr_event_set(&opt->on_phase1_done, (void *)(gpr_intptr) 1); |
|
|
|
|
gpr_event_set(&opt->on_phase1_done, (void *)(gpr_intptr)1); |
|
|
|
|
GPR_ASSERT(gpr_event_wait(opt->phase2, ten_seconds_time())); |
|
|
|
|
|
|
|
|
|
gpr_log(GPR_INFO, "consumer %d phase 2", opt->id); |
|
|
|
@ -223,7 +225,7 @@ static void consumer_thread(void *arg) { |
|
|
|
|
break; |
|
|
|
|
case GRPC_QUEUE_SHUTDOWN: |
|
|
|
|
gpr_log(GPR_INFO, "consumer %d phase 2 done", opt->id); |
|
|
|
|
gpr_event_set(&opt->on_finished, (void *)(gpr_intptr) 1); |
|
|
|
|
gpr_event_set(&opt->on_finished, (void *)(gpr_intptr)1); |
|
|
|
|
return; |
|
|
|
|
case GRPC_QUEUE_TIMEOUT: |
|
|
|
|
gpr_log(GPR_ERROR, "Invalid timeout received"); |
|
|
|
@ -242,8 +244,8 @@ static void test_threading(int producers, int consumers) { |
|
|
|
|
int total_consumed = 0; |
|
|
|
|
static int optid = 101; |
|
|
|
|
|
|
|
|
|
gpr_log(GPR_INFO, "%s: %d producers, %d consumers", "test_threading", producers, |
|
|
|
|
consumers); |
|
|
|
|
gpr_log(GPR_INFO, "%s: %d producers, %d consumers", "test_threading", |
|
|
|
|
producers, consumers); |
|
|
|
|
|
|
|
|
|
/* start all threads: they will wait for phase1 */ |
|
|
|
|
for (i = 0; i < producers + consumers; i++) { |
|
|
|
@ -265,7 +267,7 @@ static void test_threading(int producers, int consumers) { |
|
|
|
|
/* start phase1: producers will pre-declare all operations they will
|
|
|
|
|
complete */ |
|
|
|
|
gpr_log(GPR_INFO, "start phase 1"); |
|
|
|
|
gpr_event_set(&phase1, (void *)(gpr_intptr) 1); |
|
|
|
|
gpr_event_set(&phase1, (void *)(gpr_intptr)1); |
|
|
|
|
|
|
|
|
|
gpr_log(GPR_INFO, "wait phase 1"); |
|
|
|
|
for (i = 0; i < producers + consumers; i++) { |
|
|
|
@ -275,7 +277,7 @@ static void test_threading(int producers, int consumers) { |
|
|
|
|
|
|
|
|
|
/* start phase2: operations will complete, and consumers will consume them */ |
|
|
|
|
gpr_log(GPR_INFO, "start phase 2"); |
|
|
|
|
gpr_event_set(&phase2, (void *)(gpr_intptr) 1); |
|
|
|
|
gpr_event_set(&phase2, (void *)(gpr_intptr)1); |
|
|
|
|
|
|
|
|
|
/* in parallel, we shutdown the completion channel - all events should still
|
|
|
|
|
be consumed */ |
|
|
|
|