aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/iomgr/endpoint_tests.cc
diff options
context:
space:
mode:
authorGravatar Yash Tibrewal <yashkt@google.com>2017-12-06 09:05:05 -0800
committerGravatar GitHub <noreply@github.com>2017-12-06 09:05:05 -0800
commitad4d2dde0052efbbf49d64b0843c45f0381cfeb3 (patch)
tree6a657f8c6179d873b34505cdc24bce9462ca68eb /test/core/iomgr/endpoint_tests.cc
parenta3df36cc2505a89c2f481eea4a66a87b3002844a (diff)
Revert "All instances of exec_ctx being passed around in src/core removed"
Diffstat (limited to 'test/core/iomgr/endpoint_tests.cc')
-rw-r--r--test/core/iomgr/endpoint_tests.cc99
1 files changed, 57 insertions, 42 deletions
diff --git a/test/core/iomgr/endpoint_tests.cc b/test/core/iomgr/endpoint_tests.cc
index 8ccae52067..026e34105d 100644
--- a/test/core/iomgr/endpoint_tests.cc
+++ b/test/core/iomgr/endpoint_tests.cc
@@ -115,7 +115,8 @@ struct read_and_write_test_state {
grpc_closure done_write;
};
-static void read_and_write_test_read_handler(void* data, grpc_error* error) {
+static void read_and_write_test_read_handler(grpc_exec_ctx* exec_ctx,
+ void* data, grpc_error* error) {
struct read_and_write_test_state* state =
(struct read_and_write_test_state*)data;
@@ -125,14 +126,17 @@ static void read_and_write_test_read_handler(void* data, grpc_error* error) {
gpr_log(GPR_INFO, "Read handler done");
gpr_mu_lock(g_mu);
state->read_done = 1 + (error == GRPC_ERROR_NONE);
- GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr));
+ GRPC_LOG_IF_ERROR("pollset_kick",
+ grpc_pollset_kick(exec_ctx, g_pollset, nullptr));
gpr_mu_unlock(g_mu);
} else if (error == GRPC_ERROR_NONE) {
- grpc_endpoint_read(state->read_ep, &state->incoming, &state->done_read);
+ grpc_endpoint_read(exec_ctx, state->read_ep, &state->incoming,
+ &state->done_read);
}
}
-static void read_and_write_test_write_handler(void* data, grpc_error* error) {
+static void read_and_write_test_write_handler(grpc_exec_ctx* exec_ctx,
+ void* data, grpc_error* error) {
struct read_and_write_test_state* state =
(struct read_and_write_test_state*)data;
grpc_slice* slices = nullptr;
@@ -149,7 +153,7 @@ static void read_and_write_test_write_handler(void* data, grpc_error* error) {
&state->current_write_data);
grpc_slice_buffer_reset_and_unref(&state->outgoing);
grpc_slice_buffer_addn(&state->outgoing, slices, nslices);
- grpc_endpoint_write(state->write_ep, &state->outgoing,
+ grpc_endpoint_write(exec_ctx, state->write_ep, &state->outgoing,
&state->done_write);
gpr_free(slices);
return;
@@ -159,7 +163,8 @@ static void read_and_write_test_write_handler(void* data, grpc_error* error) {
gpr_log(GPR_INFO, "Write handler done");
gpr_mu_lock(g_mu);
state->write_done = 1 + (error == GRPC_ERROR_NONE);
- GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, nullptr));
+ GRPC_LOG_IF_ERROR("pollset_kick",
+ grpc_pollset_kick(exec_ctx, g_pollset, nullptr));
gpr_mu_unlock(g_mu);
}
@@ -173,7 +178,7 @@ static void read_and_write_test(grpc_endpoint_test_config config,
struct read_and_write_test_state state;
grpc_endpoint_test_fixture f =
begin_test(config, "read_and_write_test", slice_size);
- grpc_core::ExecCtx exec_ctx;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_millis deadline =
grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(20));
gpr_log(GPR_DEBUG,
@@ -212,57 +217,66 @@ static void read_and_write_test(grpc_endpoint_test_config config,
for the first iteration as for later iterations. It does the right thing
even when bytes_written is unsigned. */
state.bytes_written -= state.current_write_size;
- read_and_write_test_write_handler(&state, GRPC_ERROR_NONE);
- grpc_core::ExecCtx::Get()->Flush();
+ read_and_write_test_write_handler(&exec_ctx, &state, GRPC_ERROR_NONE);
+ grpc_exec_ctx_flush(&exec_ctx);
- grpc_endpoint_read(state.read_ep, &state.incoming, &state.done_read);
+ grpc_endpoint_read(&exec_ctx, state.read_ep, &state.incoming,
+ &state.done_read);
if (shutdown) {
gpr_log(GPR_DEBUG, "shutdown read");
grpc_endpoint_shutdown(
- state.read_ep, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown"));
+ &exec_ctx, state.read_ep,
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown"));
gpr_log(GPR_DEBUG, "shutdown write");
grpc_endpoint_shutdown(
- state.write_ep, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown"));
+ &exec_ctx, state.write_ep,
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown"));
}
- grpc_core::ExecCtx::Get()->Flush();
+ grpc_exec_ctx_flush(&exec_ctx);
gpr_mu_lock(g_mu);
while (!state.read_done || !state.write_done) {
grpc_pollset_worker* worker = nullptr;
- GPR_ASSERT(grpc_core::ExecCtx::Get()->Now() < deadline);
+ GPR_ASSERT(grpc_exec_ctx_now(&exec_ctx) < deadline);
GPR_ASSERT(GRPC_LOG_IF_ERROR(
- "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline)));
+ "pollset_work",
+ grpc_pollset_work(&exec_ctx, g_pollset, &worker, deadline)));
}
gpr_mu_unlock(g_mu);
- grpc_core::ExecCtx::Get()->Flush();
+ grpc_exec_ctx_flush(&exec_ctx);
end_test(config);
- grpc_slice_buffer_destroy_internal(&state.outgoing);
- grpc_slice_buffer_destroy_internal(&state.incoming);
- grpc_endpoint_destroy(state.read_ep);
- grpc_endpoint_destroy(state.write_ep);
+ grpc_slice_buffer_destroy_internal(&exec_ctx, &state.outgoing);
+ grpc_slice_buffer_destroy_internal(&exec_ctx, &state.incoming);
+ grpc_endpoint_destroy(&exec_ctx, state.read_ep);
+ grpc_endpoint_destroy(&exec_ctx, state.write_ep);
+ grpc_exec_ctx_finish(&exec_ctx);
}
-static void inc_on_failure(void* arg, grpc_error* error) {
+static void inc_on_failure(grpc_exec_ctx* exec_ctx, void* arg,
+ grpc_error* error) {
gpr_mu_lock(g_mu);
*(int*)arg += (error != GRPC_ERROR_NONE);
- GPR_ASSERT(GRPC_LOG_IF_ERROR("kick", grpc_pollset_kick(g_pollset, nullptr)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR(
+ "kick", grpc_pollset_kick(exec_ctx, g_pollset, nullptr)));
gpr_mu_unlock(g_mu);
}
-static void wait_for_fail_count(int* fail_count, int want_fail_count) {
- grpc_core::ExecCtx::Get()->Flush();
+static void wait_for_fail_count(grpc_exec_ctx* exec_ctx, int* fail_count,
+ int want_fail_count) {
+ grpc_exec_ctx_flush(exec_ctx);
gpr_mu_lock(g_mu);
grpc_millis deadline =
grpc_timespec_to_millis_round_up(grpc_timeout_seconds_to_deadline(10));
- while (grpc_core::ExecCtx::Get()->Now() < deadline &&
+ while (grpc_exec_ctx_now(exec_ctx) < deadline &&
*fail_count < want_fail_count) {
grpc_pollset_worker* worker = nullptr;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
- "pollset_work", grpc_pollset_work(g_pollset, &worker, deadline)));
+ "pollset_work",
+ grpc_pollset_work(exec_ctx, g_pollset, &worker, deadline)));
gpr_mu_unlock(g_mu);
- grpc_core::ExecCtx::Get()->Flush();
+ grpc_exec_ctx_flush(exec_ctx);
gpr_mu_lock(g_mu);
}
GPR_ASSERT(*fail_count == want_fail_count);
@@ -277,32 +291,33 @@ static void multiple_shutdown_test(grpc_endpoint_test_config config) {
grpc_slice_buffer slice_buffer;
grpc_slice_buffer_init(&slice_buffer);
- grpc_core::ExecCtx exec_ctx;
- grpc_endpoint_add_to_pollset(f.client_ep, g_pollset);
- grpc_endpoint_read(f.client_ep, &slice_buffer,
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_endpoint_add_to_pollset(&exec_ctx, f.client_ep, g_pollset);
+ grpc_endpoint_read(&exec_ctx, f.client_ep, &slice_buffer,
GRPC_CLOSURE_CREATE(inc_on_failure, &fail_count,
grpc_schedule_on_exec_ctx));
- wait_for_fail_count(&fail_count, 0);
- grpc_endpoint_shutdown(f.client_ep,
+ wait_for_fail_count(&exec_ctx, &fail_count, 0);
+ grpc_endpoint_shutdown(&exec_ctx, f.client_ep,
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown"));
- wait_for_fail_count(&fail_count, 1);
- grpc_endpoint_read(f.client_ep, &slice_buffer,
+ wait_for_fail_count(&exec_ctx, &fail_count, 1);
+ grpc_endpoint_read(&exec_ctx, f.client_ep, &slice_buffer,
GRPC_CLOSURE_CREATE(inc_on_failure, &fail_count,
grpc_schedule_on_exec_ctx));
- wait_for_fail_count(&fail_count, 2);
+ wait_for_fail_count(&exec_ctx, &fail_count, 2);
grpc_slice_buffer_add(&slice_buffer, grpc_slice_from_copied_string("a"));
- grpc_endpoint_write(f.client_ep, &slice_buffer,
+ grpc_endpoint_write(&exec_ctx, f.client_ep, &slice_buffer,
GRPC_CLOSURE_CREATE(inc_on_failure, &fail_count,
grpc_schedule_on_exec_ctx));
- wait_for_fail_count(&fail_count, 3);
- grpc_endpoint_shutdown(f.client_ep,
+ wait_for_fail_count(&exec_ctx, &fail_count, 3);
+ grpc_endpoint_shutdown(&exec_ctx, f.client_ep,
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown"));
- wait_for_fail_count(&fail_count, 3);
+ wait_for_fail_count(&exec_ctx, &fail_count, 3);
- grpc_slice_buffer_destroy_internal(&slice_buffer);
+ grpc_slice_buffer_destroy_internal(&exec_ctx, &slice_buffer);
- grpc_endpoint_destroy(f.client_ep);
- grpc_endpoint_destroy(f.server_ep);
+ grpc_endpoint_destroy(&exec_ctx, f.client_ep);
+ grpc_endpoint_destroy(&exec_ctx, f.server_ep);
+ grpc_exec_ctx_finish(&exec_ctx);
}
void grpc_endpoint_tests(grpc_endpoint_test_config config,