Skip to content

Commit

Permalink
[XdsEnd2endTest] Fix flakiness around getenv (grpc#38589)
Browse files Browse the repository at this point in the history
Fix grpc#38588

Closes grpc#38589

COPYBARA_INTEGRATE_REVIEW=grpc#38589 from yashykt:GetEnvFlakiness 97fcd80
PiperOrigin-RevId: 720996995
  • Loading branch information
yashykt authored and copybara-github committed Jan 29, 2025
1 parent d97c28f commit f189dc2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion test/cpp/end2end/xds/xds_end2end_test_lib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,9 @@ const char XdsEnd2endTest::kRequestMessage[] = "Live long and prosper.";

XdsEnd2endTest::XdsEnd2endTest(
std::shared_ptr<ServerCredentials> balancer_credentials)
: balancer_(CreateAndStartBalancer("Default Balancer",
: scoped_event_engine_(
grpc_event_engine::experimental::CreateEventEngine()),
balancer_(CreateAndStartBalancer("Default Balancer",
std::move(balancer_credentials))) {
// Initialize default client-side xDS resources.
default_listener_ = XdsResourceUtils::DefaultListener();
Expand Down
13 changes: 13 additions & 0 deletions test/cpp/end2end/xds/xds_end2end_test_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "envoy/config/rbac/v3/rbac.pb.h"
#include "envoy/extensions/filters/http/rbac/v3/rbac.pb.h"
#include "envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.pb.h"
#include "src/core/lib/event_engine/default_event_engine.h"
#include "src/core/lib/security/credentials/fake/fake_credentials.h"
#include "src/core/lib/security/security_connector/ssl_utils.h"
#include "src/cpp/server/secure_server_credentials.h"
Expand Down Expand Up @@ -1035,6 +1036,18 @@ class XdsEnd2endTest : public ::testing::TestWithParam<XdsTestType>,
static std::shared_ptr<ServerCredentials> CreateMtlsServerCredentials();
static std::shared_ptr<ServerCredentials> CreateTlsServerCredentials();

// event_engine_scope_ always has to be at the top of the list to make sure
// that all other objects are destroyed before this and other event engine
// refs are released.
// We are using DefaultEventEngineScope 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::DefaultEventEngineScope scoped_event_engine_;

std::unique_ptr<BalancerServerThread> balancer_;

std::shared_ptr<Channel> channel_;
Expand Down

0 comments on commit f189dc2

Please sign in to comment.