|
|
|
@ -7314,7 +7314,6 @@ TEST_P(CdsTest, WrongLrsServer) { |
|
|
|
|
// Tests that ring hash policy that hashes using channel id ensures all RPCs
|
|
|
|
|
// to go 1 particular backend.
|
|
|
|
|
TEST_P(CdsTest, RingHashChannelIdHashing) { |
|
|
|
|
gpr_setenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH", "true"); |
|
|
|
|
auto cluster = default_cluster_; |
|
|
|
|
cluster.set_lb_policy(Cluster::RING_HASH); |
|
|
|
|
balancers_[0]->ads_service()->SetCdsResource(cluster); |
|
|
|
@ -7340,13 +7339,11 @@ TEST_P(CdsTest, RingHashChannelIdHashing) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
EXPECT_TRUE(found); |
|
|
|
|
gpr_unsetenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Tests that ring hash policy that hashes using a header value can spread
|
|
|
|
|
// RPCs across all the backends.
|
|
|
|
|
TEST_P(CdsTest, RingHashHeaderHashing) { |
|
|
|
|
gpr_setenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH", "true"); |
|
|
|
|
auto cluster = default_cluster_; |
|
|
|
|
cluster.set_lb_policy(Cluster::RING_HASH); |
|
|
|
|
balancers_[0]->ads_service()->SetCdsResource(cluster); |
|
|
|
@ -7387,13 +7384,11 @@ TEST_P(CdsTest, RingHashHeaderHashing) { |
|
|
|
|
for (size_t i = 0; i < backends_.size(); ++i) { |
|
|
|
|
EXPECT_EQ(100, backends_[i]->backend_service()->request_count()); |
|
|
|
|
} |
|
|
|
|
gpr_unsetenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Tests that ring hash policy that hashes using a header value and regex
|
|
|
|
|
// rewrite to aggregate RPCs to 1 backend.
|
|
|
|
|
TEST_P(CdsTest, RingHashHeaderHashingWithRegexRewrite) { |
|
|
|
|
gpr_setenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH", "true"); |
|
|
|
|
auto cluster = default_cluster_; |
|
|
|
|
cluster.set_lb_policy(Cluster::RING_HASH); |
|
|
|
|
balancers_[0]->ads_service()->SetCdsResource(cluster); |
|
|
|
@ -7440,12 +7435,10 @@ TEST_P(CdsTest, RingHashHeaderHashingWithRegexRewrite) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
EXPECT_TRUE(found); |
|
|
|
|
gpr_unsetenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Tests that ring hash policy that hashes using a random value.
|
|
|
|
|
TEST_P(CdsTest, RingHashNoHashPolicy) { |
|
|
|
|
gpr_setenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH", "true"); |
|
|
|
|
const double kDistribution50Percent = 0.5; |
|
|
|
|
const double kErrorTolerance = 0.05; |
|
|
|
|
const uint32_t kRpcTimeoutMs = 10000; |
|
|
|
@ -7473,13 +7466,11 @@ TEST_P(CdsTest, RingHashNoHashPolicy) { |
|
|
|
|
::testing::DoubleNear(kDistribution50Percent, kErrorTolerance)); |
|
|
|
|
EXPECT_THAT(static_cast<double>(request_count_2) / kNumRpcs, |
|
|
|
|
::testing::DoubleNear(kDistribution50Percent, kErrorTolerance)); |
|
|
|
|
gpr_unsetenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Test that ring hash policy evaluation will continue past the terminal
|
|
|
|
|
// policy if no results are produced yet.
|
|
|
|
|
TEST_P(CdsTest, RingHashContinuesPastTerminalPolicyThatDoesNotProduceResult) { |
|
|
|
|
gpr_setenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH", "true"); |
|
|
|
|
auto cluster = default_cluster_; |
|
|
|
|
cluster.set_lb_policy(Cluster::RING_HASH); |
|
|
|
|
balancers_[0]->ads_service()->SetCdsResource(cluster); |
|
|
|
@ -7502,13 +7493,11 @@ TEST_P(CdsTest, RingHashContinuesPastTerminalPolicyThatDoesNotProduceResult) { |
|
|
|
|
CheckRpcSendOk(100, rpc_options); |
|
|
|
|
EXPECT_EQ(backends_[0]->backend_service()->request_count(), 100); |
|
|
|
|
EXPECT_EQ(backends_[1]->backend_service()->request_count(), 0); |
|
|
|
|
gpr_unsetenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Test random hash is used when header hashing specified a header field that
|
|
|
|
|
// the RPC did not have.
|
|
|
|
|
TEST_P(CdsTest, RingHashOnHeaderThatIsNotPresent) { |
|
|
|
|
gpr_setenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH", "true"); |
|
|
|
|
const double kDistribution50Percent = 0.5; |
|
|
|
|
const double kErrorTolerance = 0.05; |
|
|
|
|
const uint32_t kRpcTimeoutMs = 10000; |
|
|
|
@ -7545,13 +7534,11 @@ TEST_P(CdsTest, RingHashOnHeaderThatIsNotPresent) { |
|
|
|
|
::testing::DoubleNear(kDistribution50Percent, kErrorTolerance)); |
|
|
|
|
EXPECT_THAT(static_cast<double>(request_count_2) / kNumRpcs, |
|
|
|
|
::testing::DoubleNear(kDistribution50Percent, kErrorTolerance)); |
|
|
|
|
gpr_unsetenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Test random hash is used when only unsupported hash policies are
|
|
|
|
|
// configured.
|
|
|
|
|
TEST_P(CdsTest, RingHashUnsupportedHashPolicyDefaultToRandomHashing) { |
|
|
|
|
gpr_setenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH", "true"); |
|
|
|
|
const double kDistribution50Percent = 0.5; |
|
|
|
|
const double kErrorTolerance = 0.05; |
|
|
|
|
const uint32_t kRpcTimeoutMs = 10000; |
|
|
|
@ -7590,13 +7577,11 @@ TEST_P(CdsTest, RingHashUnsupportedHashPolicyDefaultToRandomHashing) { |
|
|
|
|
::testing::DoubleNear(kDistribution50Percent, kErrorTolerance)); |
|
|
|
|
EXPECT_THAT(static_cast<double>(request_count_2) / kNumRpcs, |
|
|
|
|
::testing::DoubleNear(kDistribution50Percent, kErrorTolerance)); |
|
|
|
|
gpr_unsetenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Tests that ring hash policy that hashes using a random value can spread
|
|
|
|
|
// RPCs across all the backends according to locality weight.
|
|
|
|
|
TEST_P(CdsTest, RingHashRandomHashingDistributionAccordingToEndpointWeight) { |
|
|
|
|
gpr_setenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH", "true"); |
|
|
|
|
const size_t kWeight1 = 1; |
|
|
|
|
const size_t kWeight2 = 2; |
|
|
|
|
const size_t kWeightTotal = kWeight1 + kWeight2; |
|
|
|
@ -7632,14 +7617,12 @@ TEST_P(CdsTest, RingHashRandomHashingDistributionAccordingToEndpointWeight) { |
|
|
|
|
::testing::DoubleNear(kWeight33Percent, kErrorTolerance)); |
|
|
|
|
EXPECT_THAT(static_cast<double>(weight_66_request_count) / kNumRpcs, |
|
|
|
|
::testing::DoubleNear(kWeight66Percent, kErrorTolerance)); |
|
|
|
|
gpr_unsetenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Tests that ring hash policy that hashes using a random value can spread
|
|
|
|
|
// RPCs across all the backends according to locality weight.
|
|
|
|
|
TEST_P(CdsTest, |
|
|
|
|
RingHashRandomHashingDistributionAccordingToLocalityAndEndpointWeight) { |
|
|
|
|
gpr_setenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH", "true"); |
|
|
|
|
const size_t kWeight1 = 1 * 1; |
|
|
|
|
const size_t kWeight2 = 2 * 2; |
|
|
|
|
const size_t kWeightTotal = kWeight1 + kWeight2; |
|
|
|
@ -7674,7 +7657,6 @@ TEST_P(CdsTest, |
|
|
|
|
::testing::DoubleNear(kWeight20Percent, kErrorTolerance)); |
|
|
|
|
EXPECT_THAT(static_cast<double>(weight_80_request_count) / kNumRpcs, |
|
|
|
|
::testing::DoubleNear(kWeight80Percent, kErrorTolerance)); |
|
|
|
|
gpr_unsetenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Tests round robin is not implacted by the endpoint weight, and that the
|
|
|
|
@ -7724,7 +7706,6 @@ TEST_P(CdsTest, RingHashEndpointWeightDoesNotImpactWeightedRoundRobin) { |
|
|
|
|
// RPCs to go 1 particular backend; and that subsequent hashing policies are
|
|
|
|
|
// ignored due to the setting of terminal.
|
|
|
|
|
TEST_P(CdsTest, RingHashFixedHashingTerminalPolicy) { |
|
|
|
|
gpr_setenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH", "true"); |
|
|
|
|
auto cluster = default_cluster_; |
|
|
|
|
cluster.set_lb_policy(Cluster::RING_HASH); |
|
|
|
|
balancers_[0]->ads_service()->SetCdsResource(cluster); |
|
|
|
@ -7758,14 +7739,12 @@ TEST_P(CdsTest, RingHashFixedHashingTerminalPolicy) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
EXPECT_TRUE(found); |
|
|
|
|
gpr_unsetenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Test that the channel will go from idle to ready via connecting;
|
|
|
|
|
// (tho it is not possible to catch the connecting state before moving to
|
|
|
|
|
// ready)
|
|
|
|
|
TEST_P(CdsTest, RingHashIdleToReady) { |
|
|
|
|
gpr_setenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH", "true"); |
|
|
|
|
auto cluster = default_cluster_; |
|
|
|
|
cluster.set_lb_policy(Cluster::RING_HASH); |
|
|
|
|
balancers_[0]->ads_service()->SetCdsResource(cluster); |
|
|
|
@ -7783,13 +7762,11 @@ TEST_P(CdsTest, RingHashIdleToReady) { |
|
|
|
|
EXPECT_EQ(GRPC_CHANNEL_IDLE, channel_->GetState(false)); |
|
|
|
|
CheckRpcSendOk(); |
|
|
|
|
EXPECT_EQ(GRPC_CHANNEL_READY, channel_->GetState(false)); |
|
|
|
|
gpr_unsetenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Test that when the first pick is down leading to a transient failure, we
|
|
|
|
|
// will move on to the next ring hash entry.
|
|
|
|
|
TEST_P(CdsTest, RingHashTransientFailureCheckNextOne) { |
|
|
|
|
gpr_setenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH", "true"); |
|
|
|
|
auto cluster = default_cluster_; |
|
|
|
|
cluster.set_lb_policy(Cluster::RING_HASH); |
|
|
|
|
balancers_[0]->ads_service()->SetCdsResource(cluster); |
|
|
|
@ -7816,14 +7793,12 @@ TEST_P(CdsTest, RingHashTransientFailureCheckNextOne) { |
|
|
|
|
CheckRpcSendOk(100, rpc_options); |
|
|
|
|
EXPECT_EQ(0, backends_[0]->backend_service()->request_count()); |
|
|
|
|
EXPECT_EQ(100, backends_[1]->backend_service()->request_count()); |
|
|
|
|
gpr_unsetenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Test that when a backend goes down, we will move on to the next subchannel
|
|
|
|
|
// (with a lower priority). When the backend comes back up, traffic will move
|
|
|
|
|
// back.
|
|
|
|
|
TEST_P(CdsTest, RingHashSwitchToLowerPrioirtyAndThenBack) { |
|
|
|
|
gpr_setenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH", "true"); |
|
|
|
|
auto cluster = default_cluster_; |
|
|
|
|
cluster.set_lb_policy(Cluster::RING_HASH); |
|
|
|
|
balancers_[0]->ads_service()->SetCdsResource(cluster); |
|
|
|
@ -7853,12 +7828,10 @@ TEST_P(CdsTest, RingHashSwitchToLowerPrioirtyAndThenBack) { |
|
|
|
|
CheckRpcSendOk(100, rpc_options); |
|
|
|
|
EXPECT_EQ(100, backends_[0]->backend_service()->request_count()); |
|
|
|
|
EXPECT_EQ(0, backends_[1]->backend_service()->request_count()); |
|
|
|
|
gpr_unsetenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Test that when all backends are down, we will keep reattempting.
|
|
|
|
|
TEST_P(CdsTest, RingHashAllFailReattempt) { |
|
|
|
|
gpr_setenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH", "true"); |
|
|
|
|
const uint32_t kConnectionTimeoutMilliseconds = 5000; |
|
|
|
|
auto cluster = default_cluster_; |
|
|
|
|
cluster.set_lb_policy(Cluster::RING_HASH); |
|
|
|
@ -7887,13 +7860,11 @@ TEST_P(CdsTest, RingHashAllFailReattempt) { |
|
|
|
|
// Ensure we are actively connecting without any traffic.
|
|
|
|
|
EXPECT_TRUE(channel_->WaitForConnected( |
|
|
|
|
grpc_timeout_milliseconds_to_deadline(kConnectionTimeoutMilliseconds))); |
|
|
|
|
gpr_unsetenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Test that when all backends are down and then up, we may pick a TF backend
|
|
|
|
|
// and we will then jump to ready backend.
|
|
|
|
|
TEST_P(CdsTest, RingHashTransientFailureSkipToAvailableReady) { |
|
|
|
|
gpr_setenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH", "true"); |
|
|
|
|
const uint32_t kConnectionTimeoutMilliseconds = 5000; |
|
|
|
|
auto cluster = default_cluster_; |
|
|
|
|
cluster.set_lb_policy(Cluster::RING_HASH); |
|
|
|
@ -7946,13 +7917,11 @@ TEST_P(CdsTest, RingHashTransientFailureSkipToAvailableReady) { |
|
|
|
|
EXPECT_TRUE(channel_->WaitForConnected( |
|
|
|
|
grpc_timeout_milliseconds_to_deadline(kConnectionTimeoutMilliseconds))); |
|
|
|
|
WaitForBackend(1, WaitForBackendOptions(), rpc_options); |
|
|
|
|
gpr_unsetenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Test unspported hash policy types are all ignored before a supported
|
|
|
|
|
// policy.
|
|
|
|
|
TEST_P(CdsTest, RingHashUnsupportedHashPolicyUntilChannelIdHashing) { |
|
|
|
|
gpr_setenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH", "true"); |
|
|
|
|
auto cluster = default_cluster_; |
|
|
|
|
cluster.set_lb_policy(Cluster::RING_HASH); |
|
|
|
|
balancers_[0]->ads_service()->SetCdsResource(cluster); |
|
|
|
@ -7986,13 +7955,11 @@ TEST_P(CdsTest, RingHashUnsupportedHashPolicyUntilChannelIdHashing) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
EXPECT_TRUE(found); |
|
|
|
|
gpr_unsetenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Test we nack when ring hash policy has invalid hash function (something
|
|
|
|
|
// other than XX_HASH.
|
|
|
|
|
TEST_P(CdsTest, RingHashPolicyHasInvalidHashFunction) { |
|
|
|
|
gpr_setenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH", "true"); |
|
|
|
|
auto cluster = default_cluster_; |
|
|
|
|
cluster.set_lb_policy(Cluster::RING_HASH); |
|
|
|
|
cluster.mutable_ring_hash_lb_config()->set_hash_function( |
|
|
|
@ -8016,12 +7983,10 @@ TEST_P(CdsTest, RingHashPolicyHasInvalidHashFunction) { |
|
|
|
|
EXPECT_THAT( |
|
|
|
|
response_state.error_message, |
|
|
|
|
::testing::HasSubstr("ring hash lb config has invalid hash function.")); |
|
|
|
|
gpr_unsetenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Test we nack when ring hash policy has invalid ring size.
|
|
|
|
|
TEST_P(CdsTest, RingHashPolicyHasInvalidMinimumRingSize) { |
|
|
|
|
gpr_setenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH", "true"); |
|
|
|
|
auto cluster = default_cluster_; |
|
|
|
|
cluster.set_lb_policy(Cluster::RING_HASH); |
|
|
|
|
cluster.mutable_ring_hash_lb_config()->mutable_minimum_ring_size()->set_value( |
|
|
|
@ -8045,12 +8010,10 @@ TEST_P(CdsTest, RingHashPolicyHasInvalidMinimumRingSize) { |
|
|
|
|
EXPECT_THAT(response_state.error_message, |
|
|
|
|
::testing::HasSubstr( |
|
|
|
|
"min_ring_size is not in the range of 1 to 8388608.")); |
|
|
|
|
gpr_unsetenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Test we nack when ring hash policy has invalid ring size.
|
|
|
|
|
TEST_P(CdsTest, RingHashPolicyHasInvalidMaxmumRingSize) { |
|
|
|
|
gpr_setenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH", "true"); |
|
|
|
|
auto cluster = default_cluster_; |
|
|
|
|
cluster.set_lb_policy(Cluster::RING_HASH); |
|
|
|
|
cluster.mutable_ring_hash_lb_config()->mutable_maximum_ring_size()->set_value( |
|
|
|
@ -8074,12 +8037,10 @@ TEST_P(CdsTest, RingHashPolicyHasInvalidMaxmumRingSize) { |
|
|
|
|
EXPECT_THAT(response_state.error_message, |
|
|
|
|
::testing::HasSubstr( |
|
|
|
|
"max_ring_size is not in the range of 1 to 8388608.")); |
|
|
|
|
gpr_unsetenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Test we nack when ring hash policy has invalid ring size.
|
|
|
|
|
TEST_P(CdsTest, RingHashPolicyHasInvalidRingSizeMinGreaterThanMax) { |
|
|
|
|
gpr_setenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH", "true"); |
|
|
|
|
auto cluster = default_cluster_; |
|
|
|
|
cluster.set_lb_policy(Cluster::RING_HASH); |
|
|
|
|
cluster.mutable_ring_hash_lb_config()->mutable_maximum_ring_size()->set_value( |
|
|
|
@ -8105,7 +8066,6 @@ TEST_P(CdsTest, RingHashPolicyHasInvalidRingSizeMinGreaterThanMax) { |
|
|
|
|
EXPECT_THAT(response_state.error_message, |
|
|
|
|
::testing::HasSubstr( |
|
|
|
|
"min_ring_size cannot be greater than max_ring_size.")); |
|
|
|
|
gpr_unsetenv("GRPC_XDS_EXPERIMENTAL_ENABLE_RING_HASH"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class XdsSecurityTest : public BasicTest { |
|
|
|
|