Merge pull request #22857 from donnadionne/policy_name

Modifying SetXdsResource methods sigurature to avoid passing in the
pull/22867/head
donnadionne 5 years ago committed by GitHub
commit 2bfbef4562
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 222
      test/cpp/end2end/xds_end2end_test.cc

@ -420,10 +420,10 @@ class AdsServiceImpl : public AggregatedDiscoveryService::Service,
auto* route = virtual_host->add_routes();
route->mutable_match()->set_prefix("");
route->mutable_route()->set_cluster(kDefaultResourceName);
SetRdsResource(default_route_config_, kDefaultResourceName);
SetRdsResource(default_route_config_);
// Construct LDS response data (with inlined RDS result).
default_listener_ = BuildListener(default_route_config_);
SetLdsResource(default_listener_, kDefaultResourceName);
SetLdsResource(default_listener_);
// Construct CDS response data.
default_cluster_.set_name(kDefaultResourceName);
default_cluster_.set_type(envoy::api::v2::Cluster::EDS);
@ -434,7 +434,7 @@ class AdsServiceImpl : public AggregatedDiscoveryService::Service,
if (enable_load_reporting) {
default_cluster_.mutable_lrs_server()->mutable_self();
}
SetCdsResource(default_cluster_, kDefaultResourceName);
SetCdsResource(default_cluster_);
}
Status StreamAggregatedResources(ServerContext* context,
@ -684,30 +684,28 @@ class AdsServiceImpl : public AggregatedDiscoveryService::Service,
}
}
void SetLdsResource(const Listener& listener, const std::string& name) {
void SetLdsResource(const Listener& listener) {
google::protobuf::Any resource;
resource.PackFrom(listener);
SetResource(std::move(resource), kLdsTypeUrl, name);
SetResource(std::move(resource), kLdsTypeUrl, listener.name());
}
void SetRdsResource(const RouteConfiguration& route,
const std::string& name) {
void SetRdsResource(const RouteConfiguration& route) {
google::protobuf::Any resource;
resource.PackFrom(route);
SetResource(std::move(resource), kRdsTypeUrl, name);
SetResource(std::move(resource), kRdsTypeUrl, route.name());
}
void SetCdsResource(const Cluster& cluster, const std::string& name) {
void SetCdsResource(const Cluster& cluster) {
google::protobuf::Any resource;
resource.PackFrom(cluster);
SetResource(std::move(resource), kCdsTypeUrl, name);
SetResource(std::move(resource), kCdsTypeUrl, cluster.name());
}
void SetEdsResource(const ClusterLoadAssignment& assignment,
const std::string& name) {
void SetEdsResource(const ClusterLoadAssignment& assignment) {
google::protobuf::Any resource;
resource.PackFrom(assignment);
SetResource(std::move(resource), kEdsTypeUrl, name);
SetResource(std::move(resource), kEdsTypeUrl, assignment.cluster_name());
}
void SetLdsToUseDynamicRds() {
@ -718,7 +716,7 @@ class AdsServiceImpl : public AggregatedDiscoveryService::Service,
rds->mutable_config_source()->mutable_ads();
listener.mutable_api_listener()->mutable_api_listener()->PackFrom(
http_connection_manager);
SetLdsResource(listener, kDefaultResourceName);
SetLdsResource(listener);
}
static Listener BuildListener(const RouteConfiguration& route_config) {
@ -1482,11 +1480,10 @@ class XdsEnd2endTest : public ::testing::TestWithParam<TestType> {
void SetRouteConfiguration(int idx, const RouteConfiguration& route_config) {
if (GetParam().enable_rds_testing()) {
balancers_[idx]->ads_service()->SetRdsResource(route_config,
kDefaultResourceName);
balancers_[idx]->ads_service()->SetRdsResource(route_config);
} else {
balancers_[idx]->ads_service()->SetLdsResource(
AdsServiceImpl::BuildListener(route_config), kDefaultResourceName);
AdsServiceImpl::BuildListener(route_config));
}
}
@ -1503,10 +1500,10 @@ class XdsEnd2endTest : public ::testing::TestWithParam<TestType> {
// via bind with a qualified name, it needs to be public.
void SetEdsResourceWithDelay(size_t i,
const ClusterLoadAssignment& assignment,
int delay_ms, const std::string& name) {
int delay_ms) {
GPR_ASSERT(delay_ms > 0);
gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(delay_ms));
balancers_[i]->ads_service()->SetEdsResource(assignment, name);
balancers_[i]->ads_service()->SetEdsResource(assignment);
}
protected:
@ -1697,7 +1694,7 @@ TEST_P(BasicTest, Vanilla) {
{"locality0", GetBackendPorts()},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// Make sure that trying to connect works without a call.
channel_->GetState(true /* try_to_connect */);
// We need to wait for all backends to come online.
@ -1727,7 +1724,7 @@ TEST_P(BasicTest, IgnoresUnhealthyEndpoints) {
{envoy::api::v2::HealthStatus::DRAINING}},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// Make sure that trying to connect works without a call.
channel_->GetState(true /* try_to_connect */);
// We need to wait for all backends to come online.
@ -1753,7 +1750,7 @@ TEST_P(BasicTest, SameBackendListedMultipleTimes) {
});
const size_t kNumRpcsPerAddress = 10;
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// We need to wait for the backend to come online.
WaitForBackend(0);
// Send kNumRpcsPerAddress RPCs per server.
@ -1778,15 +1775,14 @@ TEST_P(BasicTest, InitiallyEmptyServerlist) {
empty_locality,
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// Send non-empty serverlist only after kServerlistDelayMs.
args = AdsServiceImpl::EdsResourceArgs({
{"locality0", GetBackendPorts()},
});
std::thread delayed_resource_setter(
std::bind(&BasicTest::SetEdsResourceWithDelay, this, 0,
AdsServiceImpl::BuildEdsResource(args), kServerlistDelayMs,
kDefaultResourceName));
AdsServiceImpl::BuildEdsResource(args), kServerlistDelayMs));
const auto t0 = system_clock::now();
// Client will block: LB will initially send empty serverlist.
CheckRpcSendOk(
@ -1816,7 +1812,7 @@ TEST_P(BasicTest, AllServersUnreachableFailFast) {
{"locality0", ports},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
const Status status = SendRpc();
// The error shouldn't be DEADLINE_EXCEEDED.
EXPECT_EQ(StatusCode::UNAVAILABLE, status.error_code());
@ -1831,7 +1827,7 @@ TEST_P(BasicTest, BackendsRestart) {
{"locality0", GetBackendPorts()},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
WaitForAllBackends();
// Stop backends. RPCs should fail.
ShutdownAllBackends();
@ -1861,7 +1857,7 @@ TEST_P(XdsResolverOnlyTest, ChangeClusters) {
{"locality0", GetBackendPorts(0, 2)},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// We need to wait for all backends to come online.
WaitForAllBackends(0, 2);
// Populate new EDS resource.
@ -1869,12 +1865,11 @@ TEST_P(XdsResolverOnlyTest, ChangeClusters) {
{"locality0", GetBackendPorts(2, 4)},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args2, kNewClusterName),
kNewClusterName);
AdsServiceImpl::BuildEdsResource(args2, kNewClusterName));
// Populate new CDS resource.
Cluster new_cluster = balancers_[0]->ads_service()->default_cluster();
new_cluster.set_name(kNewClusterName);
balancers_[0]->ads_service()->SetCdsResource(new_cluster, kNewClusterName);
balancers_[0]->ads_service()->SetCdsResource(new_cluster);
// Change RDS resource to point to new cluster.
RouteConfiguration new_route_config =
balancers_[0]->ads_service()->default_route_config();
@ -1884,7 +1879,7 @@ TEST_P(XdsResolverOnlyTest, ChangeClusters) {
->set_cluster(kNewClusterName);
Listener listener =
balancers_[0]->ads_service()->BuildListener(new_route_config);
balancers_[0]->ads_service()->SetLdsResource(listener, kDefaultResourceName);
balancers_[0]->ads_service()->SetLdsResource(listener);
// Wait for all new backends to be used.
std::tuple<int, int, int> counts = WaitForAllBackends(2, 4);
// Make sure no RPCs failed in the transition.
@ -1899,7 +1894,7 @@ TEST_P(XdsResolverOnlyTest, ClusterRemoved) {
{"locality0", GetBackendPorts()},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// We need to wait for all backends to come online.
WaitForAllBackends();
// Unset CDS resource.
@ -1922,7 +1917,7 @@ TEST_P(XdsResolverOnlyTest, RestartsRequestsUponReconnection) {
{"locality0", GetBackendPorts(0, 2)},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// We need to wait for all backends to come online.
WaitForAllBackends(0, 2);
// Now shut down and restart the balancer. When the client
@ -1937,12 +1932,11 @@ TEST_P(XdsResolverOnlyTest, RestartsRequestsUponReconnection) {
{"locality0", GetBackendPorts(2, 4)},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args2, kNewClusterName),
kNewClusterName);
AdsServiceImpl::BuildEdsResource(args2, kNewClusterName));
// Populate new CDS resource.
Cluster new_cluster = balancers_[0]->ads_service()->default_cluster();
new_cluster.set_name(kNewClusterName);
balancers_[0]->ads_service()->SetCdsResource(new_cluster, kNewClusterName);
balancers_[0]->ads_service()->SetCdsResource(new_cluster);
// Change RDS resource to point to new cluster.
RouteConfiguration new_route_config =
balancers_[0]->ads_service()->default_route_config();
@ -1950,8 +1944,7 @@ TEST_P(XdsResolverOnlyTest, RestartsRequestsUponReconnection) {
->mutable_routes(0)
->mutable_route()
->set_cluster(kNewClusterName);
balancers_[0]->ads_service()->SetRdsResource(new_route_config,
kDefaultResourceName);
balancers_[0]->ads_service()->SetRdsResource(new_route_config);
// Wait for all new backends to be used.
std::tuple<int, int, int> counts = WaitForAllBackends(2, 4);
// Make sure no RPCs failed in the transition.
@ -1966,14 +1959,14 @@ TEST_P(XdsResolverOnlyTest, DefaultRouteSpecifiesSlashPrefix) {
->mutable_match()
->set_prefix("/");
balancers_[0]->ads_service()->SetLdsResource(
AdsServiceImpl::BuildListener(route_config), kDefaultResourceName);
AdsServiceImpl::BuildListener(route_config));
SetNextResolution({});
SetNextResolutionForLbChannelAllBalancers();
AdsServiceImpl::EdsResourceArgs args({
{"locality0", GetBackendPorts()},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// We need to wait for all backends to come online.
WaitForAllBackends();
}
@ -1995,18 +1988,17 @@ TEST_P(XdsResolverLoadReportingOnlyTest, ChangeClusters) {
{"locality0", GetBackendPorts(0, 2)},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// cluster kNewClusterName -> locality1 -> backends 2 and 3
AdsServiceImpl::EdsResourceArgs args2({
{"locality1", GetBackendPorts(2, 4)},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args2, kNewClusterName),
kNewClusterName);
AdsServiceImpl::BuildEdsResource(args2, kNewClusterName));
// CDS resource for kNewClusterName.
Cluster new_cluster = balancers_[0]->ads_service()->default_cluster();
new_cluster.set_name(kNewClusterName);
balancers_[0]->ads_service()->SetCdsResource(new_cluster, kNewClusterName);
balancers_[0]->ads_service()->SetCdsResource(new_cluster);
// Wait for all backends to come online.
int num_ok = 0;
int num_failure = 0;
@ -2047,7 +2039,7 @@ TEST_P(XdsResolverLoadReportingOnlyTest, ChangeClusters) {
->set_cluster(kNewClusterName);
Listener listener =
balancers_[0]->ads_service()->BuildListener(new_route_config);
balancers_[0]->ads_service()->SetLdsResource(listener, kDefaultResourceName);
balancers_[0]->ads_service()->SetLdsResource(listener);
// Wait for all new backends to be used.
std::tie(num_ok, num_failure, num_drops) = WaitForAllBackends(2, 4);
// The load report received at the balancer should be correct.
@ -2126,7 +2118,7 @@ TEST_P(SecureNamingTest, TargetNameIsExpected) {
{"locality0", GetBackendPorts()},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// Make sure that trying to connect works without a call.
channel_->GetState(true /* try_to_connect */);
// We need to wait for all backends to come online.
@ -2163,7 +2155,7 @@ using LdsTest = BasicTest;
TEST_P(LdsTest, NoApiListener) {
auto listener = balancers_[0]->ads_service()->default_listener();
listener.clear_api_listener();
balancers_[0]->ads_service()->SetLdsResource(listener, kDefaultResourceName);
balancers_[0]->ads_service()->SetLdsResource(listener);
SetNextResolution({});
SetNextResolutionForLbChannelAllBalancers();
CheckRpcSendFailure();
@ -2181,7 +2173,7 @@ TEST_P(LdsTest, WrongRouteSpecifier) {
http_connection_manager.mutable_scoped_routes();
listener.mutable_api_listener()->mutable_api_listener()->PackFrom(
http_connection_manager);
balancers_[0]->ads_service()->SetLdsResource(listener, kDefaultResourceName);
balancers_[0]->ads_service()->SetLdsResource(listener);
SetNextResolution({});
SetNextResolutionForLbChannelAllBalancers();
CheckRpcSendFailure();
@ -2201,7 +2193,7 @@ TEST_P(LdsTest, RdsMissingConfigSource) {
kDefaultResourceName);
listener.mutable_api_listener()->mutable_api_listener()->PackFrom(
http_connection_manager);
balancers_[0]->ads_service()->SetLdsResource(listener, kDefaultResourceName);
balancers_[0]->ads_service()->SetLdsResource(listener);
SetNextResolution({});
SetNextResolutionForLbChannelAllBalancers();
CheckRpcSendFailure();
@ -2222,7 +2214,7 @@ TEST_P(LdsTest, RdsConfigSourceDoesNotSpecifyAds) {
rds->mutable_config_source()->mutable_self();
listener.mutable_api_listener()->mutable_api_listener()->PackFrom(
http_connection_manager);
balancers_[0]->ads_service()->SetLdsResource(listener, kDefaultResourceName);
balancers_[0]->ads_service()->SetLdsResource(listener);
SetNextResolution({});
SetNextResolutionForLbChannelAllBalancers();
CheckRpcSendFailure();
@ -2636,20 +2628,18 @@ TEST_P(LdsRdsTest, XdsRoutingPathMatching) {
{"locality0", GetBackendPorts(3, 4)},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args1, kNewCluster1Name),
kNewCluster1Name);
AdsServiceImpl::BuildEdsResource(args1, kNewCluster1Name));
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args2, kNewCluster2Name),
kNewCluster2Name);
AdsServiceImpl::BuildEdsResource(args2, kNewCluster2Name));
// Populate new CDS resources.
Cluster new_cluster1 = balancers_[0]->ads_service()->default_cluster();
new_cluster1.set_name(kNewCluster1Name);
balancers_[0]->ads_service()->SetCdsResource(new_cluster1, kNewCluster1Name);
balancers_[0]->ads_service()->SetCdsResource(new_cluster1);
Cluster new_cluster2 = balancers_[0]->ads_service()->default_cluster();
new_cluster2.set_name(kNewCluster2Name);
balancers_[0]->ads_service()->SetCdsResource(new_cluster2, kNewCluster2Name);
balancers_[0]->ads_service()->SetCdsResource(new_cluster2);
// Populating Route Configurations for LDS.
RouteConfiguration new_route_config =
balancers_[0]->ads_service()->default_route_config();
@ -2714,20 +2704,18 @@ TEST_P(LdsRdsTest, XdsRoutingPrefixMatching) {
{"locality0", GetBackendPorts(3, 4)},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args1, kNewCluster1Name),
kNewCluster1Name);
AdsServiceImpl::BuildEdsResource(args1, kNewCluster1Name));
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args2, kNewCluster2Name),
kNewCluster2Name);
AdsServiceImpl::BuildEdsResource(args2, kNewCluster2Name));
// Populate new CDS resources.
Cluster new_cluster1 = balancers_[0]->ads_service()->default_cluster();
new_cluster1.set_name(kNewCluster1Name);
balancers_[0]->ads_service()->SetCdsResource(new_cluster1, kNewCluster1Name);
balancers_[0]->ads_service()->SetCdsResource(new_cluster1);
Cluster new_cluster2 = balancers_[0]->ads_service()->default_cluster();
new_cluster2.set_name(kNewCluster2Name);
balancers_[0]->ads_service()->SetCdsResource(new_cluster2, kNewCluster2Name);
balancers_[0]->ads_service()->SetCdsResource(new_cluster2);
// Populating Route Configurations for LDS.
RouteConfiguration new_route_config =
balancers_[0]->ads_service()->default_route_config();
@ -2780,7 +2768,7 @@ TEST_P(CdsTest, Vanilla) {
TEST_P(CdsTest, WrongClusterType) {
auto cluster = balancers_[0]->ads_service()->default_cluster();
cluster.set_type(envoy::api::v2::Cluster::STATIC);
balancers_[0]->ads_service()->SetCdsResource(cluster, kDefaultResourceName);
balancers_[0]->ads_service()->SetCdsResource(cluster);
SetNextResolution({});
SetNextResolutionForLbChannelAllBalancers();
CheckRpcSendFailure();
@ -2795,7 +2783,7 @@ TEST_P(CdsTest, WrongClusterType) {
TEST_P(CdsTest, WrongEdsConfig) {
auto cluster = balancers_[0]->ads_service()->default_cluster();
cluster.mutable_eds_cluster_config()->mutable_eds_config()->mutable_self();
balancers_[0]->ads_service()->SetCdsResource(cluster, kDefaultResourceName);
balancers_[0]->ads_service()->SetCdsResource(cluster);
SetNextResolution({});
SetNextResolutionForLbChannelAllBalancers();
CheckRpcSendFailure();
@ -2810,7 +2798,7 @@ TEST_P(CdsTest, WrongEdsConfig) {
TEST_P(CdsTest, WrongLbPolicy) {
auto cluster = balancers_[0]->ads_service()->default_cluster();
cluster.set_lb_policy(envoy::api::v2::Cluster::LEAST_REQUEST);
balancers_[0]->ads_service()->SetCdsResource(cluster, kDefaultResourceName);
balancers_[0]->ads_service()->SetCdsResource(cluster);
SetNextResolution({});
SetNextResolutionForLbChannelAllBalancers();
CheckRpcSendFailure();
@ -2825,7 +2813,7 @@ TEST_P(CdsTest, WrongLbPolicy) {
TEST_P(CdsTest, WrongLrsServer) {
auto cluster = balancers_[0]->ads_service()->default_cluster();
cluster.mutable_lrs_server()->mutable_ads();
balancers_[0]->ads_service()->SetCdsResource(cluster, kDefaultResourceName);
balancers_[0]->ads_service()->SetCdsResource(cluster);
SetNextResolution({});
SetNextResolutionForLbChannelAllBalancers();
CheckRpcSendFailure();
@ -2863,7 +2851,7 @@ TEST_P(EdsTest, NacksSparsePriorityList) {
{"locality0", GetBackendPorts(), kDefaultLocalityWeight, 1},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
CheckRpcSendFailure();
const auto& response_state =
balancers_[0]->ads_service()->eds_response_state();
@ -2893,7 +2881,7 @@ TEST_P(LocalityMapTest, WeightedRoundRobin) {
{"locality1", GetBackendPorts(1, 2), kLocalityWeight1},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// Wait for both backends to be ready.
WaitForAllBackends(0, 2);
// Send kNumRpcs RPCs.
@ -2927,7 +2915,7 @@ TEST_P(LocalityMapTest, LocalityContainingNoEndpoints) {
{"locality1", {}},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// Wait for both backends to be ready.
WaitForAllBackends();
// Send kNumRpcs RPCs.
@ -2949,7 +2937,7 @@ TEST_P(LocalityMapTest, NoLocalities) {
SetNextResolutionForLbChannelAllBalancers();
// EDS response contains 2 localities, one with no endpoints.
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource({}), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource({}));
Status status = SendRpc();
EXPECT_FALSE(status.ok());
EXPECT_EQ(status.error_code(), StatusCode::UNAVAILABLE);
@ -2971,14 +2959,14 @@ TEST_P(LocalityMapTest, StressTest) {
args.locality_list.emplace_back(std::move(locality));
}
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// The second ADS response contains 1 locality, which contains backend 1.
args = AdsServiceImpl::EdsResourceArgs({
{"locality0", GetBackendPorts(1, 2)},
});
std::thread delayed_resource_setter(std::bind(
&BasicTest::SetEdsResourceWithDelay, this, 0,
AdsServiceImpl::BuildEdsResource(args), 60 * 1000, kDefaultResourceName));
std::thread delayed_resource_setter(
std::bind(&BasicTest::SetEdsResourceWithDelay, this, 0,
AdsServiceImpl::BuildEdsResource(args), 60 * 1000));
// Wait until backend 0 is ready, before which kNumLocalities localities are
// received and handled by the xds policy.
WaitForBackend(0, /*reset_counters=*/false);
@ -3019,7 +3007,7 @@ TEST_P(LocalityMapTest, UpdateMap) {
{"locality2", GetBackendPorts(2, 3), 4},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// Wait for the first 3 backends to be ready.
WaitForAllBackends(0, 3);
gpr_log(GPR_INFO, "========= BEFORE FIRST BATCH ==========");
@ -3050,7 +3038,7 @@ TEST_P(LocalityMapTest, UpdateMap) {
{"locality3", GetBackendPorts(3, 4), 6},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// Backend 3 hasn't received any request.
EXPECT_EQ(0U, backends_[3]->backend_service()->request_count());
// Wait until the locality update has been processed, as signaled by backend 3
@ -3090,13 +3078,13 @@ TEST_P(LocalityMapTest, ReplaceAllLocalitiesInPriority) {
{"locality0", GetBackendPorts(0, 1)},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
args = AdsServiceImpl::EdsResourceArgs({
{"locality1", GetBackendPorts(1, 2)},
});
std::thread delayed_resource_setter(std::bind(
&BasicTest::SetEdsResourceWithDelay, this, 0,
AdsServiceImpl::BuildEdsResource(args), 5000, kDefaultResourceName));
std::thread delayed_resource_setter(
std::bind(&BasicTest::SetEdsResourceWithDelay, this, 0,
AdsServiceImpl::BuildEdsResource(args), 5000));
// Wait for the first backend to be ready.
WaitForBackend(0);
// Keep sending RPCs until we switch over to backend 1, which tells us
@ -3125,7 +3113,7 @@ TEST_P(FailoverTest, ChooseHighestPriority) {
{"locality3", GetBackendPorts(3, 4), kDefaultLocalityWeight, 0},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
WaitForBackend(3, false);
for (size_t i = 0; i < 3; ++i) {
EXPECT_EQ(0U, backends_[i]->backend_service()->request_count());
@ -3143,7 +3131,7 @@ TEST_P(FailoverTest, DoesNotUsePriorityWithNoEndpoints) {
{"locality3", {}, kDefaultLocalityWeight, 0},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
WaitForBackend(0, false);
for (size_t i = 1; i < 3; ++i) {
EXPECT_EQ(0U, backends_[i]->backend_service()->request_count());
@ -3159,7 +3147,7 @@ TEST_P(FailoverTest, DoesNotUseLocalityWithNoEndpoints) {
{"locality1", GetBackendPorts(), kDefaultLocalityWeight, 0},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// Wait for all backends to be used.
std::tuple<int, int, int> counts = WaitForAllBackends();
// Make sure no RPCs failed in the transition.
@ -3180,7 +3168,7 @@ TEST_P(FailoverTest, Failover) {
ShutdownBackend(3);
ShutdownBackend(0);
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
WaitForBackend(1, false);
for (size_t i = 0; i < 4; ++i) {
if (i == 1) continue;
@ -3203,7 +3191,7 @@ TEST_P(FailoverTest, SwitchBackToHigherPriority) {
ShutdownBackend(3);
ShutdownBackend(0);
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
WaitForBackend(1, false);
for (size_t i = 0; i < 4; ++i) {
if (i == 1) continue;
@ -3225,7 +3213,7 @@ TEST_P(FailoverTest, UpdateInitialUnavailable) {
{"locality1", GetBackendPorts(1, 2), kDefaultLocalityWeight, 1},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
args = AdsServiceImpl::EdsResourceArgs({
{"locality0", GetBackendPorts(0, 1), kDefaultLocalityWeight, 0},
{"locality1", GetBackendPorts(1, 2), kDefaultLocalityWeight, 1},
@ -3234,9 +3222,9 @@ TEST_P(FailoverTest, UpdateInitialUnavailable) {
});
ShutdownBackend(0);
ShutdownBackend(1);
std::thread delayed_resource_setter(std::bind(
&BasicTest::SetEdsResourceWithDelay, this, 0,
AdsServiceImpl::BuildEdsResource(args), 1000, kDefaultResourceName));
std::thread delayed_resource_setter(
std::bind(&BasicTest::SetEdsResourceWithDelay, this, 0,
AdsServiceImpl::BuildEdsResource(args), 1000));
gpr_timespec deadline = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
gpr_time_from_millis(500, GPR_TIMESPAN));
// Send 0.5 second worth of RPCs.
@ -3264,16 +3252,16 @@ TEST_P(FailoverTest, UpdatePriority) {
{"locality3", GetBackendPorts(3, 4), kDefaultLocalityWeight, 0},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
args = AdsServiceImpl::EdsResourceArgs({
{"locality0", GetBackendPorts(0, 1), kDefaultLocalityWeight, 2},
{"locality1", GetBackendPorts(1, 2), kDefaultLocalityWeight, 0},
{"locality2", GetBackendPorts(2, 3), kDefaultLocalityWeight, 1},
{"locality3", GetBackendPorts(3, 4), kDefaultLocalityWeight, 3},
});
std::thread delayed_resource_setter(std::bind(
&BasicTest::SetEdsResourceWithDelay, this, 0,
AdsServiceImpl::BuildEdsResource(args), 1000, kDefaultResourceName));
std::thread delayed_resource_setter(
std::bind(&BasicTest::SetEdsResourceWithDelay, this, 0,
AdsServiceImpl::BuildEdsResource(args), 1000));
WaitForBackend(3, false);
for (size_t i = 0; i < 3; ++i) {
EXPECT_EQ(0U, backends_[i]->backend_service()->request_count());
@ -3297,7 +3285,7 @@ TEST_P(FailoverTest, MoveAllLocalitiesInCurrentPriorityToHigherPriority) {
{"locality1", GetBackendPorts(1, 3), kDefaultLocalityWeight, 1},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// Second update:
// - Priority 0 contains both localities 0 and 1.
// - Priority 1 is not present.
@ -3307,9 +3295,9 @@ TEST_P(FailoverTest, MoveAllLocalitiesInCurrentPriorityToHigherPriority) {
{"locality0", GetBackendPorts(0, 1), kDefaultLocalityWeight, 0},
{"locality1", GetBackendPorts(1, 4), kDefaultLocalityWeight, 0},
});
std::thread delayed_resource_setter(std::bind(
&BasicTest::SetEdsResourceWithDelay, this, 0,
AdsServiceImpl::BuildEdsResource(args), 1000, kDefaultResourceName));
std::thread delayed_resource_setter(
std::bind(&BasicTest::SetEdsResourceWithDelay, this, 0,
AdsServiceImpl::BuildEdsResource(args), 1000));
// When we get the first update, all backends in priority 0 are down,
// so we will create priority 1. Backends 1 and 2 should have traffic,
// but backend 3 should not.
@ -3343,7 +3331,7 @@ TEST_P(DropTest, Vanilla) {
args.drop_categories = {{kLbDropType, kDropPerMillionForLb},
{kThrottleDropType, kDropPerMillionForThrottle}};
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
WaitForAllBackends();
// Send kNumRpcs RPCs and count the drops.
size_t num_drops = 0;
@ -3383,7 +3371,7 @@ TEST_P(DropTest, DropPerHundred) {
args.drop_categories = {{kLbDropType, kDropPerHundredForLb}};
args.drop_denominator = FractionalPercent::HUNDRED;
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
WaitForAllBackends();
// Send kNumRpcs RPCs and count the drops.
size_t num_drops = 0;
@ -3422,7 +3410,7 @@ TEST_P(DropTest, DropPerTenThousand) {
args.drop_categories = {{kLbDropType, kDropPerTenThousandForLb}};
args.drop_denominator = FractionalPercent::TEN_THOUSAND;
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
WaitForAllBackends();
// Send kNumRpcs RPCs and count the drops.
size_t num_drops = 0;
@ -3464,7 +3452,7 @@ TEST_P(DropTest, Update) {
});
args.drop_categories = {{kLbDropType, kDropPerMillionForLb}};
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
WaitForAllBackends();
// Send kNumRpcs RPCs and count the drops.
size_t num_drops = 0;
@ -3495,7 +3483,7 @@ TEST_P(DropTest, Update) {
args.drop_categories = {{kLbDropType, kDropPerMillionForLb},
{kThrottleDropType, kDropPerMillionForThrottle}};
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// Wait until the drop rate increases to the middle of the two configs, which
// implies that the update has been in effect.
const double kDropRateThreshold =
@ -3553,7 +3541,7 @@ TEST_P(DropTest, DropAll) {
args.drop_categories = {{kLbDropType, kDropPerMillionForLb},
{kThrottleDropType, kDropPerMillionForThrottle}};
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// Send kNumRpcs RPCs and all of them are dropped.
for (size_t i = 0; i < kNumRpcs; ++i) {
EchoResponse response;
@ -3577,12 +3565,12 @@ TEST_P(BalancerUpdateTest, UpdateBalancersButKeepUsingOriginalBalancer) {
{"locality0", {backends_[0]->port()}},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
args = AdsServiceImpl::EdsResourceArgs({
{"locality0", {backends_[1]->port()}},
});
balancers_[1]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// Wait until the first backend is ready.
WaitForBackend(0);
// Send 10 requests.
@ -3632,12 +3620,12 @@ TEST_P(BalancerUpdateTest, Repeated) {
{"locality0", {backends_[0]->port()}},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
args = AdsServiceImpl::EdsResourceArgs({
{"locality0", {backends_[1]->port()}},
});
balancers_[1]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// Wait until the first backend is ready.
WaitForBackend(0);
// Send 10 requests.
@ -3698,12 +3686,12 @@ TEST_P(BalancerUpdateTest, DeadUpdate) {
{"locality0", {backends_[0]->port()}},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
args = AdsServiceImpl::EdsResourceArgs({
{"locality0", {backends_[1]->port()}},
});
balancers_[1]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// Start servers and send 10 RPCs per server.
gpr_log(GPR_INFO, "========= BEFORE FIRST BATCH ==========");
CheckRpcSendOk(10);
@ -3784,7 +3772,7 @@ TEST_P(ClientLoadReportingTest, Vanilla) {
{"locality0", GetBackendPorts()},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// Wait until all backends are ready.
int num_ok = 0;
int num_failure = 0;
@ -3829,7 +3817,7 @@ TEST_P(ClientLoadReportingTest, HonorsClustersRequestedByLrsServer) {
{"locality0", GetBackendPorts()},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// Wait until all backends are ready.
int num_ok = 0;
int num_failure = 0;
@ -3863,7 +3851,7 @@ TEST_P(ClientLoadReportingTest, BalancerRestart) {
{"locality0", GetBackendPorts(0, kNumBackendsFirstPass)},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// Wait until all backends returned by the balancer are ready.
int num_ok = 0;
int num_failure = 0;
@ -3901,7 +3889,7 @@ TEST_P(ClientLoadReportingTest, BalancerRestart) {
{"locality0", GetBackendPorts(kNumBackendsFirstPass)},
});
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
// Wait for queries to start going to one of the new backends.
// This tells us that we're now using the new serverlist.
std::tie(num_ok, num_failure, num_drops) =
@ -3943,7 +3931,7 @@ TEST_P(ClientLoadReportingWithDropTest, Vanilla) {
args.drop_categories = {{kLbDropType, kDropPerMillionForLb},
{kThrottleDropType, kDropPerMillionForThrottle}};
balancers_[0]->ads_service()->SetEdsResource(
AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName);
AdsServiceImpl::BuildEdsResource(args));
int num_ok = 0;
int num_failure = 0;
int num_drops = 0;

Loading…
Cancel
Save