Timeout for shutdown!

pull/21631/head
Esun Kim 5 years ago
parent 8c9dcf7c35
commit 74d2fb842e
  1. 5
      test/core/backoff/backoff_test.cc
  2. 6
      test/core/transport/chttp2/context_list_test.cc
  3. 17
      test/core/util/test_config.cc
  4. 25
      test/cpp/performance/writes_per_rpc_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;
}

@ -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;
}

@ -25,6 +25,7 @@
#include <stdlib.h>
#include <string.h>
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
@ -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

@ -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;
}

Loading…
Cancel
Save