Add condition to avoid duplicate shutdown

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

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

Loading…
Cancel
Save