From 81fc8c9c336fab7a71b448f748a32d680301277c Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Tue, 28 Nov 2017 13:23:36 -0800 Subject: Fix tests to call grpc_init and grpc_shutdown before using exec_ctx --- test/core/http/format_request_test.cc | 2 + test/core/http/httpcli_test.cc | 107 +++++++++++++++++----------------- test/core/http/httpscli_test.cc | 11 ++-- test/core/http/parser_test.cc | 3 + 4 files changed, 65 insertions(+), 58 deletions(-) (limited to 'test/core/http') diff --git a/test/core/http/format_request_test.cc b/test/core/http/format_request_test.cc index 684738a997..353e138b2a 100644 --- a/test/core/http/format_request_test.cc +++ b/test/core/http/format_request_test.cc @@ -139,11 +139,13 @@ static void test_format_post_request_content_type_override(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); + grpc_init(); test_format_get_request(); test_format_post_request(); test_format_post_request_no_body(); test_format_post_request_content_type_override(); + grpc_shutdown(); return 0; } diff --git a/test/core/http/httpcli_test.cc b/test/core/http/httpcli_test.cc index d354ad3570..ed5c03558f 100644 --- a/test/core/http/httpcli_test.cc +++ b/test/core/http/httpcli_test.cc @@ -141,62 +141,63 @@ static void destroy_pops(void* p, grpc_error* error) { } int main(int argc, char** argv) { - grpc_closure destroyed; - grpc_core::ExecCtx _local_exec_ctx; gpr_subprocess* server; - char* me = argv[0]; - char* lslash = strrchr(me, '/'); - char* args[4]; - int port = grpc_pick_unused_port_or_die(); - int arg_shift = 0; - /* figure out where we are */ - char* root; - if (lslash) { - root = static_cast(gpr_malloc((size_t)(lslash - me + 1))); - memcpy(root, me, (size_t)(lslash - me)); - root[lslash - me] = 0; - } else { - root = gpr_strdup("."); - } - - GPR_ASSERT(argc <= 2); - if (argc == 2) { - args[0] = gpr_strdup(argv[1]); - } else { - arg_shift = 1; - gpr_asprintf(&args[0], "%s/../../tools/distrib/python_wrapper.sh", root); - gpr_asprintf(&args[1], "%s/../../test/core/http/test_server.py", root); - } - - /* start the server */ - args[1 + arg_shift] = const_cast("--port"); - gpr_asprintf(&args[2 + arg_shift], "%d", port); - server = gpr_subprocess_create(3 + arg_shift, (const char**)args); - GPR_ASSERT(server); - gpr_free(args[0]); - if (arg_shift) gpr_free(args[1]); - gpr_free(args[2 + arg_shift]); - gpr_free(root); - - gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_seconds(5, GPR_TIMESPAN))); - grpc_test_init(argc, argv); grpc_init(); - grpc_httpcli_context_init(&g_context); - grpc_pollset* pollset = - static_cast(gpr_zalloc(grpc_pollset_size())); - grpc_pollset_init(pollset, &g_mu); - g_pops = grpc_polling_entity_create_from_pollset(pollset); - - test_get(port); - test_post(port); - - grpc_httpcli_context_destroy(&g_context); - GRPC_CLOSURE_INIT(&destroyed, destroy_pops, &g_pops, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(grpc_polling_entity_pollset(&g_pops), &destroyed); - + { + grpc_closure destroyed; + grpc_core::ExecCtx _local_exec_ctx; + char* me = argv[0]; + char* lslash = strrchr(me, '/'); + char* args[4]; + int port = grpc_pick_unused_port_or_die(); + int arg_shift = 0; + /* figure out where we are */ + char* root; + if (lslash) { + root = static_cast(gpr_malloc((size_t)(lslash - me + 1))); + memcpy(root, me, (size_t)(lslash - me)); + root[lslash - me] = 0; + } else { + root = gpr_strdup("."); + } + + GPR_ASSERT(argc <= 2); + if (argc == 2) { + args[0] = gpr_strdup(argv[1]); + } else { + arg_shift = 1; + gpr_asprintf(&args[0], "%s/../../tools/distrib/python_wrapper.sh", root); + gpr_asprintf(&args[1], "%s/../../test/core/http/test_server.py", root); + } + + /* start the server */ + args[1 + arg_shift] = const_cast("--port"); + gpr_asprintf(&args[2 + arg_shift], "%d", port); + server = gpr_subprocess_create(3 + arg_shift, (const char**)args); + GPR_ASSERT(server); + gpr_free(args[0]); + if (arg_shift) gpr_free(args[1]); + gpr_free(args[2 + arg_shift]); + gpr_free(root); + + gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_seconds(5, GPR_TIMESPAN))); + + grpc_httpcli_context_init(&g_context); + grpc_pollset* pollset = + static_cast(gpr_zalloc(grpc_pollset_size())); + grpc_pollset_init(pollset, &g_mu); + g_pops = grpc_polling_entity_create_from_pollset(pollset); + + test_get(port); + test_post(port); + + grpc_httpcli_context_destroy(&g_context); + GRPC_CLOSURE_INIT(&destroyed, destroy_pops, &g_pops, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(grpc_polling_entity_pollset(&g_pops), &destroyed); + } grpc_shutdown(); gpr_free(grpc_polling_entity_pollset(&g_pops)); diff --git a/test/core/http/httpscli_test.cc b/test/core/http/httpscli_test.cc index 76bbd2d366..ee2bff18db 100644 --- a/test/core/http/httpscli_test.cc +++ b/test/core/http/httpscli_test.cc @@ -195,11 +195,12 @@ int main(int argc, char** argv) { test_get(port); test_post(port); - grpc_httpcli_context_destroy(&g_context); - GRPC_CLOSURE_INIT(&destroyed, destroy_pops, &g_pops, - grpc_schedule_on_exec_ctx); - grpc_pollset_shutdown(grpc_polling_entity_pollset(&g_pops), &destroyed); - + { + grpc_httpcli_context_destroy(&g_context); + GRPC_CLOSURE_INIT(&destroyed, destroy_pops, &g_pops, + grpc_schedule_on_exec_ctx); + grpc_pollset_shutdown(grpc_polling_entity_pollset(&g_pops), &destroyed); + } grpc_shutdown(); gpr_free(grpc_polling_entity_pollset(&g_pops)); diff --git a/test/core/http/parser_test.cc b/test/core/http/parser_test.cc index 0b60e369b7..18f19856bd 100644 --- a/test/core/http/parser_test.cc +++ b/test/core/http/parser_test.cc @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -217,6 +218,7 @@ int main(int argc, char** argv) { char *tmp1, *tmp2; grpc_test_init(argc, argv); + grpc_init(); for (i = 0; i < GPR_ARRAY_SIZE(split_modes); i++) { test_succeeds(split_modes[i], @@ -300,5 +302,6 @@ int main(int argc, char** argv) { gpr_free(tmp2); } + grpc_shutdown(); return 0; } -- cgit v1.2.3