Skip to content

Commit

Permalink
Add condition to avoid duplicate shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
mhaidrygoog committed Jul 19, 2019
1 parent f4b1182 commit da85cec
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions test/cpp/end2end/generic_end2end_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -77,17 +78,21 @@ class GenericEnd2endTest : public ::testing::Test {
server_ = builder.BuildAndStart();
}

void TearDown() override {
server_->Shutdown();
void* ignored_tag;
bool ignored_ok;
cli_cq_.Shutdown();
srv_cq_->Shutdown();
while (cli_cq_.Next(&ignored_tag, &ignored_ok))
;
while (srv_cq_->Next(&ignored_tag, &ignored_ok))
;
void ShutDownServerAndCQs() {
if (!shut_down_) {
server_->Shutdown();
void* ignored_tag;
bool ignored_ok;
cli_cq_.Shutdown();
srv_cq_->Shutdown();
while (cli_cq_.Next(&ignored_tag, &ignored_ok))
;
while (srv_cq_->Next(&ignored_tag, &ignored_ok))
;
shut_down_ = true;
}
}
void TearDown() override { ShutDownServerAndCQs(); }

void ResetStub() {
std::shared_ptr<Channel> channel = grpc::CreateChannel(
Expand Down Expand Up @@ -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_;
};

Expand Down Expand Up @@ -400,7 +406,7 @@ TEST_F(GenericEnd2endTest, ShortDeadline) {
std::lock_guard<std::mutex> lock(shutting_down_mu_);
shutting_down_ = true;
}
TearDown();
ShutDownServerAndCQs();
driver.join();
}

Expand Down

0 comments on commit da85cec

Please sign in to comment.