Add condition to avoid duplicate shutdown

pull/19682/head
Moiz Haidry 5 years ago
parent f4b1182a10
commit da85cec0f2
  1. 10
      test/cpp/end2end/generic_end2end_test.cc

@ -62,6 +62,7 @@ class GenericEnd2endTest : public ::testing::Test {
GenericEnd2endTest() : server_host_("localhost") {}
void SetUp() override {
shut_down_ = false;
int port = grpc_pick_unused_port_or_die();
server_address_ << server_host_ << ":" << port;
// Setup server
@ -77,7 +78,8 @@ class GenericEnd2endTest : public ::testing::Test {
server_ = builder.BuildAndStart();
}
void TearDown() override {
void ShutDownServerAndCQs() {
if (!shut_down_) {
server_->Shutdown();
void* ignored_tag;
bool ignored_ok;
@ -87,7 +89,10 @@ class GenericEnd2endTest : public ::testing::Test {
;
while (srv_cq_->Next(&ignored_tag, &ignored_ok))
;
shut_down_ = true;
}
}
void TearDown() override { ShutDownServerAndCQs(); }
void ResetStub() {
std::shared_ptr<Channel> channel = grpc::CreateChannel(
@ -235,6 +240,7 @@ class GenericEnd2endTest : public ::testing::Test {
const grpc::string server_host_;
std::ostringstream server_address_;
bool shutting_down_;
bool shut_down_;
std::mutex shutting_down_mu_;
};
@ -400,7 +406,7 @@ TEST_F(GenericEnd2endTest, ShortDeadline) {
std::lock_guard<std::mutex> lock(shutting_down_mu_);
shutting_down_ = true;
}
TearDown();
ShutDownServerAndCQs();
driver.join();
}

Loading…
Cancel
Save