xds_end2end_test: improve TestType API (#25557)

pull/25563/head
Mark D. Roth 4 years ago committed by GitHub
parent 202b6ca5f1
commit 013e339761
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 240
      test/cpp/end2end/xds_end2end_test.cc

@ -1319,23 +1319,39 @@ class LrsServiceImpl : public std::enable_shared_from_this<LrsServiceImpl> {
class TestType { class TestType {
public: public:
TestType(bool use_xds_resolver, bool enable_load_reporting, TestType& set_use_fake_resolver() {
bool enable_rds_testing = false, bool use_v2 = false, use_fake_resolver_ = true;
bool use_xds_credentials = false) return *this;
: use_xds_resolver_(use_xds_resolver), }
enable_load_reporting_(enable_load_reporting),
enable_rds_testing_(enable_rds_testing), TestType& set_enable_load_reporting() {
use_v2_(use_v2), enable_load_reporting_ = true;
use_xds_credentials_(use_xds_credentials) {} return *this;
}
bool use_xds_resolver() const { return use_xds_resolver_; }
TestType& set_enable_rds_testing() {
enable_rds_testing_ = true;
return *this;
}
TestType& set_use_v2() {
use_v2_ = true;
return *this;
}
TestType& set_use_xds_credentials() {
use_xds_credentials_ = true;
return *this;
}
bool use_fake_resolver() const { return use_fake_resolver_; }
bool enable_load_reporting() const { return enable_load_reporting_; } bool enable_load_reporting() const { return enable_load_reporting_; }
bool enable_rds_testing() const { return enable_rds_testing_; } bool enable_rds_testing() const { return enable_rds_testing_; }
bool use_v2() const { return use_v2_; } bool use_v2() const { return use_v2_; }
bool use_xds_credentials() const { return use_xds_credentials_; } bool use_xds_credentials() const { return use_xds_credentials_; }
std::string AsString() const { std::string AsString() const {
std::string retval = (use_xds_resolver_ ? "XdsResolver" : "FakeResolver"); std::string retval = (use_fake_resolver_ ? "FakeResolver" : "XdsResolver");
retval += (use_v2_ ? "V2" : "V3"); retval += (use_v2_ ? "V2" : "V3");
if (enable_load_reporting_) retval += "WithLoadReporting"; if (enable_load_reporting_) retval += "WithLoadReporting";
if (enable_rds_testing_) retval += "Rds"; if (enable_rds_testing_) retval += "Rds";
@ -1344,11 +1360,11 @@ class TestType {
} }
private: private:
const bool use_xds_resolver_; bool use_fake_resolver_ = false;
const bool enable_load_reporting_; bool enable_load_reporting_ = false;
const bool enable_rds_testing_; bool enable_rds_testing_ = false;
const bool use_v2_; bool use_v2_ = false;
const bool use_xds_credentials_; bool use_xds_credentials_ = false;
}; };
std::string ReadFile(const char* file_path) { std::string ReadFile(const char* file_path) {
@ -1618,7 +1634,8 @@ class XdsEnd2endTest : public ::testing::TestWithParam<TestType> {
} }
const char* DefaultEdsServiceName() const { const char* DefaultEdsServiceName() const {
return GetParam().use_xds_resolver() ? kDefaultEdsServiceName : kServerName; return GetParam().use_fake_resolver() ? kServerName
: kDefaultEdsServiceName;
} }
void TearDown() override { void TearDown() override {
@ -1659,7 +1676,7 @@ class XdsEnd2endTest : public ::testing::TestWithParam<TestType> {
} }
// If the parent channel is using the fake resolver, we inject the // If the parent channel is using the fake resolver, we inject the
// response generator here. // response generator here.
if (!GetParam().use_xds_resolver()) { if (GetParam().use_fake_resolver()) {
if (response_generator == nullptr) { if (response_generator == nullptr) {
response_generator = response_generator_.get(); response_generator = response_generator_.get();
} }
@ -1671,7 +1688,7 @@ class XdsEnd2endTest : public ::testing::TestWithParam<TestType> {
logical_dns_cluster_resolver_response_generator_.get(), logical_dns_cluster_resolver_response_generator_.get(),
&kLogicalDnsClusterResolverResponseGeneratorVtable); &kLogicalDnsClusterResolverResponseGeneratorVtable);
std::string uri = absl::StrCat( std::string uri = absl::StrCat(
GetParam().use_xds_resolver() ? "xds" : "fake", ":///", server_name); GetParam().use_fake_resolver() ? "fake" : "xds", ":///", server_name);
std::shared_ptr<ChannelCredentials> channel_creds = std::shared_ptr<ChannelCredentials> channel_creds =
GetParam().use_xds_credentials() GetParam().use_xds_credentials()
? experimental::XdsCredentials(CreateTlsFallbackCredentials()) ? experimental::XdsCredentials(CreateTlsFallbackCredentials())
@ -1852,7 +1869,7 @@ class XdsEnd2endTest : public ::testing::TestWithParam<TestType> {
void SetNextResolution( void SetNextResolution(
const std::vector<int>& ports, const std::vector<int>& ports,
grpc_core::FakeResolverResponseGenerator* response_generator = nullptr) { grpc_core::FakeResolverResponseGenerator* response_generator = nullptr) {
if (GetParam().use_xds_resolver()) return; // Not used with xds resolver. if (!GetParam().use_fake_resolver()) return; // Not used with xds resolver.
grpc_core::ExecCtx exec_ctx; grpc_core::ExecCtx exec_ctx;
grpc_core::Resolver::Result result; grpc_core::Resolver::Result result;
result.addresses = CreateAddressListFromPortList(ports); result.addresses = CreateAddressListFromPortList(ports);
@ -2342,8 +2359,8 @@ TEST_P(BasicTest, Vanilla) {
} }
// Check LB policy name for the channel. // Check LB policy name for the channel.
EXPECT_EQ( EXPECT_EQ(
(GetParam().use_xds_resolver() ? "xds_cluster_manager_experimental" (GetParam().use_fake_resolver() ? "xds_cluster_resolver_experimental"
: "xds_cluster_resolver_experimental"), : "xds_cluster_manager_experimental"),
channel_->GetLoadBalancingPolicyName()); channel_->GetLoadBalancingPolicyName());
} }
@ -7911,7 +7928,7 @@ class ClientLoadReportingTest : public XdsEnd2endTest {
// Tests that the load report received at the balancer is correct. // Tests that the load report received at the balancer is correct.
TEST_P(ClientLoadReportingTest, Vanilla) { TEST_P(ClientLoadReportingTest, Vanilla) {
if (!GetParam().use_xds_resolver()) { if (GetParam().use_fake_resolver()) {
balancers_[0]->lrs_service()->set_cluster_names({kServerName}); balancers_[0]->lrs_service()->set_cluster_names({kServerName});
} }
SetNextResolution({}); SetNextResolution({});
@ -8041,7 +8058,7 @@ TEST_P(ClientLoadReportingTest, HonorsClustersRequestedByLrsServer) {
// Tests that if the balancer restarts, the client load report contains the // Tests that if the balancer restarts, the client load report contains the
// stats before and after the restart correctly. // stats before and after the restart correctly.
TEST_P(ClientLoadReportingTest, BalancerRestart) { TEST_P(ClientLoadReportingTest, BalancerRestart) {
if (!GetParam().use_xds_resolver()) { if (GetParam().use_fake_resolver()) {
balancers_[0]->lrs_service()->set_cluster_names({kServerName}); balancers_[0]->lrs_service()->set_cluster_names({kServerName});
} }
SetNextResolution({}); SetNextResolution({});
@ -8117,7 +8134,7 @@ class ClientLoadReportingWithDropTest : public XdsEnd2endTest {
// Tests that the drop stats are correctly reported by client load reporting. // Tests that the drop stats are correctly reported by client load reporting.
TEST_P(ClientLoadReportingWithDropTest, Vanilla) { TEST_P(ClientLoadReportingWithDropTest, Vanilla) {
if (!GetParam().use_xds_resolver()) { if (GetParam().use_fake_resolver()) {
balancers_[0]->lrs_service()->set_cluster_names({kServerName}); balancers_[0]->lrs_service()->set_cluster_names({kServerName});
} }
SetNextResolution({}); SetNextResolution({});
@ -8209,139 +8226,136 @@ std::string TestTypeName(const ::testing::TestParamInfo<TestType>& info) {
return info.param.AsString(); return info.param.AsString();
} }
// TestType params: // Run with all combinations of xds/fake resolver and enabling load reporting.
// - use_xds_resolver INSTANTIATE_TEST_SUITE_P(
// - enable_load_reporting XdsTest, BasicTest,
// - enable_rds_testing = false ::testing::Values(
// - use_v2 = false TestType(), TestType().set_enable_load_reporting(),
// - use_xds_credentials = false TestType().set_use_fake_resolver(),
TestType().set_use_fake_resolver().set_enable_load_reporting()),
INSTANTIATE_TEST_SUITE_P(XdsTest, BasicTest, &TestTypeName);
::testing::Values(TestType(false, true),
TestType(false, false),
TestType(true, false),
TestType(true, true)),
&TestTypeName);
// Run with both fake resolver and xds resolver. // Run with both fake resolver and xds resolver.
// Don't run with load reporting or v2 or RDS, since they are irrelevant to // Don't run with load reporting or v2 or RDS, since they are irrelevant to
// the tests. // the tests.
INSTANTIATE_TEST_SUITE_P(XdsTest, SecureNamingTest, INSTANTIATE_TEST_SUITE_P(XdsTest, SecureNamingTest,
::testing::Values(TestType(false, false), ::testing::Values(TestType(),
TestType(true, false)), TestType().set_use_fake_resolver()),
&TestTypeName); &TestTypeName);
// LDS depends on XdsResolver. // LDS depends on XdsResolver.
INSTANTIATE_TEST_SUITE_P(XdsTest, LdsTest, INSTANTIATE_TEST_SUITE_P(XdsTest, LdsTest, ::testing::Values(TestType()),
::testing::Values(TestType(true, false),
TestType(true, true)),
&TestTypeName); &TestTypeName);
// LDS/RDS commmon tests depend on XdsResolver. // LDS/RDS commmon tests depend on XdsResolver.
INSTANTIATE_TEST_SUITE_P(XdsTest, LdsRdsTest, INSTANTIATE_TEST_SUITE_P(
::testing::Values(TestType(true, false), XdsTest, LdsRdsTest,
TestType(true, true), ::testing::Values(TestType(), TestType().set_enable_rds_testing(),
TestType(true, false, true), // Also test with xDS v2.
TestType(true, true, true), TestType().set_enable_rds_testing().set_use_v2()),
// Also test with xDS v2. &TestTypeName);
TestType(true, true, true, true)),
&TestTypeName);
// CDS depends on XdsResolver. // CDS depends on XdsResolver.
INSTANTIATE_TEST_SUITE_P(XdsTest, CdsTest, INSTANTIATE_TEST_SUITE_P(
::testing::Values(TestType(true, false), XdsTest, CdsTest,
TestType(true, true)), ::testing::Values(TestType(), TestType().set_enable_load_reporting()),
&TestTypeName); &TestTypeName);
// CDS depends on XdsResolver. // CDS depends on XdsResolver.
// Security depends on v3. // Security depends on v3.
// Not enabling load reporting or RDS, since those are irrelevant to these // Not enabling load reporting or RDS, since those are irrelevant to these
// tests. // tests.
INSTANTIATE_TEST_SUITE_P(XdsTest, XdsSecurityTest, INSTANTIATE_TEST_SUITE_P(
::testing::Values(TestType(true, false, false, false, XdsTest, XdsSecurityTest,
true)), ::testing::Values(TestType().set_use_xds_credentials()), &TestTypeName);
&TestTypeName);
// We are only testing the server here. // We are only testing the server here.
INSTANTIATE_TEST_SUITE_P(XdsTest, XdsEnabledServerTest, INSTANTIATE_TEST_SUITE_P(XdsTest, XdsEnabledServerTest,
::testing::Values(TestType(true, false, false, false, ::testing::Values(TestType()), &TestTypeName);
false)),
&TestTypeName);
// We are only testing the server here. // We are only testing the server here.
INSTANTIATE_TEST_SUITE_P(XdsTest, XdsServerSecurityTest, INSTANTIATE_TEST_SUITE_P(XdsTest, XdsServerSecurityTest,
::testing::Values(TestType(false, false, false, false, ::testing::Values(TestType()
true)), .set_use_fake_resolver()
.set_use_xds_credentials()),
&TestTypeName); &TestTypeName);
// EDS could be tested with or without XdsResolver, but the tests would // EDS could be tested with or without XdsResolver, but the tests would
// be the same either way, so we test it only with XdsResolver. // be the same either way, so we test it only with XdsResolver.
INSTANTIATE_TEST_SUITE_P(XdsTest, EdsTest, INSTANTIATE_TEST_SUITE_P(
::testing::Values(TestType(true, false), XdsTest, EdsTest,
TestType(true, true)), ::testing::Values(TestType(), TestType().set_enable_load_reporting()),
&TestTypeName); &TestTypeName);
// Test initial resource timeouts for each resource type. // Test initial resource timeouts for each resource type.
// Do this only for XdsResolver with RDS enabled, so that we can test // Do this only for XdsResolver with RDS enabled, so that we can test
// all resource types. // all resource types.
// Run with V3 only, since the functionality is no different in V2. // Run with V3 only, since the functionality is no different in V2.
INSTANTIATE_TEST_SUITE_P(XdsTest, TimeoutTest, INSTANTIATE_TEST_SUITE_P(XdsTest, TimeoutTest,
::testing::Values(TestType(true, false, true)), ::testing::Values(TestType().set_enable_rds_testing()),
&TestTypeName); &TestTypeName);
// XdsResolverOnlyTest depends on XdsResolver. // XdsResolverOnlyTest depends on XdsResolver.
INSTANTIATE_TEST_SUITE_P(XdsTest, XdsResolverOnlyTest, INSTANTIATE_TEST_SUITE_P(
::testing::Values(TestType(true, false), XdsTest, XdsResolverOnlyTest,
TestType(true, true)), ::testing::Values(TestType(), TestType().set_enable_load_reporting()),
&TestTypeName); &TestTypeName);
// XdsResolverLoadReprtingOnlyTest depends on XdsResolver and load reporting. // XdsResolverLoadReprtingOnlyTest depends on XdsResolver and load reporting.
INSTANTIATE_TEST_SUITE_P(XdsTest, XdsResolverLoadReportingOnlyTest, INSTANTIATE_TEST_SUITE_P(
::testing::Values(TestType(true, true)), XdsTest, XdsResolverLoadReportingOnlyTest,
&TestTypeName); ::testing::Values(TestType().set_enable_load_reporting()), &TestTypeName);
INSTANTIATE_TEST_SUITE_P(XdsTest, LocalityMapTest, INSTANTIATE_TEST_SUITE_P(
::testing::Values(TestType(false, true), XdsTest, LocalityMapTest,
TestType(false, false), ::testing::Values(
TestType(true, false), TestType(), TestType().set_enable_load_reporting(),
TestType(true, true)), TestType().set_use_fake_resolver(),
&TestTypeName); TestType().set_use_fake_resolver().set_enable_load_reporting()),
&TestTypeName);
INSTANTIATE_TEST_SUITE_P(XdsTest, FailoverTest,
::testing::Values(TestType(false, true), INSTANTIATE_TEST_SUITE_P(
TestType(false, false), XdsTest, FailoverTest,
TestType(true, false), ::testing::Values(
TestType(true, true)), TestType(), TestType().set_enable_load_reporting(),
&TestTypeName); TestType().set_use_fake_resolver(),
TestType().set_use_fake_resolver().set_enable_load_reporting()),
INSTANTIATE_TEST_SUITE_P(XdsTest, DropTest, &TestTypeName);
::testing::Values(TestType(false, true),
TestType(false, false), INSTANTIATE_TEST_SUITE_P(
TestType(true, false), XdsTest, DropTest,
TestType(true, true)), ::testing::Values(
&TestTypeName); TestType(), TestType().set_enable_load_reporting(),
TestType().set_use_fake_resolver(),
INSTANTIATE_TEST_SUITE_P(XdsTest, BalancerUpdateTest, TestType().set_use_fake_resolver().set_enable_load_reporting()),
::testing::Values(TestType(false, true), &TestTypeName);
TestType(false, false),
TestType(true, true)), INSTANTIATE_TEST_SUITE_P(
&TestTypeName); XdsTest, BalancerUpdateTest,
::testing::Values(
TestType().set_use_fake_resolver(),
TestType().set_use_fake_resolver().set_enable_load_reporting(),
TestType().set_enable_load_reporting()),
&TestTypeName);
// Load reporting tests are not run with load reporting disabled. // Load reporting tests are not run with load reporting disabled.
INSTANTIATE_TEST_SUITE_P(XdsTest, ClientLoadReportingTest, INSTANTIATE_TEST_SUITE_P(
::testing::Values(TestType(false, true), XdsTest, ClientLoadReportingTest,
TestType(true, true)), ::testing::Values(
&TestTypeName); TestType().set_enable_load_reporting(),
TestType().set_enable_load_reporting().set_use_fake_resolver()),
&TestTypeName);
// Load reporting tests are not run with load reporting disabled. // Load reporting tests are not run with load reporting disabled.
INSTANTIATE_TEST_SUITE_P(XdsTest, ClientLoadReportingWithDropTest, INSTANTIATE_TEST_SUITE_P(
::testing::Values(TestType(false, true), XdsTest, ClientLoadReportingWithDropTest,
TestType(true, true)), ::testing::Values(
&TestTypeName); TestType().set_enable_load_reporting(),
TestType().set_enable_load_reporting().set_use_fake_resolver()),
&TestTypeName);
INSTANTIATE_TEST_SUITE_P(XdsTest, BootstrapContentsFromEnvVarTest, INSTANTIATE_TEST_SUITE_P(XdsTest, BootstrapContentsFromEnvVarTest,
::testing::Values(TestType(true, false)), ::testing::Values(TestType()), &TestTypeName);
&TestTypeName);
} // namespace } // namespace
} // namespace testing } // namespace testing

Loading…
Cancel
Save