From 74d2fb842ebb05b0e30866b04bd943e4c66884b6 Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Thu, 9 Jan 2020 17:00:12 -0800 Subject: [PATCH] Timeout for shutdown! --- test/core/backoff/backoff_test.cc | 5 ++-- .../transport/chttp2/context_list_test.cc | 6 +++-- test/core/util/test_config.cc | 17 ++++++++++++- test/cpp/performance/writes_per_rpc_test.cc | 25 +++++-------------- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/test/core/backoff/backoff_test.cc b/test/core/backoff/backoff_test.cc index 3c6fa9e28b3..a6a3af91df1 100644 --- a/test/core/backoff/backoff_test.cc +++ b/test/core/backoff/backoff_test.cc @@ -172,9 +172,10 @@ TEST(BackOffTest, JitterBackOff) { } // namespace grpc int main(int argc, char** argv) { - grpc_init(); grpc::testing::TestEnvironment env(argc, argv); ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + grpc_init(); + int ret = RUN_ALL_TESTS(); grpc_shutdown(); + return ret; } diff --git a/test/core/transport/chttp2/context_list_test.cc b/test/core/transport/chttp2/context_list_test.cc index 1757770aba7..629e01df196 100644 --- a/test/core/transport/chttp2/context_list_test.cc +++ b/test/core/transport/chttp2/context_list_test.cc @@ -165,7 +165,9 @@ TEST_F(ContextListTest, NonEmptyListEmptyTimestamp) { int main(int argc, char** argv) { grpc::testing::TestEnvironment env(argc, argv); - grpc_init(); ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + grpc_init(); + int ret = RUN_ALL_TESTS(); + grpc_shutdown(); + return ret; } diff --git a/test/core/util/test_config.cc b/test/core/util/test_config.cc index a450361b85f..115a9833c44 100644 --- a/test/core/util/test_config.cc +++ b/test/core/util/test_config.cc @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -398,7 +399,21 @@ TestEnvironment::TestEnvironment(int argc, char** argv) { grpc_test_init(argc, argv); } -TestEnvironment::~TestEnvironment() { grpc_maybe_wait_for_async_shutdown(); } +TestEnvironment::~TestEnvironment() { + // This will wait until gRPC shutdown has actually happened to make sure + // no gRPC resources (such as thread) are active. (timeout = 10s) + gpr_timespec timeout = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_seconds(10, GPR_TIMESPAN)); + while (grpc_is_initialized()) { + grpc_maybe_wait_for_async_shutdown(); + gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_millis(1, GPR_TIMESPAN))); + if (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), timeout) > 0) { + gpr_log(GPR_ERROR, "Timeout in waiting for gRPC shutdown"); + break; + } + } +} } // namespace testing } // namespace grpc diff --git a/test/cpp/performance/writes_per_rpc_test.cc b/test/cpp/performance/writes_per_rpc_test.cc index b74f4d0466b..8cae89cf155 100644 --- a/test/cpp/performance/writes_per_rpc_test.cc +++ b/test/cpp/performance/writes_per_rpc_test.cc @@ -57,22 +57,6 @@ static void ApplyCommonChannelArguments(ChannelArguments* c) { c->SetInt(GRPC_ARG_MAX_SEND_MESSAGE_LENGTH, INT_MAX); } -static class InitializeStuff { - public: - InitializeStuff() { - init_lib_.init(); - rq_ = grpc_resource_quota_create("bm"); - } - - ~InitializeStuff() { init_lib_.shutdown(); } - - grpc_resource_quota* rq() { return rq_; } - - private: - internal::GrpcLibrary init_lib_; - grpc_resource_quota* rq_; -} initialize_stuff; - class EndpointPairFixture { public: EndpointPairFixture(Service* service, grpc_endpoint_pair endpoints) { @@ -160,9 +144,9 @@ class InProcessCHTTP2 : public EndpointPairFixture { grpc_passthru_endpoint_stats* stats_; static grpc_endpoint_pair MakeEndpoints(grpc_passthru_endpoint_stats* stats) { + static grpc_resource_quota* rq = grpc_resource_quota_create("bm"); grpc_endpoint_pair p; - grpc_passthru_endpoint_create(&p.client, &p.server, initialize_stuff.rq(), - stats); + grpc_passthru_endpoint_create(&p.client, &p.server, rq, stats); return p; } }; @@ -257,5 +241,8 @@ TEST(WritesPerRpcTest, UnaryPingPong) { int main(int argc, char** argv) { grpc::testing::TestEnvironment env(argc, argv); ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + grpc_init(); + int ret = RUN_ALL_TESTS(); + grpc_shutdown(); + return ret; }