Skip to content

Commit

Permalink
[XdsEnd2endTest] Fix flaky issue 38588
Browse files Browse the repository at this point in the history
  • Loading branch information
yashykt committed Jan 28, 2025
1 parent 20c6e27 commit eb6d642
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/cpp/end2end/xds/xds_end2end_test_lib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,17 @@ XdsEnd2endTest::XdsEnd2endTest(
default_server_listener_ = XdsResourceUtils::DefaultServerListener();
}

XdsEnd2endTest::~XdsEnd2endTest() {
// We need to make sure that all work from the current test is done before the
// next test starts. Without this, we run into errors such as
// https://github.com/grpc/grpc/issues/38588. Note that we are using all refs
// to current event engine going down to 0 as a proxy for checking that all
// work from the current test is done, but this is not a guaranteed way
// since there might still be threads that are not using event engine but are
// still accessing/modifying the system state.
grpc_event_engine::experimental::ShutdownDefaultEventEngine();
}

void XdsEnd2endTest::TearDown() {
ShutdownAllBackends();
balancer_->Shutdown();
Expand All @@ -411,6 +422,13 @@ void XdsEnd2endTest::TearDown() {
remove(bootstrap_file_);
gpr_free(bootstrap_file_);
}
// Destruct members so that we can make sure no EventEngine ref is being held
backends_.clear();
stub2_.reset();
stub1_.reset();
stub_.reset();
channel_.reset();
balancer_.reset();
}

std::unique_ptr<XdsEnd2endTest::BalancerServerThread>
Expand Down
1 change: 1 addition & 0 deletions test/cpp/end2end/xds/xds_end2end_test_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ class XdsEnd2endTest : public ::testing::TestWithParam<XdsTestType>,
// If balancer_credentials is null, it defaults to fake credentials.
explicit XdsEnd2endTest(
std::shared_ptr<ServerCredentials> balancer_credentials = nullptr);
~XdsEnd2endTest();

void SetUp() override { InitClient(); }
void TearDown() override;
Expand Down

0 comments on commit eb6d642

Please sign in to comment.