From 07504e66f321744ad76254c9be5a655edb943813 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Thu, 25 Oct 2018 12:30:46 -0700 Subject: Don't unnecessarily create exec_ctx --- test/core/iomgr/tcp_client_uv_test.cc | 27 ++++++++++++----------- test/core/iomgr/tcp_server_uv_test.cc | 40 ++++++++++++++++++++--------------- 2 files changed, 38 insertions(+), 29 deletions(-) (limited to 'test/core') diff --git a/test/core/iomgr/tcp_client_uv_test.cc b/test/core/iomgr/tcp_client_uv_test.cc index ffcc7937c7..27f894e3f3 100644 --- a/test/core/iomgr/tcp_client_uv_test.cc +++ b/test/core/iomgr/tcp_client_uv_test.cc @@ -129,6 +129,7 @@ void test_succeeds(void) { uv_close((uv_handle_t*)svr_handle, close_cb); gpr_mu_unlock(g_mu); + grpc_core::ExecCtx::Get()->Flush(); } void test_fails(void) { @@ -178,6 +179,7 @@ void test_fails(void) { } gpr_mu_unlock(g_mu); + grpc_core::ExecCtx::Get()->Flush(); } static void destroy_pollset(void* p, grpc_error* error) { @@ -186,21 +188,22 @@ static void destroy_pollset(void* p, grpc_error* error) { int main(int argc, char** argv) { grpc_closure destroyed; - grpc_core::ExecCtx exec_ctx; grpc_test_init(argc, argv); grpc_init(); - g_pollset = static_cast(gpr_malloc(grpc_pollset_size())); - grpc_pollset_init(g_pollset, &g_mu); - - test_succeeds(); - gpr_log(GPR_ERROR, "End of first test"); - test_fails(); - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(g_pollset, &destroyed); - + { + grpc_core::ExecCtx exec_ctx; + g_pollset = static_cast(gpr_malloc(grpc_pollset_size())); + grpc_pollset_init(g_pollset, &g_mu); + + test_succeeds(); + gpr_log(GPR_ERROR, "End of first test"); + test_fails(); + GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(g_pollset, &destroyed); + gpr_free(g_pollset); + } grpc_shutdown(); - gpr_free(g_pollset); return 0; } diff --git a/test/core/iomgr/tcp_server_uv_test.cc b/test/core/iomgr/tcp_server_uv_test.cc index 35d62b51b7..e99fa79bfd 100644 --- a/test/core/iomgr/tcp_server_uv_test.cc +++ b/test/core/iomgr/tcp_server_uv_test.cc @@ -119,6 +119,7 @@ static void test_no_op(void) { grpc_tcp_server* s; GPR_ASSERT(GRPC_ERROR_NONE == grpc_tcp_server_create(NULL, NULL, &s)); grpc_tcp_server_unref(s); + grpc_core::ExecCtx::Get()->Flush(); } static void test_no_op_with_start(void) { @@ -128,6 +129,7 @@ static void test_no_op_with_start(void) { LOG_TEST("test_no_op_with_start"); grpc_tcp_server_start(s, NULL, 0, on_connect, NULL); grpc_tcp_server_unref(s); + grpc_core::ExecCtx::Get()->Flush(); } static void test_no_op_with_port(void) { @@ -147,6 +149,7 @@ static void test_no_op_with_port(void) { port > 0); grpc_tcp_server_unref(s); + grpc_core::ExecCtx::Get()->Flush(); } static void test_no_op_with_port_and_start(void) { @@ -168,6 +171,7 @@ static void test_no_op_with_port_and_start(void) { grpc_tcp_server_start(s, NULL, 0, on_connect, NULL); grpc_tcp_server_unref(s); + grpc_core::ExecCtx::Get()->Flush(); } static void connect_cb(uv_connect_t* req, int status) { @@ -273,7 +277,7 @@ static void test_connect(unsigned n) { GPR_ASSERT(weak_ref.server != NULL); grpc_tcp_server_unref(s); - + grpc_core::ExecCtx::Get()->Flush(); /* Weak ref lost. */ GPR_ASSERT(weak_ref.server == NULL); } @@ -284,25 +288,27 @@ static void destroy_pollset(void* p, grpc_error* error) { int main(int argc, char** argv) { grpc_closure destroyed; - grpc_core::ExecCtx exec_ctx; grpc_test_init(argc, argv); grpc_init(); - g_pollset = static_cast(gpr_malloc(grpc_pollset_size())); - grpc_pollset_init(g_pollset, &g_mu); - - test_no_op(); - test_no_op_with_start(); - test_no_op_with_port(); - test_no_op_with_port_and_start(); - test_connect(1); - test_connect(10); - - GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(g_pollset, &destroyed); - + { + grpc_core::ExecCtx exec_ctx; + g_pollset = static_cast(gpr_malloc(grpc_pollset_size())); + grpc_pollset_init(g_pollset, &g_mu); + + test_no_op(); + test_no_op_with_start(); + test_no_op_with_port(); + test_no_op_with_port_and_start(); + test_connect(1); + test_connect(10); + + GRPC_CLOSURE_INIT(&destroyed, destroy_pollset, g_pollset, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(g_pollset, &destroyed); + + gpr_free(g_pollset); + } grpc_shutdown(); - gpr_free(g_pollset); return 0; } -- cgit v1.2.3