diff options
author | Yash Tibrewal <yashkt@google.com> | 2017-11-28 13:23:36 -0800 |
---|---|---|
committer | Yash Tibrewal <yashkt@google.com> | 2017-11-28 13:23:36 -0800 |
commit | 81fc8c9c336fab7a71b448f748a32d680301277c (patch) | |
tree | 5cd64fd191db0f87d59ef53768c1b6760b4f1654 /test/core/util/port_server_client.cc | |
parent | 3285f4c7329bf4305133be74f88dd4b10d5e2052 (diff) |
Fix tests to call grpc_init and grpc_shutdown before using exec_ctx
Diffstat (limited to 'test/core/util/port_server_client.cc')
-rw-r--r-- | test/core/util/port_server_client.cc | 83 |
1 files changed, 42 insertions, 41 deletions
diff --git a/test/core/util/port_server_client.cc b/test/core/util/port_server_client.cc index 9d0cb20bbd..705286c6d4 100644 --- a/test/core/util/port_server_client.cc +++ b/test/core/util/port_server_client.cc @@ -194,54 +194,55 @@ int grpc_pick_port_using_server(void) { grpc_httpcli_context context; grpc_httpcli_request req; portreq pr; - grpc_core::ExecCtx _local_exec_ctx; grpc_closure* shutdown_closure; grpc_init(); + { + grpc_core::ExecCtx _local_exec_ctx; + memset(&pr, 0, sizeof(pr)); + memset(&req, 0, sizeof(req)); + grpc_pollset* pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + grpc_pollset_init(pollset, &pr.mu); + pr.pops = grpc_polling_entity_create_from_pollset(pollset); + shutdown_closure = GRPC_CLOSURE_CREATE(destroy_pops_and_shutdown, &pr.pops, + grpc_schedule_on_exec_ctx); + pr.port = -1; + pr.server = const_cast<char*>(GRPC_PORT_SERVER_ADDRESS); + pr.ctx = &context; + + req.host = const_cast<char*>(GRPC_PORT_SERVER_ADDRESS); + req.http.path = const_cast<char*>("/get"); - memset(&pr, 0, sizeof(pr)); - memset(&req, 0, sizeof(req)); - grpc_pollset* pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); - grpc_pollset_init(pollset, &pr.mu); - pr.pops = grpc_polling_entity_create_from_pollset(pollset); - shutdown_closure = GRPC_CLOSURE_CREATE(destroy_pops_and_shutdown, &pr.pops, - grpc_schedule_on_exec_ctx); - pr.port = -1; - pr.server = const_cast<char*>(GRPC_PORT_SERVER_ADDRESS); - pr.ctx = &context; - - req.host = const_cast<char*>(GRPC_PORT_SERVER_ADDRESS); - req.http.path = const_cast<char*>("/get"); - - grpc_httpcli_context_init(&context); - grpc_resource_quota* resource_quota = - grpc_resource_quota_create("port_server_client/pick"); - grpc_httpcli_get( - &context, &pr.pops, resource_quota, &req, - grpc_core::ExecCtx::Get()->Now() + 30 * GPR_MS_PER_SEC, - GRPC_CLOSURE_CREATE(got_port_from_server, &pr, grpc_schedule_on_exec_ctx), - &pr.response); - grpc_resource_quota_unref_internal(resource_quota); - grpc_core::ExecCtx::Get()->Flush(); - gpr_mu_lock(pr.mu); - while (pr.port == -1) { - grpc_pollset_worker* worker = nullptr; - if (!GRPC_LOG_IF_ERROR( - "pollset_work", - grpc_pollset_work( - grpc_polling_entity_pollset(&pr.pops), &worker, - grpc_core::ExecCtx::Get()->Now() + GPR_MS_PER_SEC))) { - pr.port = 0; + grpc_httpcli_context_init(&context); + grpc_resource_quota* resource_quota = + grpc_resource_quota_create("port_server_client/pick"); + grpc_httpcli_get(&context, &pr.pops, resource_quota, &req, + grpc_core::ExecCtx::Get()->Now() + 30 * GPR_MS_PER_SEC, + GRPC_CLOSURE_CREATE(got_port_from_server, &pr, + grpc_schedule_on_exec_ctx), + &pr.response); + grpc_resource_quota_unref_internal(resource_quota); + grpc_core::ExecCtx::Get()->Flush(); + gpr_mu_lock(pr.mu); + while (pr.port == -1) { + grpc_pollset_worker* worker = nullptr; + if (!GRPC_LOG_IF_ERROR( + "pollset_work", + grpc_pollset_work( + grpc_polling_entity_pollset(&pr.pops), &worker, + grpc_core::ExecCtx::Get()->Now() + GPR_MS_PER_SEC))) { + pr.port = 0; + } } - } - gpr_mu_unlock(pr.mu); + gpr_mu_unlock(pr.mu); - grpc_http_response_destroy(&pr.response); - grpc_httpcli_context_destroy(&context); - grpc_pollset_shutdown(grpc_polling_entity_pollset(&pr.pops), - shutdown_closure); + grpc_http_response_destroy(&pr.response); + grpc_httpcli_context_destroy(&context); + grpc_pollset_shutdown(grpc_polling_entity_pollset(&pr.pops), + shutdown_closure); - grpc_core::ExecCtx::Get()->Flush(); + grpc_core::ExecCtx::Get()->Flush(); + } grpc_shutdown(); return pr.port; |