|
|
|
@ -35,7 +35,6 @@ |
|
|
|
|
#include <grpcpp/server_builder.h> |
|
|
|
|
|
|
|
|
|
#include "src/core/ext/filters/client_channel/backup_poller.h" |
|
|
|
|
#include "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h" |
|
|
|
|
#include "src/core/ext/filters/client_channel/parse_address.h" |
|
|
|
|
#include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h" |
|
|
|
|
#include "src/core/ext/filters/client_channel/server_address.h" |
|
|
|
@ -84,13 +83,6 @@ namespace grpc { |
|
|
|
|
namespace testing { |
|
|
|
|
namespace { |
|
|
|
|
|
|
|
|
|
constexpr char kDefaultServiceConfig[] = |
|
|
|
|
"{\n" |
|
|
|
|
" \"loadBalancingConfig\":[\n" |
|
|
|
|
" { \"grpclb\":{} }\n" |
|
|
|
|
" ]\n" |
|
|
|
|
"}"; |
|
|
|
|
|
|
|
|
|
template <typename ServiceType> |
|
|
|
|
class CountedService : public ServiceType { |
|
|
|
|
public: |
|
|
|
@ -522,10 +514,11 @@ class GrpclbEnd2endTest : public ::testing::Test { |
|
|
|
|
|
|
|
|
|
struct AddressData { |
|
|
|
|
int port; |
|
|
|
|
bool is_balancer; |
|
|
|
|
grpc::string balancer_name; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static grpc_core::ServerAddressList CreateLbAddressesFromAddressDataList( |
|
|
|
|
grpc_core::ServerAddressList CreateLbAddressesFromAddressDataList( |
|
|
|
|
const std::vector<AddressData>& address_data) { |
|
|
|
|
grpc_core::ServerAddressList addresses; |
|
|
|
|
for (const auto& addr : address_data) { |
|
|
|
@ -535,10 +528,16 @@ class GrpclbEnd2endTest : public ::testing::Test { |
|
|
|
|
GPR_ASSERT(lb_uri != nullptr); |
|
|
|
|
grpc_resolved_address address; |
|
|
|
|
GPR_ASSERT(grpc_parse_uri(lb_uri, &address)); |
|
|
|
|
grpc_arg arg = |
|
|
|
|
grpc_core::CreateGrpclbBalancerNameArg(addr.balancer_name.c_str()); |
|
|
|
|
grpc_channel_args* args = |
|
|
|
|
grpc_channel_args_copy_and_add(nullptr, &arg, 1); |
|
|
|
|
std::vector<grpc_arg> args_to_add; |
|
|
|
|
if (addr.is_balancer) { |
|
|
|
|
args_to_add.emplace_back(grpc_channel_arg_integer_create( |
|
|
|
|
const_cast<char*>(GRPC_ARG_ADDRESS_IS_BALANCER), 1)); |
|
|
|
|
args_to_add.emplace_back(grpc_channel_arg_string_create( |
|
|
|
|
const_cast<char*>(GRPC_ARG_ADDRESS_BALANCER_NAME), |
|
|
|
|
const_cast<char*>(addr.balancer_name.c_str()))); |
|
|
|
|
} |
|
|
|
|
grpc_channel_args* args = grpc_channel_args_copy_and_add( |
|
|
|
|
nullptr, args_to_add.data(), args_to_add.size()); |
|
|
|
|
addresses.emplace_back(address.addr, address.len, args); |
|
|
|
|
grpc_uri_destroy(lb_uri); |
|
|
|
|
gpr_free(lb_uri_str); |
|
|
|
@ -546,50 +545,34 @@ class GrpclbEnd2endTest : public ::testing::Test { |
|
|
|
|
return addresses; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static grpc_core::Resolver::Result MakeResolverResult( |
|
|
|
|
const std::vector<AddressData>& balancer_address_data, |
|
|
|
|
const std::vector<AddressData>& backend_address_data = {}, |
|
|
|
|
const char* service_config_json = kDefaultServiceConfig) { |
|
|
|
|
grpc_core::Resolver::Result result; |
|
|
|
|
result.addresses = |
|
|
|
|
CreateLbAddressesFromAddressDataList(backend_address_data); |
|
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
|
result.service_config = |
|
|
|
|
grpc_core::ServiceConfig::Create(service_config_json, &error); |
|
|
|
|
GPR_ASSERT(error == GRPC_ERROR_NONE); |
|
|
|
|
grpc_core::ServerAddressList balancer_addresses = |
|
|
|
|
CreateLbAddressesFromAddressDataList(balancer_address_data); |
|
|
|
|
grpc_arg arg = CreateGrpclbBalancerAddressesArg(&balancer_addresses); |
|
|
|
|
result.args = grpc_channel_args_copy_and_add(nullptr, &arg, 1); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SetNextResolutionAllBalancers( |
|
|
|
|
const char* service_config_json = kDefaultServiceConfig) { |
|
|
|
|
const char* service_config_json = nullptr) { |
|
|
|
|
std::vector<AddressData> addresses; |
|
|
|
|
for (size_t i = 0; i < balancers_.size(); ++i) { |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[i]->port_, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[i]->port_, true, ""}); |
|
|
|
|
} |
|
|
|
|
SetNextResolution(addresses, {}, service_config_json); |
|
|
|
|
SetNextResolution(addresses, service_config_json); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SetNextResolution( |
|
|
|
|
const std::vector<AddressData>& balancer_address_data, |
|
|
|
|
const std::vector<AddressData>& backend_address_data = {}, |
|
|
|
|
const char* service_config_json = kDefaultServiceConfig) { |
|
|
|
|
void SetNextResolution(const std::vector<AddressData>& address_data, |
|
|
|
|
const char* service_config_json = nullptr) { |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
grpc_core::Resolver::Result result = MakeResolverResult( |
|
|
|
|
balancer_address_data, backend_address_data, service_config_json); |
|
|
|
|
grpc_core::Resolver::Result result; |
|
|
|
|
result.addresses = CreateLbAddressesFromAddressDataList(address_data); |
|
|
|
|
if (service_config_json != nullptr) { |
|
|
|
|
grpc_error* error = GRPC_ERROR_NONE; |
|
|
|
|
result.service_config = |
|
|
|
|
grpc_core::ServiceConfig::Create(service_config_json, &error); |
|
|
|
|
GRPC_ERROR_UNREF(error); |
|
|
|
|
} |
|
|
|
|
response_generator_->SetResponse(std::move(result)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SetNextReresolutionResponse( |
|
|
|
|
const std::vector<AddressData>& balancer_address_data, |
|
|
|
|
const std::vector<AddressData>& backend_address_data = {}, |
|
|
|
|
const char* service_config_json = kDefaultServiceConfig) { |
|
|
|
|
const std::vector<AddressData>& address_data) { |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
grpc_core::Resolver::Result result = MakeResolverResult( |
|
|
|
|
balancer_address_data, backend_address_data, service_config_json); |
|
|
|
|
grpc_core::Resolver::Result result; |
|
|
|
|
result.addresses = CreateLbAddressesFromAddressDataList(address_data); |
|
|
|
|
response_generator_->SetReresolutionResponse(std::move(result)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -764,11 +747,44 @@ TEST_F(SingleBalancerTest, SelectGrpclbWithMigrationServiceConfig) { |
|
|
|
|
EXPECT_EQ("grpclb", channel_->GetLoadBalancingPolicyName()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(SingleBalancerTest, |
|
|
|
|
DoNotSpecialCaseUseGrpclbWithLoadBalancingConfigTest) { |
|
|
|
|
const int kFallbackTimeoutMs = 200 * grpc_test_slowdown_factor(); |
|
|
|
|
ResetStub(kFallbackTimeoutMs); |
|
|
|
|
SetNextResolution({AddressData{backends_[0]->port_, false, ""}, |
|
|
|
|
AddressData{balancers_[0]->port_, true, ""}}, |
|
|
|
|
"{\n" |
|
|
|
|
" \"loadBalancingConfig\":[\n" |
|
|
|
|
" {\"pick_first\":{} }\n" |
|
|
|
|
" ]\n" |
|
|
|
|
"}"); |
|
|
|
|
CheckRpcSendOk(); |
|
|
|
|
// Check LB policy name for the channel.
|
|
|
|
|
EXPECT_EQ("pick_first", channel_->GetLoadBalancingPolicyName()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F( |
|
|
|
|
SingleBalancerTest, |
|
|
|
|
DoNotSpecialCaseUseGrpclbWithLoadBalancingConfigTestAndNoBackendAddress) { |
|
|
|
|
const int kFallbackTimeoutMs = 200 * grpc_test_slowdown_factor(); |
|
|
|
|
ResetStub(kFallbackTimeoutMs); |
|
|
|
|
SetNextResolution({AddressData{balancers_[0]->port_, true, ""}}, |
|
|
|
|
"{\n" |
|
|
|
|
" \"loadBalancingConfig\":[\n" |
|
|
|
|
" {\"pick_first\":{} }\n" |
|
|
|
|
" ]\n" |
|
|
|
|
"}"); |
|
|
|
|
// This should fail since we do not have a non-balancer backend
|
|
|
|
|
CheckRpcSendFailure(); |
|
|
|
|
// Check LB policy name for the channel.
|
|
|
|
|
EXPECT_EQ("pick_first", channel_->GetLoadBalancingPolicyName()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(SingleBalancerTest, |
|
|
|
|
SelectGrpclbWithMigrationServiceConfigAndNoAddresses) { |
|
|
|
|
const int kFallbackTimeoutMs = 200 * grpc_test_slowdown_factor(); |
|
|
|
|
ResetStub(kFallbackTimeoutMs); |
|
|
|
|
SetNextResolution({}, {}, |
|
|
|
|
SetNextResolution({}, |
|
|
|
|
"{\n" |
|
|
|
|
" \"loadBalancingConfig\":[\n" |
|
|
|
|
" { \"does_not_exist\":{} },\n" |
|
|
|
@ -788,6 +804,23 @@ TEST_F(SingleBalancerTest, |
|
|
|
|
EXPECT_EQ("grpclb", channel_->GetLoadBalancingPolicyName()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(SingleBalancerTest, |
|
|
|
|
SelectGrpclbWithMigrationServiceConfigAndNoBalancerAddresses) { |
|
|
|
|
const int kFallbackTimeoutMs = 200 * grpc_test_slowdown_factor(); |
|
|
|
|
ResetStub(kFallbackTimeoutMs); |
|
|
|
|
// Resolution includes fallback address but no balancers.
|
|
|
|
|
SetNextResolution({AddressData{backends_[0]->port_, false, ""}}, |
|
|
|
|
"{\n" |
|
|
|
|
" \"loadBalancingConfig\":[\n" |
|
|
|
|
" { \"does_not_exist\":{} },\n" |
|
|
|
|
" { \"grpclb\":{} }\n" |
|
|
|
|
" ]\n" |
|
|
|
|
"}"); |
|
|
|
|
CheckRpcSendOk(1, 1000 /* timeout_ms */, true /* wait_for_ready */); |
|
|
|
|
// Check LB policy name for the channel.
|
|
|
|
|
EXPECT_EQ("grpclb", channel_->GetLoadBalancingPolicyName()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(SingleBalancerTest, UsePickFirstChildPolicy) { |
|
|
|
|
SetNextResolutionAllBalancers( |
|
|
|
|
"{\n" |
|
|
|
@ -842,7 +875,7 @@ TEST_F(SingleBalancerTest, SwapChildPolicy) { |
|
|
|
|
EXPECT_EQ(backends_[i]->service_.request_count(), 0UL); |
|
|
|
|
} |
|
|
|
|
// Send new resolution that removes child policy from service config.
|
|
|
|
|
SetNextResolutionAllBalancers(); |
|
|
|
|
SetNextResolutionAllBalancers("{}"); |
|
|
|
|
WaitForAllBackends(); |
|
|
|
|
CheckRpcSendOk(kNumRpcs, 1000 /* timeout_ms */, true /* wait_for_ready */); |
|
|
|
|
// Check that every backend saw the same number of requests. This verifies
|
|
|
|
@ -870,11 +903,9 @@ TEST_F(SingleBalancerTest, UpdatesGoToMostRecentChildPolicy) { |
|
|
|
|
SetNextResolution( |
|
|
|
|
{ |
|
|
|
|
// Unreachable balancer.
|
|
|
|
|
{unreachable_balancer_port, ""}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
{unreachable_balancer_port, true, ""}, |
|
|
|
|
// Fallback address: first backend.
|
|
|
|
|
{backends_[0]->port_, ""}, |
|
|
|
|
{backends_[0]->port_, false, ""}, |
|
|
|
|
}, |
|
|
|
|
"{\n" |
|
|
|
|
" \"loadBalancingConfig\":[\n" |
|
|
|
@ -892,11 +923,9 @@ TEST_F(SingleBalancerTest, UpdatesGoToMostRecentChildPolicy) { |
|
|
|
|
SetNextResolution( |
|
|
|
|
{ |
|
|
|
|
// Unreachable balancer.
|
|
|
|
|
{unreachable_balancer_port, ""}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
{unreachable_balancer_port, true, ""}, |
|
|
|
|
// Fallback address: unreachable backend.
|
|
|
|
|
{unreachable_backend_port, ""}, |
|
|
|
|
{unreachable_backend_port, false, ""}, |
|
|
|
|
}, |
|
|
|
|
"{\n" |
|
|
|
|
" \"loadBalancingConfig\":[\n" |
|
|
|
@ -917,12 +946,10 @@ TEST_F(SingleBalancerTest, UpdatesGoToMostRecentChildPolicy) { |
|
|
|
|
SetNextResolution( |
|
|
|
|
{ |
|
|
|
|
// Unreachable balancer.
|
|
|
|
|
{unreachable_balancer_port, ""}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
{unreachable_balancer_port, true, ""}, |
|
|
|
|
// Fallback address: second and third backends.
|
|
|
|
|
{backends_[1]->port_, ""}, |
|
|
|
|
{backends_[2]->port_, ""}, |
|
|
|
|
{backends_[1]->port_, false, ""}, |
|
|
|
|
{backends_[2]->port_, false, ""}, |
|
|
|
|
}, |
|
|
|
|
"{\n" |
|
|
|
|
" \"loadBalancingConfig\":[\n" |
|
|
|
@ -961,7 +988,7 @@ TEST_F(SingleBalancerTest, SameBackendListedMultipleTimes) { |
|
|
|
|
|
|
|
|
|
TEST_F(SingleBalancerTest, SecureNaming) { |
|
|
|
|
ResetStub(0, kApplicationTargetName_ + ";lb"); |
|
|
|
|
SetNextResolution({AddressData{balancers_[0]->port_, "lb"}}); |
|
|
|
|
SetNextResolution({AddressData{balancers_[0]->port_, true, "lb"}}); |
|
|
|
|
const size_t kNumRpcsPerAddress = 100; |
|
|
|
|
ScheduleResponseForBalancer( |
|
|
|
|
0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts(), {}), |
|
|
|
@ -993,7 +1020,7 @@ TEST_F(SingleBalancerTest, SecureNamingDeathTest) { |
|
|
|
|
ASSERT_DEATH_IF_SUPPORTED( |
|
|
|
|
{ |
|
|
|
|
ResetStub(0, kApplicationTargetName_ + ";lb"); |
|
|
|
|
SetNextResolution({AddressData{balancers_[0]->port_, "woops"}}); |
|
|
|
|
SetNextResolution({AddressData{balancers_[0]->port_, true, "woops"}}); |
|
|
|
|
channel_->WaitForConnected(grpc_timeout_seconds_to_deadline(1)); |
|
|
|
|
}, |
|
|
|
|
""); |
|
|
|
@ -1053,13 +1080,12 @@ TEST_F(SingleBalancerTest, Fallback) { |
|
|
|
|
const size_t kNumBackendsInResolution = backends_.size() / 2; |
|
|
|
|
|
|
|
|
|
ResetStub(kFallbackTimeoutMs); |
|
|
|
|
std::vector<AddressData> balancer_addresses; |
|
|
|
|
balancer_addresses.emplace_back(AddressData{balancers_[0]->port_, ""}); |
|
|
|
|
std::vector<AddressData> backend_addresses; |
|
|
|
|
std::vector<AddressData> addresses; |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[0]->port_, true, ""}); |
|
|
|
|
for (size_t i = 0; i < kNumBackendsInResolution; ++i) { |
|
|
|
|
backend_addresses.emplace_back(AddressData{backends_[i]->port_, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{backends_[i]->port_, false, ""}); |
|
|
|
|
} |
|
|
|
|
SetNextResolution(balancer_addresses, backend_addresses); |
|
|
|
|
SetNextResolution(addresses); |
|
|
|
|
|
|
|
|
|
// Send non-empty serverlist only after kServerlistDelayMs.
|
|
|
|
|
ScheduleResponseForBalancer( |
|
|
|
@ -1122,13 +1148,12 @@ TEST_F(SingleBalancerTest, FallbackUpdate) { |
|
|
|
|
const size_t kNumBackendsInResolutionUpdate = backends_.size() / 3; |
|
|
|
|
|
|
|
|
|
ResetStub(kFallbackTimeoutMs); |
|
|
|
|
std::vector<AddressData> balancer_addresses; |
|
|
|
|
balancer_addresses.emplace_back(AddressData{balancers_[0]->port_, ""}); |
|
|
|
|
std::vector<AddressData> backend_addresses; |
|
|
|
|
std::vector<AddressData> addresses; |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[0]->port_, true, ""}); |
|
|
|
|
for (size_t i = 0; i < kNumBackendsInResolution; ++i) { |
|
|
|
|
backend_addresses.emplace_back(AddressData{backends_[i]->port_, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{backends_[i]->port_, false, ""}); |
|
|
|
|
} |
|
|
|
|
SetNextResolution(balancer_addresses, backend_addresses); |
|
|
|
|
SetNextResolution(addresses); |
|
|
|
|
|
|
|
|
|
// Send non-empty serverlist only after kServerlistDelayMs.
|
|
|
|
|
ScheduleResponseForBalancer( |
|
|
|
@ -1158,14 +1183,13 @@ TEST_F(SingleBalancerTest, FallbackUpdate) { |
|
|
|
|
EXPECT_EQ(0U, backends_[i]->service_.request_count()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
balancer_addresses.clear(); |
|
|
|
|
balancer_addresses.emplace_back(AddressData{balancers_[0]->port_, ""}); |
|
|
|
|
backend_addresses.clear(); |
|
|
|
|
addresses.clear(); |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[0]->port_, true, ""}); |
|
|
|
|
for (size_t i = kNumBackendsInResolution; |
|
|
|
|
i < kNumBackendsInResolution + kNumBackendsInResolutionUpdate; ++i) { |
|
|
|
|
backend_addresses.emplace_back(AddressData{backends_[i]->port_, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{backends_[i]->port_, false, ""}); |
|
|
|
|
} |
|
|
|
|
SetNextResolution(balancer_addresses, backend_addresses); |
|
|
|
|
SetNextResolution(addresses); |
|
|
|
|
|
|
|
|
|
// Wait until the resolution update has been processed and all the new
|
|
|
|
|
// fallback backends are reachable.
|
|
|
|
@ -1229,15 +1253,14 @@ TEST_F(SingleBalancerTest, |
|
|
|
|
// First two backends are fallback, last two are pointed to by balancer.
|
|
|
|
|
const size_t kNumFallbackBackends = 2; |
|
|
|
|
const size_t kNumBalancerBackends = backends_.size() - kNumFallbackBackends; |
|
|
|
|
std::vector<AddressData> backend_addresses; |
|
|
|
|
std::vector<AddressData> addresses; |
|
|
|
|
for (size_t i = 0; i < kNumFallbackBackends; ++i) { |
|
|
|
|
backend_addresses.emplace_back(AddressData{backends_[i]->port_, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{backends_[i]->port_, false, ""}); |
|
|
|
|
} |
|
|
|
|
std::vector<AddressData> balancer_addresses; |
|
|
|
|
for (size_t i = 0; i < balancers_.size(); ++i) { |
|
|
|
|
balancer_addresses.emplace_back(AddressData{balancers_[i]->port_, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[i]->port_, true, ""}); |
|
|
|
|
} |
|
|
|
|
SetNextResolution(balancer_addresses, backend_addresses); |
|
|
|
|
SetNextResolution(addresses); |
|
|
|
|
ScheduleResponseForBalancer(0, |
|
|
|
|
BalancerServiceImpl::BuildResponseForBackends( |
|
|
|
|
GetBackendPorts(kNumFallbackBackends), {}), |
|
|
|
@ -1284,15 +1307,14 @@ TEST_F(SingleBalancerTest, |
|
|
|
|
// First two backends are fallback, last two are pointed to by balancer.
|
|
|
|
|
const size_t kNumFallbackBackends = 2; |
|
|
|
|
const size_t kNumBalancerBackends = backends_.size() - kNumFallbackBackends; |
|
|
|
|
std::vector<AddressData> backend_addresses; |
|
|
|
|
std::vector<AddressData> addresses; |
|
|
|
|
for (size_t i = 0; i < kNumFallbackBackends; ++i) { |
|
|
|
|
backend_addresses.emplace_back(AddressData{backends_[i]->port_, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{backends_[i]->port_, false, ""}); |
|
|
|
|
} |
|
|
|
|
std::vector<AddressData> balancer_addresses; |
|
|
|
|
for (size_t i = 0; i < balancers_.size(); ++i) { |
|
|
|
|
balancer_addresses.emplace_back(AddressData{balancers_[i]->port_, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[i]->port_, true, ""}); |
|
|
|
|
} |
|
|
|
|
SetNextResolution(balancer_addresses, backend_addresses); |
|
|
|
|
SetNextResolution(addresses); |
|
|
|
|
ScheduleResponseForBalancer(0, |
|
|
|
|
BalancerServiceImpl::BuildResponseForBackends( |
|
|
|
|
GetBackendPorts(kNumFallbackBackends), {}), |
|
|
|
@ -1336,12 +1358,10 @@ TEST_F(SingleBalancerTest, FallbackEarlyWhenBalancerChannelFails) { |
|
|
|
|
const int kFallbackTimeoutMs = 10000 * grpc_test_slowdown_factor(); |
|
|
|
|
ResetStub(kFallbackTimeoutMs); |
|
|
|
|
// Return an unreachable balancer and one fallback backend.
|
|
|
|
|
std::vector<AddressData> balancer_addresses; |
|
|
|
|
balancer_addresses.emplace_back( |
|
|
|
|
AddressData{grpc_pick_unused_port_or_die(), ""}); |
|
|
|
|
std::vector<AddressData> backend_addresses; |
|
|
|
|
backend_addresses.emplace_back(AddressData{backends_[0]->port_, ""}); |
|
|
|
|
SetNextResolution(balancer_addresses, backend_addresses); |
|
|
|
|
std::vector<AddressData> addresses; |
|
|
|
|
addresses.emplace_back(AddressData{grpc_pick_unused_port_or_die(), true, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{backends_[0]->port_, false, ""}); |
|
|
|
|
SetNextResolution(addresses); |
|
|
|
|
// Send RPC with deadline less than the fallback timeout and make sure it
|
|
|
|
|
// succeeds.
|
|
|
|
|
CheckRpcSendOk(/* times */ 1, /* timeout_ms */ 1000, |
|
|
|
@ -1352,11 +1372,10 @@ TEST_F(SingleBalancerTest, FallbackEarlyWhenBalancerCallFails) { |
|
|
|
|
const int kFallbackTimeoutMs = 10000 * grpc_test_slowdown_factor(); |
|
|
|
|
ResetStub(kFallbackTimeoutMs); |
|
|
|
|
// Return one balancer and one fallback backend.
|
|
|
|
|
std::vector<AddressData> balancer_addresses; |
|
|
|
|
balancer_addresses.emplace_back(AddressData{balancers_[0]->port_, ""}); |
|
|
|
|
std::vector<AddressData> backend_addresses; |
|
|
|
|
backend_addresses.emplace_back(AddressData{backends_[0]->port_, ""}); |
|
|
|
|
SetNextResolution(balancer_addresses, backend_addresses); |
|
|
|
|
std::vector<AddressData> addresses; |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[0]->port_, true, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{backends_[0]->port_, false, ""}); |
|
|
|
|
SetNextResolution(addresses); |
|
|
|
|
// Balancer drops call without sending a serverlist.
|
|
|
|
|
balancers_[0]->service_.NotifyDoneWithServerlists(); |
|
|
|
|
// Send RPC with deadline less than the fallback timeout and make sure it
|
|
|
|
@ -1369,11 +1388,10 @@ TEST_F(SingleBalancerTest, FallbackControlledByBalancer_BeforeFirstServerlist) { |
|
|
|
|
const int kFallbackTimeoutMs = 10000 * grpc_test_slowdown_factor(); |
|
|
|
|
ResetStub(kFallbackTimeoutMs); |
|
|
|
|
// Return one balancer and one fallback backend.
|
|
|
|
|
std::vector<AddressData> balancer_addresses; |
|
|
|
|
balancer_addresses.emplace_back(AddressData{balancers_[0]->port_, ""}); |
|
|
|
|
std::vector<AddressData> backend_addresses; |
|
|
|
|
backend_addresses.emplace_back(AddressData{backends_[0]->port_, ""}); |
|
|
|
|
SetNextResolution(balancer_addresses, backend_addresses); |
|
|
|
|
std::vector<AddressData> addresses; |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[0]->port_, true, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{backends_[0]->port_, false, ""}); |
|
|
|
|
SetNextResolution(addresses); |
|
|
|
|
// Balancer explicitly tells client to fallback.
|
|
|
|
|
LoadBalanceResponse resp; |
|
|
|
|
resp.mutable_fallback_response(); |
|
|
|
@ -1386,11 +1404,10 @@ TEST_F(SingleBalancerTest, FallbackControlledByBalancer_BeforeFirstServerlist) { |
|
|
|
|
|
|
|
|
|
TEST_F(SingleBalancerTest, FallbackControlledByBalancer_AfterFirstServerlist) { |
|
|
|
|
// Return one balancer and one fallback backend (backend 0).
|
|
|
|
|
std::vector<AddressData> balancer_addresses; |
|
|
|
|
balancer_addresses.emplace_back(AddressData{balancers_[0]->port_, ""}); |
|
|
|
|
std::vector<AddressData> backend_addresses; |
|
|
|
|
backend_addresses.emplace_back(AddressData{backends_[0]->port_, ""}); |
|
|
|
|
SetNextResolution(balancer_addresses, backend_addresses); |
|
|
|
|
std::vector<AddressData> addresses; |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[0]->port_, true, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{backends_[0]->port_, false, ""}); |
|
|
|
|
SetNextResolution(addresses); |
|
|
|
|
// Balancer initially sends serverlist, then tells client to fall back,
|
|
|
|
|
// then sends the serverlist again.
|
|
|
|
|
// The serverlist points to backend 1.
|
|
|
|
@ -1466,7 +1483,7 @@ TEST_F(UpdatesTest, UpdateBalancersButKeepUsingOriginalBalancer) { |
|
|
|
|
EXPECT_EQ(0U, balancers_[2]->service_.response_count()); |
|
|
|
|
|
|
|
|
|
std::vector<AddressData> addresses; |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[1]->port_, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[1]->port_, true, ""}); |
|
|
|
|
gpr_log(GPR_INFO, "========= ABOUT TO UPDATE 1 =========="); |
|
|
|
|
SetNextResolution(addresses); |
|
|
|
|
gpr_log(GPR_INFO, "========= UPDATE 1 DONE =========="); |
|
|
|
@ -1525,9 +1542,9 @@ TEST_F(UpdatesTest, UpdateBalancersRepeated) { |
|
|
|
|
EXPECT_EQ(0U, balancers_[2]->service_.response_count()); |
|
|
|
|
|
|
|
|
|
std::vector<AddressData> addresses; |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[0]->port_, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[1]->port_, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[2]->port_, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[0]->port_, true, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[1]->port_, true, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[2]->port_, true, ""}); |
|
|
|
|
gpr_log(GPR_INFO, "========= ABOUT TO UPDATE 1 =========="); |
|
|
|
|
SetNextResolution(addresses); |
|
|
|
|
gpr_log(GPR_INFO, "========= UPDATE 1 DONE =========="); |
|
|
|
@ -1545,8 +1562,8 @@ TEST_F(UpdatesTest, UpdateBalancersRepeated) { |
|
|
|
|
balancers_[0]->service_.NotifyDoneWithServerlists(); |
|
|
|
|
|
|
|
|
|
addresses.clear(); |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[0]->port_, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[1]->port_, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[0]->port_, true, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[1]->port_, true, ""}); |
|
|
|
|
gpr_log(GPR_INFO, "========= ABOUT TO UPDATE 2 =========="); |
|
|
|
|
SetNextResolution(addresses); |
|
|
|
|
gpr_log(GPR_INFO, "========= UPDATE 2 DONE =========="); |
|
|
|
@ -1566,7 +1583,7 @@ TEST_F(UpdatesTest, UpdateBalancersRepeated) { |
|
|
|
|
|
|
|
|
|
TEST_F(UpdatesTest, UpdateBalancersDeadUpdate) { |
|
|
|
|
std::vector<AddressData> addresses; |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[0]->port_, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[0]->port_, true, ""}); |
|
|
|
|
SetNextResolution(addresses); |
|
|
|
|
const std::vector<int> first_backend{GetBackendPorts()[0]}; |
|
|
|
|
const std::vector<int> second_backend{GetBackendPorts()[1]}; |
|
|
|
@ -1606,7 +1623,7 @@ TEST_F(UpdatesTest, UpdateBalancersDeadUpdate) { |
|
|
|
|
EXPECT_EQ(0U, balancers_[2]->service_.response_count()); |
|
|
|
|
|
|
|
|
|
addresses.clear(); |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[1]->port_, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[1]->port_, true, ""}); |
|
|
|
|
gpr_log(GPR_INFO, "========= ABOUT TO UPDATE 1 =========="); |
|
|
|
|
SetNextResolution(addresses); |
|
|
|
|
gpr_log(GPR_INFO, "========= UPDATE 1 DONE =========="); |
|
|
|
@ -1643,20 +1660,18 @@ TEST_F(UpdatesTest, ReresolveDeadBackend) { |
|
|
|
|
ResetStub(500); |
|
|
|
|
// The first resolution contains the addresses of a balancer that never
|
|
|
|
|
// responds, and a fallback backend.
|
|
|
|
|
std::vector<AddressData> balancer_addresses; |
|
|
|
|
balancer_addresses.emplace_back(AddressData{balancers_[0]->port_, ""}); |
|
|
|
|
std::vector<AddressData> backend_addresses; |
|
|
|
|
backend_addresses.emplace_back(AddressData{backends_[0]->port_, ""}); |
|
|
|
|
SetNextResolution(balancer_addresses, backend_addresses); |
|
|
|
|
std::vector<AddressData> addresses; |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[0]->port_, true, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{backends_[0]->port_, false, ""}); |
|
|
|
|
SetNextResolution(addresses); |
|
|
|
|
// Ask channel to connect to trigger resolver creation.
|
|
|
|
|
channel_->GetState(true); |
|
|
|
|
// The re-resolution result will contain the addresses of the same balancer
|
|
|
|
|
// and a new fallback backend.
|
|
|
|
|
balancer_addresses.clear(); |
|
|
|
|
balancer_addresses.emplace_back(AddressData{balancers_[0]->port_, ""}); |
|
|
|
|
backend_addresses.clear(); |
|
|
|
|
backend_addresses.emplace_back(AddressData{backends_[1]->port_, ""}); |
|
|
|
|
SetNextReresolutionResponse(balancer_addresses, backend_addresses); |
|
|
|
|
addresses.clear(); |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[0]->port_, true, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{backends_[1]->port_, false, ""}); |
|
|
|
|
SetNextReresolutionResponse(addresses); |
|
|
|
|
|
|
|
|
|
// Start servers and send 10 RPCs per server.
|
|
|
|
|
gpr_log(GPR_INFO, "========= BEFORE FIRST BATCH =========="); |
|
|
|
@ -1705,10 +1720,10 @@ TEST_F(UpdatesWithClientLoadReportingTest, ReresolveDeadBalancer) { |
|
|
|
|
// Ask channel to connect to trigger resolver creation.
|
|
|
|
|
channel_->GetState(true); |
|
|
|
|
std::vector<AddressData> addresses; |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[0]->port_, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[0]->port_, true, ""}); |
|
|
|
|
SetNextResolution(addresses); |
|
|
|
|
addresses.clear(); |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[1]->port_, ""}); |
|
|
|
|
addresses.emplace_back(AddressData{balancers_[1]->port_, true, ""}); |
|
|
|
|
SetNextReresolutionResponse(addresses); |
|
|
|
|
const std::vector<int> first_backend{GetBackendPorts()[0]}; |
|
|
|
|
const std::vector<int> second_backend{GetBackendPorts()[1]}; |
|
|
|
|