diff --git a/CMakeLists.txt b/CMakeLists.txt index ba7c114ecea..0a684bf94f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2087,6 +2087,7 @@ add_library(grpc_test_util test/core/util/port_isolated_runtime_environment.cc test/core/util/port_server_client.cc test/core/util/reconnect_server.cc + test/core/util/resolve_localhost_ip46.cc test/core/util/slice_splitter.cc test/core/util/subprocess_posix.cc test/core/util/subprocess_windows.cc @@ -2158,6 +2159,7 @@ add_library(grpc_test_util_unsecure test/core/util/port_isolated_runtime_environment.cc test/core/util/port_server_client.cc test/core/util/reconnect_server.cc + test/core/util/resolve_localhost_ip46.cc test/core/util/slice_splitter.cc test/core/util/subprocess_posix.cc test/core/util/subprocess_windows.cc @@ -15072,6 +15074,7 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) test/core/util/port_isolated_runtime_environment.cc test/core/util/port_server_client.cc test/core/util/reconnect_server.cc + test/core/util/resolve_localhost_ip46.cc test/core/util/slice_splitter.cc test/core/util/subprocess_posix.cc test/core/util/subprocess_windows.cc diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 06b09792502..6ed671d6316 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -1416,6 +1416,7 @@ libs: - test/core/util/port.h - test/core/util/port_server_client.h - test/core/util/reconnect_server.h + - test/core/util/resolve_localhost_ip46.h - test/core/util/slice_splitter.h - test/core/util/subprocess.h - test/core/util/test_config.h @@ -1438,6 +1439,7 @@ libs: - test/core/util/port_isolated_runtime_environment.cc - test/core/util/port_server_client.cc - test/core/util/reconnect_server.cc + - test/core/util/resolve_localhost_ip46.cc - test/core/util/slice_splitter.cc - test/core/util/subprocess_posix.cc - test/core/util/subprocess_windows.cc @@ -1472,6 +1474,7 @@ libs: - test/core/util/port.h - test/core/util/port_server_client.h - test/core/util/reconnect_server.h + - test/core/util/resolve_localhost_ip46.h - test/core/util/slice_splitter.h - test/core/util/subprocess.h - test/core/util/test_config.h @@ -1494,6 +1497,7 @@ libs: - test/core/util/port_isolated_runtime_environment.cc - test/core/util/port_server_client.cc - test/core/util/reconnect_server.cc + - test/core/util/resolve_localhost_ip46.cc - test/core/util/slice_splitter.cc - test/core/util/subprocess_posix.cc - test/core/util/subprocess_windows.cc @@ -7667,6 +7671,7 @@ targets: - test/core/util/port.h - test/core/util/port_server_client.h - test/core/util/reconnect_server.h + - test/core/util/resolve_localhost_ip46.h - test/core/util/slice_splitter.h - test/core/util/subprocess.h - test/core/util/test_config.h @@ -7692,6 +7697,7 @@ targets: - test/core/util/port_isolated_runtime_environment.cc - test/core/util/port_server_client.cc - test/core/util/reconnect_server.cc + - test/core/util/resolve_localhost_ip46.cc - test/core/util/slice_splitter.cc - test/core/util/subprocess_posix.cc - test/core/util/subprocess_windows.cc diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 47e88701fc4..fdcf4d06db7 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -2021,6 +2021,8 @@ Pod::Spec.new do |s| 'test/core/util/port_server_client.h', 'test/core/util/reconnect_server.cc', 'test/core/util/reconnect_server.h', + 'test/core/util/resolve_localhost_ip46.cc', + 'test/core/util/resolve_localhost_ip46.h', 'test/core/util/slice_splitter.cc', 'test/core/util/slice_splitter.h', 'test/core/util/subprocess.h', diff --git a/grpc.gyp b/grpc.gyp index 1aa768c519f..2e12326f7a9 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -1007,6 +1007,7 @@ 'test/core/util/port_isolated_runtime_environment.cc', 'test/core/util/port_server_client.cc', 'test/core/util/reconnect_server.cc', + 'test/core/util/resolve_localhost_ip46.cc', 'test/core/util/slice_splitter.cc', 'test/core/util/subprocess_posix.cc', 'test/core/util/subprocess_windows.cc', @@ -1044,6 +1045,7 @@ 'test/core/util/port_isolated_runtime_environment.cc', 'test/core/util/port_server_client.cc', 'test/core/util/reconnect_server.cc', + 'test/core/util/resolve_localhost_ip46.cc', 'test/core/util/slice_splitter.cc', 'test/core/util/subprocess_posix.cc', 'test/core/util/subprocess_windows.cc', diff --git a/test/core/util/BUILD b/test/core/util/BUILD index ce16ccbc0cd..9d2d27fac8c 100644 --- a/test/core/util/BUILD +++ b/test/core/util/BUILD @@ -51,6 +51,7 @@ grpc_cc_library( "port_isolated_runtime_environment.cc", "port_server_client.cc", "reconnect_server.cc", + "resolve_localhost_ip46.cc", "slice_splitter.cc", "subprocess_posix.cc", "subprocess_windows.cc", @@ -73,6 +74,7 @@ grpc_cc_library( "port.h", "port_server_client.h", "reconnect_server.h", + "resolve_localhost_ip46.h", "slice_splitter.h", "subprocess.h", "test_config.h", @@ -94,6 +96,7 @@ grpc_cc_library( deps = [ ":grpc_debugger_macros", "//:gpr", + "//:grpc_base_c", "//:grpc_common", ], ) diff --git a/test/core/util/resolve_localhost_ip46.cc b/test/core/util/resolve_localhost_ip46.cc new file mode 100644 index 00000000000..b465b754ba5 --- /dev/null +++ b/test/core/util/resolve_localhost_ip46.cc @@ -0,0 +1,58 @@ +// +// +// Copyright 2020 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// + +#include "test/core/util/resolve_localhost_ip46.h" + +#include + +#include "src/core/lib/iomgr/port.h" +#include "src/core/lib/iomgr/resolve_address.h" +#include "src/core/lib/iomgr/sockaddr.h" + +namespace grpc_core { +namespace { + +bool localhost_to_ipv4 = false; +bool localhost_to_ipv6 = false; +gpr_once g_resolve_localhost_ipv46 = GPR_ONCE_INIT; + +void InitResolveLocalhost() { + grpc_resolved_addresses* addresses; + grpc_error* err = + grpc_blocking_resolve_address("localhost", "https", &addresses); + GPR_ASSERT(err == GRPC_ERROR_NONE); + for (size_t i = 0; i < addresses->naddrs; i++) { + grpc_sockaddr* addr = + reinterpret_cast(addresses->addrs[i].addr); + if (addr->sa_family == GRPC_AF_INET) { + localhost_to_ipv4 = true; + } else if (addr->sa_family == GRPC_AF_INET6) { + localhost_to_ipv6 = true; + } + } + grpc_resolved_addresses_destroy(addresses); +} +} // namespace + +void LocalhostResolves(bool* ipv4, bool* ipv6) { + gpr_once_init(&g_resolve_localhost_ipv46, InitResolveLocalhost); + *ipv4 = localhost_to_ipv4; + *ipv6 = localhost_to_ipv6; +} + +} // namespace grpc_core diff --git a/test/core/util/resolve_localhost_ip46.h b/test/core/util/resolve_localhost_ip46.h new file mode 100644 index 00000000000..d8f7883adfe --- /dev/null +++ b/test/core/util/resolve_localhost_ip46.h @@ -0,0 +1,29 @@ +// +// +// Copyright 2020 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// + +#ifndef GRPC_TEST_CORE_UTIL_RESOLVE_LOCALHOST_IP46_H_ +#define GRPC_TEST_CORE_UTIL_RESOLVE_LOCALHOST_IP46_H_ + +namespace grpc_core { + +// Test whether localhost resolves to ipv4 and/or ipv6 +void LocalhostResolves(bool* ipv4, bool* ipv6); + +} // namespace grpc_core + +#endif // GRPC_TEST_CORE_UTIL_RESOLVE_LOCALHOST_IP46_H_ diff --git a/test/cpp/end2end/client_lb_end2end_test.cc b/test/cpp/end2end/client_lb_end2end_test.cc index 9c4923e1d62..4c6759d0e3a 100644 --- a/test/cpp/end2end/client_lb_end2end_test.cc +++ b/test/cpp/end2end/client_lb_end2end_test.cc @@ -59,6 +59,7 @@ #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "src/proto/grpc/testing/xds/orca_load_report_for_test.pb.h" #include "test/core/util/port.h" +#include "test/core/util/resolve_localhost_ip46.h" #include "test/core/util/test_config.h" #include "test/core/util/test_lb_policies.h" #include "test/cpp/end2end/test_service_impl.h" @@ -152,12 +153,14 @@ class MyTestServiceImpl : public TestServiceImpl { class FakeResolverResponseGeneratorWrapper { public: - FakeResolverResponseGeneratorWrapper() - : response_generator_(grpc_core::MakeRefCounted< + explicit FakeResolverResponseGeneratorWrapper(bool ipv6_only) + : ipv6_only_(ipv6_only), + response_generator_(grpc_core::MakeRefCounted< grpc_core::FakeResolverResponseGenerator>()) {} FakeResolverResponseGeneratorWrapper( FakeResolverResponseGeneratorWrapper&& other) noexcept { + ipv6_only_ = other.ipv6_only_; response_generator_ = std::move(other.response_generator_); } @@ -167,13 +170,22 @@ class FakeResolverResponseGeneratorWrapper { std::unique_ptr attribute = nullptr) { grpc_core::ExecCtx exec_ctx; - response_generator_->SetResponse(BuildFakeResults( - ports, service_config_json, attribute_key, std::move(attribute))); + // This is a dummy log line as a workaround for + // https://github.com/grpc/grpc/issues/24550. It should be removed once the + // testing infrastructure updates compiler for MacOS. + if (service_config_json != nullptr) { + gpr_log(GPR_INFO, "SetNextResolution with service_config_json: %s", + service_config_json); + } + response_generator_->SetResponse( + BuildFakeResults(ipv6_only_, ports, service_config_json, attribute_key, + std::move(attribute))); } void SetNextResolutionUponError(const std::vector& ports) { grpc_core::ExecCtx exec_ctx; - response_generator_->SetReresolutionResponse(BuildFakeResults(ports)); + response_generator_->SetReresolutionResponse( + BuildFakeResults(ipv6_only_, ports)); } void SetFailureOnReresolution() { @@ -187,13 +199,15 @@ class FakeResolverResponseGeneratorWrapper { private: static grpc_core::Resolver::Result BuildFakeResults( - const std::vector& ports, const char* service_config_json = nullptr, + bool ipv6_only, const std::vector& ports, + const char* service_config_json = nullptr, const char* attribute_key = nullptr, std::unique_ptr attribute = nullptr) { grpc_core::Resolver::Result result; for (const int& port : ports) { - std::string lb_uri_str = absl::StrCat("ipv4:127.0.0.1:", port); + std::string lb_uri_str = + absl::StrCat(ipv6_only ? "ipv6:[::1]:" : "ipv4:127.0.0.1:", port); grpc_uri* lb_uri = grpc_uri_parse(lb_uri_str.c_str(), true); GPR_ASSERT(lb_uri != nullptr); grpc_resolved_address address; @@ -216,6 +230,7 @@ class FakeResolverResponseGeneratorWrapper { return result; } + bool ipv6_only_ = false; grpc_core::RefCountedPtr response_generator_; }; @@ -238,7 +253,14 @@ class ClientLbEnd2endTest : public ::testing::Test { #endif } - void SetUp() override { grpc_init(); } + void SetUp() override { + grpc_init(); + bool localhost_resolves_to_ipv4 = false; + bool localhost_resolves_to_ipv6 = false; + grpc_core::LocalhostResolves(&localhost_resolves_to_ipv4, + &localhost_resolves_to_ipv6); + ipv6_only_ = !localhost_resolves_to_ipv4 && localhost_resolves_to_ipv6; + } void TearDown() override { for (size_t i = 0; i < servers_.size(); ++i) { @@ -278,7 +300,7 @@ class ClientLbEnd2endTest : public ::testing::Test { } FakeResolverResponseGeneratorWrapper BuildResolverResponseGenerator() { - return FakeResolverResponseGeneratorWrapper(); + return FakeResolverResponseGeneratorWrapper(ipv6_only_); } std::unique_ptr BuildStub( @@ -468,6 +490,7 @@ class ClientLbEnd2endTest : public ::testing::Test { std::vector> servers_; const std::string kRequestMessage_; std::shared_ptr creds_; + bool ipv6_only_ = false; }; TEST_F(ClientLbEnd2endTest, ChannelStateConnectingWhenResolving) { @@ -1969,8 +1992,9 @@ TEST_F(ClientLbAddressTest, Basic) { // Make sure that the attributes wind up on the subchannels. std::vector expected; for (const int port : GetServersPorts()) { - expected.emplace_back(absl::StrCat( - "127.0.0.1:", port, " args={} attributes={", kAttributeKey, "=foo}")); + expected.emplace_back( + absl::StrCat(ipv6_only_ ? "[::1]:" : "127.0.0.1:", port, + " args={} attributes={", kAttributeKey, "=foo}")); } EXPECT_EQ(addresses_seen(), expected); } diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 3c68c8a1c14..e89971e018b 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -350,7 +350,7 @@ class End2endTest : public ::testing::TestWithParam { void StartServer(const std::shared_ptr& processor) { int port = grpc_pick_unused_port_or_die(); first_picked_port_ = port; - server_address_ << "127.0.0.1:" << port; + server_address_ << "localhost:" << port; // Setup server BuildAndStartServer(processor); } @@ -1414,7 +1414,7 @@ TEST_P(End2endTest, ChannelStateTimeout) { } int port = grpc_pick_unused_port_or_die(); std::ostringstream server_address; - server_address << "127.0.0.1:" << port; + server_address << "localhost:" << port; // Channel to non-existing server auto channel = grpc::CreateChannel(server_address.str(), InsecureChannelCredentials()); diff --git a/test/cpp/end2end/grpclb_end2end_test.cc b/test/cpp/end2end/grpclb_end2end_test.cc index ac885f402ad..7858878ab33 100644 --- a/test/cpp/end2end/grpclb_end2end_test.cc +++ b/test/cpp/end2end/grpclb_end2end_test.cc @@ -53,6 +53,7 @@ #include "src/cpp/server/secure_server_credentials.h" #include "test/core/util/port.h" +#include "test/core/util/resolve_localhost_ip46.h" #include "test/core/util/test_config.h" #include "test/cpp/end2end/test_service_impl.h" @@ -184,6 +185,12 @@ std::string Ip4ToPackedString(const char* ip_str) { return std::string(reinterpret_cast(&ip4), sizeof(ip4)); } +std::string Ip6ToPackedString(const char* ip_str) { + struct in6_addr ip6; + GPR_ASSERT(inet_pton(AF_INET6, ip_str, &ip6) == 1); + return std::string(reinterpret_cast(&ip6), sizeof(ip6)); +} + struct ClientStats { size_t num_calls_started = 0; size_t num_calls_finished = 0; @@ -321,28 +328,6 @@ class BalancerServiceImpl : public BalancerService { gpr_log(GPR_INFO, "LB[%p]: shut down", this); } - static LoadBalanceResponse BuildResponseForBackends( - const std::vector& backend_ports, - const std::map& drop_token_counts) { - LoadBalanceResponse response; - for (const auto& drop_token_count : drop_token_counts) { - for (size_t i = 0; i < drop_token_count.second; ++i) { - auto* server = response.mutable_server_list()->add_servers(); - server->set_drop(true); - server->set_load_balance_token(drop_token_count.first); - } - } - for (const int& backend_port : backend_ports) { - auto* server = response.mutable_server_list()->add_servers(); - server->set_ip_address(Ip4ToPackedString("127.0.0.1")); - server->set_port(backend_port); - static int token_count = 0; - server->set_load_balance_token( - absl::StrFormat("token%03d", ++token_count)); - } - return response; - } - ClientStats WaitForLoadReport() { grpc::internal::MutexLock lock(&mu_); grpc::internal::CondVar cv; @@ -418,6 +403,11 @@ class GrpclbEnd2endTest : public ::testing::Test { static void TearDownTestCase() { grpc_shutdown(); } void SetUp() override { + bool localhost_resolves_to_ipv4 = false; + bool localhost_resolves_to_ipv6 = false; + grpc_core::LocalhostResolves(&localhost_resolves_to_ipv4, + &localhost_resolves_to_ipv6); + ipv6_only_ = !localhost_resolves_to_ipv4 && localhost_resolves_to_ipv6; response_generator_ = grpc_core::MakeRefCounted(); // Start the backends. @@ -546,11 +536,12 @@ class GrpclbEnd2endTest : public ::testing::Test { std::string balancer_name; }; - static grpc_core::ServerAddressList CreateLbAddressesFromAddressDataList( + grpc_core::ServerAddressList CreateLbAddressesFromAddressDataList( const std::vector& address_data) { grpc_core::ServerAddressList addresses; for (const auto& addr : address_data) { - std::string lb_uri_str = absl::StrCat("ipv4:127.0.0.1:", addr.port); + std::string lb_uri_str = absl::StrCat( + ipv6_only_ ? "ipv6:[::1]:" : "ipv4:127.0.0.1:", addr.port); grpc_uri* lb_uri = grpc_uri_parse(lb_uri_str.c_str(), true); GPR_ASSERT(lb_uri != nullptr); grpc_resolved_address address; @@ -565,7 +556,7 @@ class GrpclbEnd2endTest : public ::testing::Test { return addresses; } - static grpc_core::Resolver::Result MakeResolverResult( + grpc_core::Resolver::Result MakeResolverResult( const std::vector& balancer_address_data, const std::vector& backend_address_data = {}, const char* service_config_json = kDefaultServiceConfig) { @@ -628,6 +619,29 @@ class GrpclbEnd2endTest : public ::testing::Test { balancers_[i]->service_.add_response(response, delay_ms); } + LoadBalanceResponse BuildResponseForBackends( + const std::vector& backend_ports, + const std::map& drop_token_counts) { + LoadBalanceResponse response; + for (const auto& drop_token_count : drop_token_counts) { + for (size_t i = 0; i < drop_token_count.second; ++i) { + auto* server = response.mutable_server_list()->add_servers(); + server->set_drop(true); + server->set_load_balance_token(drop_token_count.first); + } + } + for (const int& backend_port : backend_ports) { + auto* server = response.mutable_server_list()->add_servers(); + server->set_ip_address(ipv6_only_ ? Ip6ToPackedString("::1") + : Ip4ToPackedString("127.0.0.1")); + server->set_port(backend_port); + static int token_count = 0; + server->set_load_balance_token( + absl::StrFormat("token%03d", ++token_count)); + } + return response; + } + Status SendRpc(EchoResponse* response = nullptr, int timeout_ms = 1000, bool wait_for_ready = false, const Status& expected_status = Status::OK) { @@ -726,6 +740,7 @@ class GrpclbEnd2endTest : public ::testing::Test { const size_t num_backends_; const size_t num_balancers_; const int client_load_reporting_interval_seconds_; + bool ipv6_only_ = false; std::shared_ptr channel_; std::unique_ptr stub_; std::vector>> backends_; @@ -745,8 +760,7 @@ TEST_F(SingleBalancerTest, Vanilla) { SetNextResolutionAllBalancers(); const size_t kNumRpcsPerAddress = 100; ScheduleResponseForBalancer( - 0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts(), {}), - 0); + 0, BuildResponseForBackends(GetBackendPorts(), {}), 0); // 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. @@ -771,8 +785,7 @@ TEST_F(SingleBalancerTest, Vanilla) { TEST_F(SingleBalancerTest, ReturnServerStatus) { SetNextResolutionAllBalancers(); ScheduleResponseForBalancer( - 0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts(), {}), - 0); + 0, BuildResponseForBackends(GetBackendPorts(), {}), 0); // We need to wait for all backends to come online. WaitForAllBackends(); // Send a request that the backend will fail, and make sure we get @@ -793,8 +806,7 @@ TEST_F(SingleBalancerTest, SelectGrpclbWithMigrationServiceConfig) { " ]\n" "}"); ScheduleResponseForBalancer( - 0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts(), {}), - 0); + 0, BuildResponseForBackends(GetBackendPorts(), {}), 0); CheckRpcSendOk(1, 1000 /* timeout_ms */, true /* wait_for_ready */); balancers_[0]->service_.NotifyDoneWithServerlists(); // The balancer got a single request. @@ -841,8 +853,7 @@ TEST_F(SingleBalancerTest, UsePickFirstChildPolicy) { " ]\n" "}"); ScheduleResponseForBalancer( - 0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts(), {}), - 0); + 0, BuildResponseForBackends(GetBackendPorts(), {}), 0); const size_t kNumRpcs = num_backends_ * 2; CheckRpcSendOk(kNumRpcs, 1000 /* timeout_ms */, true /* wait_for_ready */); balancers_[0]->service_.NotifyDoneWithServerlists(); @@ -872,8 +883,7 @@ TEST_F(SingleBalancerTest, SwapChildPolicy) { " ]\n" "}"); ScheduleResponseForBalancer( - 0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts(), {}), - 0); + 0, BuildResponseForBackends(GetBackendPorts(), {}), 0); const size_t kNumRpcs = num_backends_ * 2; CheckRpcSendOk(kNumRpcs, 1000 /* timeout_ms */, true /* wait_for_ready */); // Check that all requests went to the first backend. This verifies @@ -908,8 +918,7 @@ TEST_F(SingleBalancerTest, SameBackendListedMultipleTimes) { ports.push_back(backends_[0]->port_); ports.push_back(backends_[0]->port_); const size_t kNumRpcsPerAddress = 10; - ScheduleResponseForBalancer( - 0, BalancerServiceImpl::BuildResponseForBackends(ports, {}), 0); + ScheduleResponseForBalancer(0, BuildResponseForBackends(ports, {}), 0); // We need to wait for the backend to come online. WaitForBackend(0); // Send kNumRpcsPerAddress RPCs per server. @@ -927,8 +936,7 @@ TEST_F(SingleBalancerTest, SecureNaming) { SetNextResolution({AddressData{balancers_[0]->port_, "lb"}}); const size_t kNumRpcsPerAddress = 100; ScheduleResponseForBalancer( - 0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts(), {}), - 0); + 0, BuildResponseForBackends(GetBackendPorts(), {}), 0); // 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. @@ -970,8 +978,7 @@ TEST_F(SingleBalancerTest, InitiallyEmptyServerlist) { ScheduleResponseForBalancer(0, LoadBalanceResponse(), 0); // Send non-empty serverlist only after kServerlistDelayMs ScheduleResponseForBalancer( - 0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts(), {}), - kServerlistDelayMs); + 0, BuildResponseForBackends(GetBackendPorts(), {}), kServerlistDelayMs); const auto t0 = system_clock::now(); // Client will block: LB will initially send empty serverlist. CheckRpcSendOk(1, kCallDeadlineMs, true /* wait_for_ready */); @@ -997,8 +1004,7 @@ TEST_F(SingleBalancerTest, AllServersUnreachableFailFast) { for (size_t i = 0; i < kNumUnreachableServers; ++i) { ports.push_back(grpc_pick_unused_port_or_die()); } - ScheduleResponseForBalancer( - 0, BalancerServiceImpl::BuildResponseForBackends(ports, {}), 0); + ScheduleResponseForBalancer(0, BuildResponseForBackends(ports, {}), 0); const Status status = SendRpc(); // The error shouldn't be DEADLINE_EXCEEDED. EXPECT_EQ(StatusCode::UNAVAILABLE, status.error_code()); @@ -1027,7 +1033,7 @@ TEST_F(SingleBalancerTest, Fallback) { // Send non-empty serverlist only after kServerlistDelayMs. ScheduleResponseForBalancer( 0, - BalancerServiceImpl::BuildResponseForBackends( + BuildResponseForBackends( GetBackendPorts(kNumBackendsInResolution /* start_index */), {}), kServerlistDelayMs); @@ -1096,7 +1102,7 @@ TEST_F(SingleBalancerTest, FallbackUpdate) { // Send non-empty serverlist only after kServerlistDelayMs. ScheduleResponseForBalancer( 0, - BalancerServiceImpl::BuildResponseForBackends( + BuildResponseForBackends( GetBackendPorts(kNumBackendsInResolution + kNumBackendsInResolutionUpdate /* start_index */), {}), @@ -1201,10 +1207,9 @@ TEST_F(SingleBalancerTest, balancer_addresses.emplace_back(AddressData{balancers_[i]->port_, ""}); } SetNextResolution(balancer_addresses, backend_addresses); - ScheduleResponseForBalancer(0, - BalancerServiceImpl::BuildResponseForBackends( - GetBackendPorts(kNumFallbackBackends), {}), - 0); + ScheduleResponseForBalancer( + 0, BuildResponseForBackends(GetBackendPorts(kNumFallbackBackends), {}), + 0); // Try to connect. channel_->GetState(true /* try_to_connect */); WaitForAllBackends(1 /* num_requests_multiple_of */, @@ -1234,10 +1239,9 @@ TEST_F(SingleBalancerTest, // Now start the balancer again. This should cause us to exit // fallback mode. balancers_[0]->Start(server_host_); - ScheduleResponseForBalancer(0, - BalancerServiceImpl::BuildResponseForBackends( - GetBackendPorts(kNumFallbackBackends), {}), - 0); + ScheduleResponseForBalancer( + 0, BuildResponseForBackends(GetBackendPorts(kNumFallbackBackends), {}), + 0); WaitForAllBackends(1 /* num_requests_multiple_of */, kNumFallbackBackends /* start_index */); } @@ -1256,10 +1260,9 @@ TEST_F(SingleBalancerTest, balancer_addresses.emplace_back(AddressData{balancers_[i]->port_, ""}); } SetNextResolution(balancer_addresses, backend_addresses); - ScheduleResponseForBalancer(0, - BalancerServiceImpl::BuildResponseForBackends( - GetBackendPorts(kNumFallbackBackends), {}), - 0); + ScheduleResponseForBalancer( + 0, BuildResponseForBackends(GetBackendPorts(kNumFallbackBackends), {}), + 0); // Try to connect. channel_->GetState(true /* try_to_connect */); WaitForAllBackends(1 /* num_requests_multiple_of */, @@ -1287,10 +1290,9 @@ TEST_F(SingleBalancerTest, // Now start the balancer again. This should cause us to exit // fallback mode. balancers_[0]->Start(server_host_); - ScheduleResponseForBalancer(0, - BalancerServiceImpl::BuildResponseForBackends( - GetBackendPorts(kNumFallbackBackends), {}), - 0); + ScheduleResponseForBalancer( + 0, BuildResponseForBackends(GetBackendPorts(kNumFallbackBackends), {}), + 0); WaitForAllBackends(1 /* num_requests_multiple_of */, kNumFallbackBackends /* start_index */); } @@ -1358,7 +1360,7 @@ TEST_F(SingleBalancerTest, FallbackControlledByBalancer_AfterFirstServerlist) { // then sends the serverlist again. // The serverlist points to backend 1. LoadBalanceResponse serverlist_resp = - BalancerServiceImpl::BuildResponseForBackends({backends_[1]->port_}, {}); + BuildResponseForBackends({backends_[1]->port_}, {}); LoadBalanceResponse fallback_resp; fallback_resp.mutable_fallback_response(); ScheduleResponseForBalancer(0, serverlist_resp, 0); @@ -1375,8 +1377,7 @@ TEST_F(SingleBalancerTest, BackendsRestart) { SetNextResolutionAllBalancers(); const size_t kNumRpcsPerAddress = 100; ScheduleResponseForBalancer( - 0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts(), {}), - 0); + 0, BuildResponseForBackends(GetBackendPorts(), {}), 0); // Make sure that trying to connect works without a call. channel_->GetState(true /* try_to_connect */); // Send kNumRpcsPerAddress RPCs per server. @@ -1406,8 +1407,7 @@ TEST_F(SingleBalancerTest, ServiceNameFromLbPolicyConfig) { SetNextResolutionAllBalancers(kServiceConfigWithTarget); ScheduleResponseForBalancer( - 0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts(), {}), - 0); + 0, BuildResponseForBackends(GetBackendPorts(), {}), 0); // 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. @@ -1424,10 +1424,10 @@ TEST_F(UpdatesTest, UpdateBalancersButKeepUsingOriginalBalancer) { SetNextResolutionAllBalancers(); const std::vector first_backend{GetBackendPorts()[0]}; const std::vector second_backend{GetBackendPorts()[1]}; - ScheduleResponseForBalancer( - 0, BalancerServiceImpl::BuildResponseForBackends(first_backend, {}), 0); - ScheduleResponseForBalancer( - 1, BalancerServiceImpl::BuildResponseForBackends(second_backend, {}), 0); + ScheduleResponseForBalancer(0, BuildResponseForBackends(first_backend, {}), + 0); + ScheduleResponseForBalancer(1, BuildResponseForBackends(second_backend, {}), + 0); // Wait until the first backend is ready. WaitForBackend(0); @@ -1482,10 +1482,10 @@ TEST_F(UpdatesTest, UpdateBalancersRepeated) { const std::vector first_backend{GetBackendPorts()[0]}; const std::vector second_backend{GetBackendPorts()[0]}; - ScheduleResponseForBalancer( - 0, BalancerServiceImpl::BuildResponseForBackends(first_backend, {}), 0); - ScheduleResponseForBalancer( - 1, BalancerServiceImpl::BuildResponseForBackends(second_backend, {}), 0); + ScheduleResponseForBalancer(0, BuildResponseForBackends(first_backend, {}), + 0); + ScheduleResponseForBalancer(1, BuildResponseForBackends(second_backend, {}), + 0); // Wait until the first backend is ready. WaitForBackend(0); @@ -1555,10 +1555,10 @@ TEST_F(UpdatesTest, UpdateBalancersDeadUpdate) { const std::vector first_backend{GetBackendPorts()[0]}; const std::vector second_backend{GetBackendPorts()[1]}; - ScheduleResponseForBalancer( - 0, BalancerServiceImpl::BuildResponseForBackends(first_backend, {}), 0); - ScheduleResponseForBalancer( - 1, BalancerServiceImpl::BuildResponseForBackends(second_backend, {}), 0); + ScheduleResponseForBalancer(0, BuildResponseForBackends(first_backend, {}), + 0); + ScheduleResponseForBalancer(1, BuildResponseForBackends(second_backend, {}), + 0); // Start servers and send 10 RPCs per server. gpr_log(GPR_INFO, "========= BEFORE FIRST BATCH =========="); @@ -1688,10 +1688,10 @@ class UpdatesWithClientLoadReportingTest : public GrpclbEnd2endTest { TEST_F(UpdatesWithClientLoadReportingTest, ReresolveDeadBalancer) { const std::vector first_backend{GetBackendPorts()[0]}; const std::vector second_backend{GetBackendPorts()[1]}; - ScheduleResponseForBalancer( - 0, BalancerServiceImpl::BuildResponseForBackends(first_backend, {}), 0); - ScheduleResponseForBalancer( - 1, BalancerServiceImpl::BuildResponseForBackends(second_backend, {}), 0); + ScheduleResponseForBalancer(0, BuildResponseForBackends(first_backend, {}), + 0); + ScheduleResponseForBalancer(1, BuildResponseForBackends(second_backend, {}), + 0); // Ask channel to connect to trigger resolver creation. channel_->GetState(true); @@ -1767,7 +1767,7 @@ TEST_F(SingleBalancerTest, Drop) { const int num_total_addresses = num_backends_ + num_of_drop_addresses; ScheduleResponseForBalancer( 0, - BalancerServiceImpl::BuildResponseForBackends( + BuildResponseForBackends( GetBackendPorts(), {{"rate_limiting", num_of_drop_by_rate_limiting_addresses}, {"load_balancing", num_of_drop_by_load_balancing_addresses}}), @@ -1806,7 +1806,7 @@ TEST_F(SingleBalancerTest, DropAllFirst) { const int num_of_drop_by_load_balancing_addresses = 1; ScheduleResponseForBalancer( 0, - BalancerServiceImpl::BuildResponseForBackends( + BuildResponseForBackends( {}, {{"rate_limiting", num_of_drop_by_rate_limiting_addresses}, {"load_balancing", num_of_drop_by_load_balancing_addresses}}), 0); @@ -1818,13 +1818,12 @@ TEST_F(SingleBalancerTest, DropAllFirst) { TEST_F(SingleBalancerTest, DropAll) { SetNextResolutionAllBalancers(); ScheduleResponseForBalancer( - 0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts(), {}), - 0); + 0, BuildResponseForBackends(GetBackendPorts(), {}), 0); const int num_of_drop_by_rate_limiting_addresses = 1; const int num_of_drop_by_load_balancing_addresses = 1; ScheduleResponseForBalancer( 0, - BalancerServiceImpl::BuildResponseForBackends( + BuildResponseForBackends( {}, {{"rate_limiting", num_of_drop_by_rate_limiting_addresses}, {"load_balancing", num_of_drop_by_load_balancing_addresses}}), 1000); @@ -1850,8 +1849,7 @@ TEST_F(SingleBalancerWithClientLoadReportingTest, Vanilla) { SetNextResolutionAllBalancers(); const size_t kNumRpcsPerAddress = 100; ScheduleResponseForBalancer( - 0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts(), {}), - 0); + 0, BuildResponseForBackends(GetBackendPorts(), {}), 0); // Wait until all backends are ready. int num_ok = 0; int num_failure = 0; @@ -1892,8 +1890,7 @@ TEST_F(SingleBalancerWithClientLoadReportingTest, BalancerRestart) { // Balancer returns backends starting at index 1. ScheduleResponseForBalancer( 0, - BalancerServiceImpl::BuildResponseForBackends( - GetBackendPorts(0, kNumBackendsFirstPass), {}), + BuildResponseForBackends(GetBackendPorts(0, kNumBackendsFirstPass), {}), 0); // Wait until all backends returned by the balancer are ready. int num_ok = 0; @@ -1922,10 +1919,9 @@ TEST_F(SingleBalancerWithClientLoadReportingTest, BalancerRestart) { } // Now restart the balancer, this time pointing to all backends. balancers_[0]->Start(server_host_); - ScheduleResponseForBalancer(0, - BalancerServiceImpl::BuildResponseForBackends( - GetBackendPorts(kNumBackendsFirstPass), {}), - 0); + ScheduleResponseForBalancer( + 0, BuildResponseForBackends(GetBackendPorts(kNumBackendsFirstPass), {}), + 0); // Wait for queries to start going to one of the new backends. // This tells us that we're now using the new serverlist. do { @@ -1955,7 +1951,7 @@ TEST_F(SingleBalancerWithClientLoadReportingTest, Drop) { const int num_total_addresses = num_backends_ + num_of_drop_addresses; ScheduleResponseForBalancer( 0, - BalancerServiceImpl::BuildResponseForBackends( + BuildResponseForBackends( GetBackendPorts(), {{"rate_limiting", num_of_drop_by_rate_limiting_addresses}, {"load_balancing", num_of_drop_by_load_balancing_addresses}}), diff --git a/test/cpp/end2end/server_early_return_test.cc b/test/cpp/end2end/server_early_return_test.cc index 49bf45eb197..c8c5bbe7d0f 100644 --- a/test/cpp/end2end/server_early_return_test.cc +++ b/test/cpp/end2end/server_early_return_test.cc @@ -115,7 +115,7 @@ class ServerEarlyReturnTest : public ::testing::Test { void SetUp() override { int port = grpc_pick_unused_port_or_die(); picked_port_ = port; - server_address_ << "127.0.0.1:" << port; + server_address_ << "localhost:" << port; ServerBuilder builder; builder.AddListeningPort(server_address_.str(), InsecureServerCredentials()); diff --git a/test/cpp/end2end/service_config_end2end_test.cc b/test/cpp/end2end/service_config_end2end_test.cc index e49704f54dc..385512498e7 100644 --- a/test/cpp/end2end/service_config_end2end_test.cc +++ b/test/cpp/end2end/service_config_end2end_test.cc @@ -57,6 +57,7 @@ #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/core/util/port.h" +#include "test/core/util/resolve_localhost_ip46.h" #include "test/core/util/test_config.h" #include "test/cpp/end2end/test_service_impl.h" @@ -131,6 +132,11 @@ class ServiceConfigEnd2endTest : public ::testing::Test { grpc_init(); response_generator_ = grpc_core::MakeRefCounted(); + bool localhost_resolves_to_ipv4 = false; + bool localhost_resolves_to_ipv6 = false; + grpc_core::LocalhostResolves(&localhost_resolves_to_ipv4, + &localhost_resolves_to_ipv6); + ipv6_only_ = !localhost_resolves_to_ipv4 && localhost_resolves_to_ipv6; } void TearDown() override { @@ -169,7 +175,8 @@ class ServiceConfigEnd2endTest : public ::testing::Test { grpc_core::Resolver::Result BuildFakeResults(const std::vector& ports) { grpc_core::Resolver::Result result; for (const int& port : ports) { - std::string lb_uri_str = absl::StrCat("ipv4:127.0.0.1:", port); + std::string lb_uri_str = + absl::StrCat(ipv6_only_ ? "ipv6:[::1]:" : "ipv4:127.0.0.1:", port); grpc_uri* lb_uri = grpc_uri_parse(lb_uri_str.c_str(), true); GPR_ASSERT(lb_uri != nullptr); grpc_resolved_address address; @@ -422,6 +429,7 @@ class ServiceConfigEnd2endTest : public ::testing::Test { return "{\"version\": \"invalid_default\""; } + bool ipv6_only_ = false; const std::string server_host_; std::unique_ptr stub_; std::vector> servers_; diff --git a/test/cpp/end2end/xds_end2end_test.cc b/test/cpp/end2end/xds_end2end_test.cc index 4c9787778e5..fd97a7cd675 100644 --- a/test/cpp/end2end/xds_end2end_test.cc +++ b/test/cpp/end2end/xds_end2end_test.cc @@ -62,6 +62,7 @@ #include "src/cpp/server/secure_server_credentials.h" #include "test/core/util/port.h" +#include "test/core/util/resolve_localhost_ip46.h" #include "test/core/util/test_config.h" #include "test/cpp/end2end/test_service_impl.h" @@ -431,6 +432,8 @@ class ClientStats { std::map dropped_requests_; }; +// TODO(roth) move all of the code that deals with default resource contents out +// of AdsServiceImpl and into XdsEnd2EndTest. class AdsServiceImpl : public std::enable_shared_from_this { public: struct ResponseState { @@ -468,32 +471,7 @@ class AdsServiceImpl : public std::enable_shared_from_this { FractionalPercent::MILLION; }; - explicit AdsServiceImpl(bool enable_load_reporting) - : v2_rpc_service_(this, /*is_v2=*/true), - v3_rpc_service_(this, /*is_v2=*/false) { - // Construct RDS response data. - default_route_config_.set_name(kDefaultRouteConfigurationName); - auto* virtual_host = default_route_config_.add_virtual_hosts(); - virtual_host->add_domains("*"); - auto* route = virtual_host->add_routes(); - route->mutable_match()->set_prefix(""); - route->mutable_route()->set_cluster(kDefaultClusterName); - SetRdsResource(default_route_config_); - // Construct LDS response data (with inlined RDS result). - default_listener_ = BuildListener(default_route_config_); - SetLdsResource(default_listener_); - // Construct CDS response data. - default_cluster_.set_name(kDefaultClusterName); - default_cluster_.set_type(Cluster::EDS); - auto* eds_config = default_cluster_.mutable_eds_cluster_config(); - eds_config->mutable_eds_config()->mutable_ads(); - eds_config->set_service_name(kDefaultEdsServiceName); - default_cluster_.set_lb_policy(Cluster::ROUND_ROBIN); - if (enable_load_reporting) { - default_cluster_.mutable_lrs_server()->mutable_self(); - } - SetCdsResource(default_cluster_); - } + explicit AdsServiceImpl(bool enable_load_reporting); bool seen_v2_client() const { return seen_v2_client_; } bool seen_v3_client() const { return seen_v3_client_; } @@ -614,57 +592,6 @@ class AdsServiceImpl : public std::enable_shared_from_this { SetLdsResource(listener); } - static Listener BuildListener(const RouteConfiguration& route_config) { - HttpConnectionManager http_connection_manager; - *(http_connection_manager.mutable_route_config()) = route_config; - Listener listener; - listener.set_name(kServerName); - listener.mutable_api_listener()->mutable_api_listener()->PackFrom( - http_connection_manager); - return listener; - } - - static ClusterLoadAssignment BuildEdsResource( - const EdsResourceArgs& args, - const char* eds_service_name = kDefaultEdsServiceName) { - ClusterLoadAssignment assignment; - assignment.set_cluster_name(eds_service_name); - for (const auto& locality : args.locality_list) { - auto* endpoints = assignment.add_endpoints(); - endpoints->mutable_load_balancing_weight()->set_value(locality.lb_weight); - endpoints->set_priority(locality.priority); - endpoints->mutable_locality()->set_region(kDefaultLocalityRegion); - endpoints->mutable_locality()->set_zone(kDefaultLocalityZone); - endpoints->mutable_locality()->set_sub_zone(locality.sub_zone); - for (size_t i = 0; i < locality.ports.size(); ++i) { - const int& port = locality.ports[i]; - auto* lb_endpoints = endpoints->add_lb_endpoints(); - if (locality.health_statuses.size() > i && - locality.health_statuses[i] != HealthStatus::UNKNOWN) { - lb_endpoints->set_health_status(locality.health_statuses[i]); - } - auto* endpoint = lb_endpoints->mutable_endpoint(); - auto* address = endpoint->mutable_address(); - auto* socket_address = address->mutable_socket_address(); - socket_address->set_address("127.0.0.1"); - socket_address->set_port_value(port); - } - } - if (!args.drop_categories.empty()) { - auto* policy = assignment.mutable_policy(); - for (const auto& p : args.drop_categories) { - const std::string& name = p.first; - const uint32_t parts_per_million = p.second; - auto* drop_overload = policy->add_drop_overloads(); - drop_overload->set_category(name); - auto* drop_percentage = drop_overload->mutable_drop_percentage(); - drop_percentage->set_numerator(parts_per_million); - drop_percentage->set_denominator(args.drop_denominator); - } - } - return assignment; - } - void Start() { grpc_core::MutexLock lock(&ads_mu_); ads_done_ = false; @@ -1430,6 +1357,11 @@ class XdsEnd2endTest : public ::testing::TestWithParam { gpr_setenv("GRPC_XDS_BOOTSTRAP", GetParam().use_v2() ? g_bootstrap_file_v2 : g_bootstrap_file_v3); g_port_saver->Reset(); + bool localhost_resolves_to_ipv4 = false; + bool localhost_resolves_to_ipv6 = false; + grpc_core::LocalhostResolves(&localhost_resolves_to_ipv4, + &localhost_resolves_to_ipv6); + ipv6_only_ = !localhost_resolves_to_ipv4 && localhost_resolves_to_ipv6; response_generator_ = grpc_core::MakeRefCounted(); // Inject xDS channel response generator. @@ -1692,7 +1624,8 @@ class XdsEnd2endTest : public ::testing::TestWithParam { const std::vector& ports) { grpc_core::ServerAddressList addresses; for (int port : ports) { - std::string lb_uri_str = absl::StrCat("ipv4:127.0.0.1:", port); + std::string lb_uri_str = + absl::StrCat(ipv6_only_ ? "ipv6:[::1]:" : "ipv4:127.0.0.1:", port); grpc_uri* lb_uri = grpc_uri_parse(lb_uri_str.c_str(), true); GPR_ASSERT(lb_uri != nullptr); grpc_resolved_address address; @@ -1841,7 +1774,7 @@ class XdsEnd2endTest : public ::testing::TestWithParam { balancers_[idx]->ads_service()->SetRdsResource(route_config); } else { balancers_[idx]->ads_service()->SetLdsResource( - AdsServiceImpl::BuildListener(route_config)); + BuildListener(route_config)); } } @@ -1853,6 +1786,47 @@ class XdsEnd2endTest : public ::testing::TestWithParam { return ads_service->lds_response_state(); } + ClusterLoadAssignment BuildEdsResource( + const AdsServiceImpl::EdsResourceArgs& args, + const char* eds_service_name = kDefaultEdsServiceName) { + ClusterLoadAssignment assignment; + assignment.set_cluster_name(eds_service_name); + for (const auto& locality : args.locality_list) { + auto* endpoints = assignment.add_endpoints(); + endpoints->mutable_load_balancing_weight()->set_value(locality.lb_weight); + endpoints->set_priority(locality.priority); + endpoints->mutable_locality()->set_region(kDefaultLocalityRegion); + endpoints->mutable_locality()->set_zone(kDefaultLocalityZone); + endpoints->mutable_locality()->set_sub_zone(locality.sub_zone); + for (size_t i = 0; i < locality.ports.size(); ++i) { + const int& port = locality.ports[i]; + auto* lb_endpoints = endpoints->add_lb_endpoints(); + if (locality.health_statuses.size() > i && + locality.health_statuses[i] != HealthStatus::UNKNOWN) { + lb_endpoints->set_health_status(locality.health_statuses[i]); + } + auto* endpoint = lb_endpoints->mutable_endpoint(); + auto* address = endpoint->mutable_address(); + auto* socket_address = address->mutable_socket_address(); + socket_address->set_address(ipv6_only_ ? "::1" : "127.0.0.1"); + socket_address->set_port_value(port); + } + } + if (!args.drop_categories.empty()) { + auto* policy = assignment.mutable_policy(); + for (const auto& p : args.drop_categories) { + const std::string& name = p.first; + const uint32_t parts_per_million = p.second; + auto* drop_overload = policy->add_drop_overloads(); + drop_overload->set_category(name); + auto* drop_percentage = drop_overload->mutable_drop_percentage(); + drop_percentage->set_numerator(parts_per_million); + drop_percentage->set_denominator(args.drop_denominator); + } + } + return assignment; + } + public: // This method could benefit test subclasses; to make it accessible // via bind with a qualified name, it needs to be public. @@ -1864,6 +1838,16 @@ class XdsEnd2endTest : public ::testing::TestWithParam { balancers_[i]->ads_service()->SetEdsResource(assignment); } + static Listener BuildListener(const RouteConfiguration& route_config) { + HttpConnectionManager http_connection_manager; + *(http_connection_manager.mutable_route_config()) = route_config; + Listener listener; + listener.set_name(kServerName); + listener.mutable_api_listener()->mutable_api_listener()->PackFrom( + http_connection_manager); + return listener; + } + protected: class ServerThread { public: @@ -2028,6 +2012,7 @@ class XdsEnd2endTest : public ::testing::TestWithParam { const size_t num_backends_; const size_t num_balancers_; const int client_load_reporting_interval_seconds_; + bool ipv6_only_ = false; std::shared_ptr channel_; std::unique_ptr stub_; std::unique_ptr stub1_; @@ -2043,6 +2028,33 @@ class XdsEnd2endTest : public ::testing::TestWithParam { grpc_channel_args xds_channel_args_; }; +AdsServiceImpl::AdsServiceImpl(bool enable_load_reporting) + : v2_rpc_service_(this, /*is_v2=*/true), + v3_rpc_service_(this, /*is_v2=*/false) { + // Construct RDS response data. + default_route_config_.set_name(kDefaultRouteConfigurationName); + auto* virtual_host = default_route_config_.add_virtual_hosts(); + virtual_host->add_domains("*"); + auto* route = virtual_host->add_routes(); + route->mutable_match()->set_prefix(""); + route->mutable_route()->set_cluster(kDefaultClusterName); + SetRdsResource(default_route_config_); + // Construct LDS response data (with inlined RDS result). + default_listener_ = XdsEnd2endTest::BuildListener(default_route_config_); + SetLdsResource(default_listener_); + // Construct CDS response data. + default_cluster_.set_name(kDefaultClusterName); + default_cluster_.set_type(Cluster::EDS); + auto* eds_config = default_cluster_.mutable_eds_cluster_config(); + eds_config->mutable_eds_config()->mutable_ads(); + eds_config->set_service_name(kDefaultEdsServiceName); + default_cluster_.set_lb_policy(Cluster::ROUND_ROBIN); + if (enable_load_reporting) { + default_cluster_.mutable_lrs_server()->mutable_self(); + } + SetCdsResource(default_cluster_); +} + class BasicTest : public XdsEnd2endTest { public: BasicTest() : XdsEnd2endTest(4, 1) {} @@ -2058,7 +2070,7 @@ TEST_P(BasicTest, Vanilla) { {"locality0", GetBackendPorts()}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); // 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. @@ -2088,7 +2100,7 @@ TEST_P(BasicTest, IgnoresUnhealthyEndpoints) { {HealthStatus::DRAINING}}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); // 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. @@ -2114,7 +2126,7 @@ TEST_P(BasicTest, SameBackendListedMultipleTimes) { }); const size_t kNumRpcsPerAddress = 10; balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); // We need to wait for the backend to come online. WaitForBackend(0); // Send kNumRpcsPerAddress RPCs per server. @@ -2139,15 +2151,14 @@ TEST_P(BasicTest, InitiallyEmptyServerlist) { empty_locality, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); // 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, DefaultEdsServiceName()), - kServerlistDelayMs)); + std::thread delayed_resource_setter(std::bind( + &BasicTest::SetEdsResourceWithDelay, this, 0, + BuildEdsResource(args, DefaultEdsServiceName()), kServerlistDelayMs)); const auto t0 = system_clock::now(); // Client will block: LB will initially send empty serverlist. CheckRpcSendOk( @@ -2177,7 +2188,7 @@ TEST_P(BasicTest, AllServersUnreachableFailFast) { {"locality0", ports}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); const Status status = SendRpc(); // The error shouldn't be DEADLINE_EXCEEDED. EXPECT_EQ(StatusCode::UNAVAILABLE, status.error_code()); @@ -2192,7 +2203,7 @@ TEST_P(BasicTest, BackendsRestart) { {"locality0", GetBackendPorts()}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); WaitForAllBackends(); // Stop backends. RPCs should fail. ShutdownAllBackends(); @@ -2219,7 +2230,7 @@ TEST_P(BasicTest, IgnoresDuplicateUpdates) { {"locality0", GetBackendPorts()}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); // Wait for all backends to come online. WaitForAllBackends(); // Send kNumRpcsPerAddress RPCs per server, but send an EDS update in @@ -2229,7 +2240,7 @@ TEST_P(BasicTest, IgnoresDuplicateUpdates) { for (size_t i = 0; i < kNumRpcsPerAddress; ++i) { CheckRpcSendOk(2); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); CheckRpcSendOk(2); } // Each backend should have gotten the right number of requests. @@ -2247,8 +2258,7 @@ TEST_P(XdsResolverOnlyTest, ResourceTypeVersionPersistsAcrossStreamRestarts) { AdsServiceImpl::EdsResourceArgs args({ {"locality0", GetBackendPorts(0, 1)}, }); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); // Wait for backends to come online. WaitForAllBackends(0, 1); // Stop balancer. @@ -2263,8 +2273,7 @@ TEST_P(XdsResolverOnlyTest, ResourceTypeVersionPersistsAcrossStreamRestarts) { AdsServiceImpl::EdsResourceArgs args2({ {"locality0", GetBackendPorts(1, 2)}, }); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args2)); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args2)); // Restart balancer. balancers_[0]->Start(); // Make sure client has reconnected. @@ -2280,8 +2289,7 @@ TEST_P(XdsResolverOnlyTest, ChangeClusters) { AdsServiceImpl::EdsResourceArgs args({ {"locality0", GetBackendPorts(0, 2)}, }); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); // We need to wait for all backends to come online. WaitForAllBackends(0, 2); // Populate new EDS resource. @@ -2289,7 +2297,7 @@ TEST_P(XdsResolverOnlyTest, ChangeClusters) { {"locality0", GetBackendPorts(2, 4)}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args2, kNewEdsServiceName)); + BuildEdsResource(args2, kNewEdsServiceName)); // Populate new CDS resource. Cluster new_cluster = balancers_[0]->ads_service()->default_cluster(); new_cluster.set_name(kNewClusterName); @@ -2303,8 +2311,7 @@ TEST_P(XdsResolverOnlyTest, ChangeClusters) { ->mutable_routes(0) ->mutable_route() ->set_cluster(kNewClusterName); - Listener listener = - balancers_[0]->ads_service()->BuildListener(new_route_config); + Listener listener = BuildListener(new_route_config); balancers_[0]->ads_service()->SetLdsResource(listener); // Wait for all new backends to be used. std::tuple counts = WaitForAllBackends(2, 4); @@ -2319,8 +2326,7 @@ TEST_P(XdsResolverOnlyTest, ClusterRemoved) { AdsServiceImpl::EdsResourceArgs args({ {"locality0", GetBackendPorts()}, }); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); // We need to wait for all backends to come online. WaitForAllBackends(); // Unset CDS resource. @@ -2345,8 +2351,7 @@ TEST_P(XdsResolverOnlyTest, RestartsRequestsUponReconnection) { AdsServiceImpl::EdsResourceArgs args({ {"locality0", GetBackendPorts(0, 2)}, }); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); + balancers_[0]->ads_service()->SetEdsResource(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 @@ -2361,7 +2366,7 @@ TEST_P(XdsResolverOnlyTest, RestartsRequestsUponReconnection) { {"locality0", GetBackendPorts(2, 4)}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args2, kNewEdsServiceName)); + BuildEdsResource(args2, kNewEdsServiceName)); // Populate new CDS resource. Cluster new_cluster = balancers_[0]->ads_service()->default_cluster(); new_cluster.set_name(kNewClusterName); @@ -2389,15 +2394,13 @@ TEST_P(XdsResolverOnlyTest, DefaultRouteSpecifiesSlashPrefix) { ->mutable_routes(0) ->mutable_match() ->set_prefix("/"); - balancers_[0]->ads_service()->SetLdsResource( - AdsServiceImpl::BuildListener(route_config)); + balancers_[0]->ads_service()->SetLdsResource(BuildListener(route_config)); SetNextResolution({}); SetNextResolutionForLbChannelAllBalancers(); AdsServiceImpl::EdsResourceArgs args({ {"locality0", GetBackendPorts()}, }); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); // We need to wait for all backends to come online. WaitForAllBackends(); } @@ -2411,8 +2414,7 @@ TEST_P(XdsResolverOnlyTest, CircuitBreaking) { AdsServiceImpl::EdsResourceArgs args({ {"locality0", GetBackendPorts(0, 1)}, }); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); // Update CDS resource to set max concurrent request. CircuitBreakers circuit_breaks; Cluster cluster = balancers_[0]->ads_service()->default_cluster(); @@ -2456,8 +2458,7 @@ TEST_P(XdsResolverOnlyTest, CircuitBreakingMultipleChannelsShareCallCounter) { AdsServiceImpl::EdsResourceArgs args({ {"locality0", GetBackendPorts(0, 1)}, }); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); // Update CDS resource to set max concurrent request. CircuitBreakers circuit_breaks; Cluster cluster = balancers_[0]->ads_service()->default_cluster(); @@ -2514,8 +2515,7 @@ TEST_P(XdsResolverOnlyTest, CircuitBreakingDisabled) { AdsServiceImpl::EdsResourceArgs args({ {"locality0", GetBackendPorts(0, 1)}, }); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); // Update CDS resource to set max concurrent request. CircuitBreakers circuit_breaks; Cluster cluster = balancers_[0]->ads_service()->default_cluster(); @@ -2555,8 +2555,7 @@ TEST_P(XdsResolverOnlyTest, MultipleChannelsShareXdsClient) { AdsServiceImpl::EdsResourceArgs args({ {"locality0", GetBackendPorts()}, }); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); WaitForAllBackends(); // Create second channel and tell it to connect to kNewServerName. auto channel2 = CreateChannel(/*failover_timeout=*/0, kNewServerName); @@ -2584,14 +2583,13 @@ TEST_P(XdsResolverLoadReportingOnlyTest, ChangeClusters) { AdsServiceImpl::EdsResourceArgs args({ {"locality0", GetBackendPorts(0, 2)}, }); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); // cluster kNewClusterName -> locality1 -> backends 2 and 3 AdsServiceImpl::EdsResourceArgs args2({ {"locality1", GetBackendPorts(2, 4)}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args2, kNewEdsServiceName)); + BuildEdsResource(args2, kNewEdsServiceName)); // CDS resource for kNewClusterName. Cluster new_cluster = balancers_[0]->ads_service()->default_cluster(); new_cluster.set_name(kNewClusterName); @@ -2636,8 +2634,7 @@ TEST_P(XdsResolverLoadReportingOnlyTest, ChangeClusters) { ->mutable_routes(0) ->mutable_route() ->set_cluster(kNewClusterName); - Listener listener = - balancers_[0]->ads_service()->BuildListener(new_route_config); + Listener listener = BuildListener(new_route_config); 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); @@ -2714,7 +2711,7 @@ TEST_P(SecureNamingTest, TargetNameIsExpected) { {"locality0", GetBackendPorts()}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); CheckRpcSendOk(); } @@ -2728,7 +2725,7 @@ TEST_P(SecureNamingTest, TargetNameIsUnexpected) { {"locality0", GetBackendPorts()}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); // Make sure that we blow up (via abort() from the security connector) when // the name from the balancer doesn't match expectations. ASSERT_DEATH_IF_SUPPORTED({ CheckRpcSendOk(); }, ""); @@ -2835,8 +2832,7 @@ TEST_P(LdsRdsTest, ListenerRemoved) { AdsServiceImpl::EdsResourceArgs args({ {"locality0", GetBackendPorts()}, }); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); // We need to wait for all backends to come online. WaitForAllBackends(); // Unset LDS resource. @@ -3280,12 +3276,11 @@ TEST_P(LdsRdsTest, XdsRoutingPathMatching) { AdsServiceImpl::EdsResourceArgs args2({ {"locality0", GetBackendPorts(3, 4)}, }); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args1, kNewEdsService1Name)); + BuildEdsResource(args1, kNewEdsService1Name)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args2, kNewEdsService2Name)); + BuildEdsResource(args2, kNewEdsService2Name)); // Populate new CDS resources. Cluster new_cluster1 = balancers_[0]->ads_service()->default_cluster(); new_cluster1.set_name(kNewCluster1Name); @@ -3357,12 +3352,11 @@ TEST_P(LdsRdsTest, XdsRoutingPathMatchingCaseInsensitive) { AdsServiceImpl::EdsResourceArgs args2({ {"locality0", GetBackendPorts(2, 3)}, }); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); + BuildEdsResource(args1, kNewEdsService1Name)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args1, kNewEdsService1Name)); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args2, kNewEdsService2Name)); + BuildEdsResource(args2, kNewEdsService2Name)); // Populate new CDS resources. Cluster new_cluster1 = balancers_[0]->ads_service()->default_cluster(); new_cluster1.set_name(kNewCluster1Name); @@ -3424,12 +3418,11 @@ TEST_P(LdsRdsTest, XdsRoutingPrefixMatching) { AdsServiceImpl::EdsResourceArgs args2({ {"locality0", GetBackendPorts(3, 4)}, }); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args1, kNewEdsService1Name)); + BuildEdsResource(args1, kNewEdsService1Name)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args2, kNewEdsService2Name)); + BuildEdsResource(args2, kNewEdsService2Name)); // Populate new CDS resources. Cluster new_cluster1 = balancers_[0]->ads_service()->default_cluster(); new_cluster1.set_name(kNewCluster1Name); @@ -3496,12 +3489,11 @@ TEST_P(LdsRdsTest, XdsRoutingPrefixMatchingCaseInsensitive) { AdsServiceImpl::EdsResourceArgs args2({ {"locality0", GetBackendPorts(2, 3)}, }); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args1, kNewEdsService1Name)); + BuildEdsResource(args1, kNewEdsService1Name)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args2, kNewEdsService2Name)); + BuildEdsResource(args2, kNewEdsService2Name)); // Populate new CDS resources. Cluster new_cluster1 = balancers_[0]->ads_service()->default_cluster(); new_cluster1.set_name(kNewCluster1Name); @@ -3563,12 +3555,11 @@ TEST_P(LdsRdsTest, XdsRoutingPathRegexMatching) { AdsServiceImpl::EdsResourceArgs args2({ {"locality0", GetBackendPorts(3, 4)}, }); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); + BuildEdsResource(args1, kNewEdsService1Name)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args1, kNewEdsService1Name)); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args2, kNewEdsService2Name)); + BuildEdsResource(args2, kNewEdsService2Name)); // Populate new CDS resources. Cluster new_cluster1 = balancers_[0]->ads_service()->default_cluster(); new_cluster1.set_name(kNewCluster1Name); @@ -3637,12 +3628,11 @@ TEST_P(LdsRdsTest, XdsRoutingPathRegexMatchingCaseInsensitive) { AdsServiceImpl::EdsResourceArgs args2({ {"locality0", GetBackendPorts(2, 3)}, }); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args1, kNewEdsService1Name)); + BuildEdsResource(args1, kNewEdsService1Name)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args2, kNewEdsService2Name)); + BuildEdsResource(args2, kNewEdsService2Name)); // Populate new CDS resources. Cluster new_cluster1 = balancers_[0]->ads_service()->default_cluster(); new_cluster1.set_name(kNewCluster1Name); @@ -3707,12 +3697,11 @@ TEST_P(LdsRdsTest, XdsRoutingWeightedCluster) { AdsServiceImpl::EdsResourceArgs args2({ {"locality0", GetBackendPorts(2, 3)}, }); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); + BuildEdsResource(args1, kNewEdsService1Name)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args1, kNewEdsService1Name)); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args2, kNewEdsService2Name)); + BuildEdsResource(args2, kNewEdsService2Name)); // Populate new CDS resources. Cluster new_cluster1 = balancers_[0]->ads_service()->default_cluster(); new_cluster1.set_name(kNewCluster1Name); @@ -3796,12 +3785,11 @@ TEST_P(LdsRdsTest, RouteActionWeightedTargetDefaultRoute) { AdsServiceImpl::EdsResourceArgs args2({ {"locality0", GetBackendPorts(2, 3)}, }); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args1, kNewEdsService1Name)); + BuildEdsResource(args1, kNewEdsService1Name)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args2, kNewEdsService2Name)); + BuildEdsResource(args2, kNewEdsService2Name)); // Populate new CDS resources. Cluster new_cluster1 = balancers_[0]->ads_service()->default_cluster(); new_cluster1.set_name(kNewCluster1Name); @@ -3884,14 +3872,13 @@ TEST_P(LdsRdsTest, XdsRoutingWeightedClusterUpdateWeights) { AdsServiceImpl::EdsResourceArgs args3({ {"locality0", GetBackendPorts(3, 4)}, }); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args1, kNewEdsService1Name)); + BuildEdsResource(args1, kNewEdsService1Name)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args2, kNewEdsService2Name)); + BuildEdsResource(args2, kNewEdsService2Name)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args3, kNewEdsService3Name)); + BuildEdsResource(args3, kNewEdsService3Name)); // Populate new CDS resources. Cluster new_cluster1 = balancers_[0]->ads_service()->default_cluster(); new_cluster1.set_name(kNewCluster1Name); @@ -4022,14 +4009,13 @@ TEST_P(LdsRdsTest, XdsRoutingWeightedClusterUpdateClusters) { AdsServiceImpl::EdsResourceArgs args3({ {"locality0", GetBackendPorts(3, 4)}, }); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); + BuildEdsResource(args1, kNewEdsService1Name)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args1, kNewEdsService1Name)); + BuildEdsResource(args2, kNewEdsService2Name)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args2, kNewEdsService2Name)); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args3, kNewEdsService3Name)); + BuildEdsResource(args3, kNewEdsService3Name)); // Populate new CDS resources. Cluster new_cluster1 = balancers_[0]->ads_service()->default_cluster(); new_cluster1.set_name(kNewCluster1Name); @@ -4175,10 +4161,9 @@ TEST_P(LdsRdsTest, XdsRoutingClusterUpdateClusters) { AdsServiceImpl::EdsResourceArgs args1({ {"locality0", GetBackendPorts(1, 2)}, }); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args1, kNewEdsServiceName)); + BuildEdsResource(args1, kNewEdsServiceName)); // Populate new CDS resources. Cluster new_cluster = balancers_[0]->ads_service()->default_cluster(); new_cluster.set_name(kNewClusterName); @@ -4216,10 +4201,9 @@ TEST_P(LdsRdsTest, XdsRoutingClusterUpdateClustersWithPickingDelays) { AdsServiceImpl::EdsResourceArgs args1({ {"locality0", GetBackendPorts(1, 2)}, }); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args1, kNewEdsServiceName)); + BuildEdsResource(args1, kNewEdsServiceName)); // Populate new CDS resources. Cluster new_cluster = balancers_[0]->ads_service()->default_cluster(); new_cluster.set_name(kNewClusterName); @@ -4290,14 +4274,13 @@ TEST_P(LdsRdsTest, XdsRoutingApplyXdsTimeout) { AdsServiceImpl::EdsResourceArgs args3({ {"locality0", {g_port_saver->GetPort()}}, }); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args1, kNewEdsService1Name)); + BuildEdsResource(args1, kNewEdsService1Name)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args2, kNewEdsService2Name)); + BuildEdsResource(args2, kNewEdsService2Name)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args3, kNewEdsService3Name)); + BuildEdsResource(args3, kNewEdsService3Name)); // Populate new CDS resources. Cluster new_cluster1 = balancers_[0]->ads_service()->default_cluster(); new_cluster1.set_name(kNewCluster1Name); @@ -4430,12 +4413,11 @@ TEST_P(LdsRdsTest, XdsRoutingApplyApplicationTimeoutWhenXdsTimeoutExplicit0) { AdsServiceImpl::EdsResourceArgs args2({ {"locality0", {g_port_saver->GetPort()}}, }); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args1, kNewEdsService1Name)); + BuildEdsResource(args1, kNewEdsService1Name)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args2, kNewEdsService2Name)); + BuildEdsResource(args2, kNewEdsService2Name)); // Populate new CDS resources. Cluster new_cluster1 = balancers_[0]->ads_service()->default_cluster(); new_cluster1.set_name(kNewCluster1Name); @@ -4530,8 +4512,7 @@ TEST_P(LdsRdsTest, XdsRoutingApplyApplicationTimeoutWhenHttpTimeoutExplicit0) { AdsServiceImpl::EdsResourceArgs args({ {"locality0", {g_port_saver->GetPort()}}, }); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); HttpConnectionManager http_connection_manager; // Set up HTTP max_stream_duration to be explicit 0 auto* duration = @@ -4580,8 +4561,7 @@ TEST_P(LdsRdsTest, XdsRoutingWithOnlyApplicationTimeout) { AdsServiceImpl::EdsResourceArgs args({ {"locality0", {g_port_saver->GetPort()}}, }); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); auto t0 = system_clock::now(); CheckRpcSendFailure(1, RpcOptions().set_wait_for_ready(true).set_timeout_ms( @@ -4608,10 +4588,9 @@ TEST_P(LdsRdsTest, XdsRoutingHeadersMatching) { AdsServiceImpl::EdsResourceArgs args1({ {"locality0", GetBackendPorts(1, 2)}, }); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args1, kNewEdsServiceName)); + BuildEdsResource(args1, kNewEdsServiceName)); // Populate new CDS resources. Cluster new_cluster = balancers_[0]->ads_service()->default_cluster(); new_cluster.set_name(kNewClusterName); @@ -4687,10 +4666,9 @@ TEST_P(LdsRdsTest, XdsRoutingHeadersMatchingSpecialHeaderContentType) { AdsServiceImpl::EdsResourceArgs args1({ {"locality0", GetBackendPorts(1, 2)}, }); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args1, kNewEdsServiceName)); + BuildEdsResource(args1, kNewEdsServiceName)); // Populate new CDS resources. Cluster new_cluster = balancers_[0]->ads_service()->default_cluster(); new_cluster.set_name(kNewClusterName); @@ -4741,12 +4719,11 @@ TEST_P(LdsRdsTest, XdsRoutingHeadersMatchingSpecialCasesToIgnore) { AdsServiceImpl::EdsResourceArgs args2({ {"locality0", GetBackendPorts(2, 3)}, }); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); + BuildEdsResource(args1, kNewEdsService1Name)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args1, kNewEdsService1Name)); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args2, kNewEdsService2Name)); + BuildEdsResource(args2, kNewEdsService2Name)); // Populate new CDS resources. Cluster new_cluster1 = balancers_[0]->ads_service()->default_cluster(); new_cluster1.set_name(kNewCluster1Name); @@ -4806,10 +4783,9 @@ TEST_P(LdsRdsTest, XdsRoutingRuntimeFractionMatching) { AdsServiceImpl::EdsResourceArgs args1({ {"locality0", GetBackendPorts(1, 2)}, }); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args1, kNewEdsServiceName)); + BuildEdsResource(args1, kNewEdsServiceName)); // Populate new CDS resources. Cluster new_cluster = balancers_[0]->ads_service()->default_cluster(); new_cluster.set_name(kNewClusterName); @@ -4872,14 +4848,13 @@ TEST_P(LdsRdsTest, XdsRoutingHeadersMatchingUnmatchCases) { AdsServiceImpl::EdsResourceArgs args3({ {"locality0", GetBackendPorts(3, 4)}, }); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); + BuildEdsResource(args1, kNewEdsService1Name)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args1, kNewEdsService1Name)); + BuildEdsResource(args2, kNewEdsService2Name)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args2, kNewEdsService2Name)); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args3, kNewEdsService3Name)); + BuildEdsResource(args3, kNewEdsService3Name)); // Populate new CDS resources. Cluster new_cluster1 = balancers_[0]->ads_service()->default_cluster(); new_cluster1.set_name(kNewCluster1Name); @@ -4961,10 +4936,9 @@ TEST_P(LdsRdsTest, XdsRoutingChangeRoutesWithoutChangingClusters) { AdsServiceImpl::EdsResourceArgs args1({ {"locality0", GetBackendPorts(1, 2)}, }); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args1, kNewEdsServiceName)); + BuildEdsResource(args1, kNewEdsServiceName)); // Populate new CDS resources. Cluster new_cluster = balancers_[0]->ads_service()->default_cluster(); new_cluster.set_name(kNewClusterName); @@ -5095,8 +5069,7 @@ TEST_P(EdsTest, NacksSparsePriorityList) { AdsServiceImpl::EdsResourceArgs args({ {"locality0", GetBackendPorts(), kDefaultLocalityWeight, 1}, }); - balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args)); + balancers_[0]->ads_service()->SetEdsResource(BuildEdsResource(args)); CheckRpcSendFailure(); const auto& response_state = balancers_[0]->ads_service()->eds_response_state(); @@ -5115,7 +5088,7 @@ TEST_P(EdsTest, EdsServiceNameDefaultsToClusterName) { {"locality0", GetBackendPorts()}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, kDefaultClusterName)); + BuildEdsResource(args, kDefaultClusterName)); Cluster cluster = balancers_[0]->ads_service()->default_cluster(); cluster.mutable_eds_cluster_config()->clear_service_name(); balancers_[0]->ads_service()->SetCdsResource(cluster); @@ -5183,7 +5156,7 @@ TEST_P(LocalityMapTest, WeightedRoundRobin) { {"locality1", GetBackendPorts(1, 2), kLocalityWeight1}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); // Wait for both backends to be ready. WaitForAllBackends(0, 2); // Send kNumRpcs RPCs. @@ -5217,7 +5190,7 @@ TEST_P(LocalityMapTest, LocalityContainingNoEndpoints) { {"locality1", {}}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); // Wait for both backends to be ready. WaitForAllBackends(); // Send kNumRpcs RPCs. @@ -5238,7 +5211,7 @@ TEST_P(LocalityMapTest, NoLocalities) { SetNextResolution({}); SetNextResolutionForLbChannelAllBalancers(); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource({}, DefaultEdsServiceName())); + BuildEdsResource({}, DefaultEdsServiceName())); Status status = SendRpc(); EXPECT_FALSE(status.ok()); EXPECT_EQ(status.error_code(), StatusCode::UNAVAILABLE); @@ -5260,15 +5233,14 @@ TEST_P(LocalityMapTest, StressTest) { args.locality_list.emplace_back(std::move(locality)); } balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); // 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, DefaultEdsServiceName()), - 60 * 1000)); + BuildEdsResource(args, DefaultEdsServiceName()), 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); @@ -5310,7 +5282,7 @@ TEST_P(LocalityMapTest, UpdateMap) { {"locality2", GetBackendPorts(2, 3), 4}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); // Wait for the first 3 backends to be ready. WaitForAllBackends(0, 3); gpr_log(GPR_INFO, "========= BEFORE FIRST BATCH =========="); @@ -5341,7 +5313,7 @@ TEST_P(LocalityMapTest, UpdateMap) { {"locality3", GetBackendPorts(3, 4), 6}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); // 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 @@ -5381,13 +5353,13 @@ TEST_P(LocalityMapTest, ReplaceAllLocalitiesInPriority) { {"locality0", GetBackendPorts(0, 1)}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); args = AdsServiceImpl::EdsResourceArgs({ {"locality1", GetBackendPorts(1, 2)}, }); - std::thread delayed_resource_setter(std::bind( - &BasicTest::SetEdsResourceWithDelay, this, 0, - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName()), 5000)); + std::thread delayed_resource_setter( + std::bind(&BasicTest::SetEdsResourceWithDelay, this, 0, + BuildEdsResource(args, DefaultEdsServiceName()), 5000)); // Wait for the first backend to be ready. WaitForBackend(0); // Keep sending RPCs until we switch over to backend 1, which tells us @@ -5416,7 +5388,7 @@ TEST_P(FailoverTest, ChooseHighestPriority) { {"locality3", GetBackendPorts(3, 4), kDefaultLocalityWeight, 0}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); WaitForBackend(3, false); for (size_t i = 0; i < 3; ++i) { EXPECT_EQ(0U, backends_[i]->backend_service()->request_count()); @@ -5434,7 +5406,7 @@ TEST_P(FailoverTest, DoesNotUsePriorityWithNoEndpoints) { {"locality3", {}, kDefaultLocalityWeight, 0}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); WaitForBackend(0, false); for (size_t i = 1; i < 3; ++i) { EXPECT_EQ(0U, backends_[i]->backend_service()->request_count()); @@ -5450,7 +5422,7 @@ TEST_P(FailoverTest, DoesNotUseLocalityWithNoEndpoints) { {"locality1", GetBackendPorts(), kDefaultLocalityWeight, 0}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); // Wait for all backends to be used. std::tuple counts = WaitForAllBackends(); // Make sure no RPCs failed in the transition. @@ -5471,7 +5443,7 @@ TEST_P(FailoverTest, Failover) { ShutdownBackend(3); ShutdownBackend(0); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); WaitForBackend(1, false); for (size_t i = 0; i < 4; ++i) { if (i == 1) continue; @@ -5494,7 +5466,7 @@ TEST_P(FailoverTest, SwitchBackToHigherPriority) { ShutdownBackend(3); ShutdownBackend(0); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); WaitForBackend(1, false); for (size_t i = 0; i < 4; ++i) { if (i == 1) continue; @@ -5516,7 +5488,7 @@ TEST_P(FailoverTest, UpdateInitialUnavailable) { {"locality1", GetBackendPorts(1, 2), kDefaultLocalityWeight, 1}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); args = AdsServiceImpl::EdsResourceArgs({ {"locality0", GetBackendPorts(0, 1), kDefaultLocalityWeight, 0}, {"locality1", GetBackendPorts(1, 2), kDefaultLocalityWeight, 1}, @@ -5525,9 +5497,9 @@ TEST_P(FailoverTest, UpdateInitialUnavailable) { }); ShutdownBackend(0); ShutdownBackend(1); - std::thread delayed_resource_setter(std::bind( - &BasicTest::SetEdsResourceWithDelay, this, 0, - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName()), 1000)); + std::thread delayed_resource_setter( + std::bind(&BasicTest::SetEdsResourceWithDelay, this, 0, + BuildEdsResource(args, DefaultEdsServiceName()), 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. @@ -5555,16 +5527,16 @@ TEST_P(FailoverTest, UpdatePriority) { {"locality3", GetBackendPorts(3, 4), kDefaultLocalityWeight, 0}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); 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, DefaultEdsServiceName()), 1000)); + std::thread delayed_resource_setter( + std::bind(&BasicTest::SetEdsResourceWithDelay, this, 0, + BuildEdsResource(args, DefaultEdsServiceName()), 1000)); WaitForBackend(3, false); for (size_t i = 0; i < 3; ++i) { EXPECT_EQ(0U, backends_[i]->backend_service()->request_count()); @@ -5588,7 +5560,7 @@ TEST_P(FailoverTest, MoveAllLocalitiesInCurrentPriorityToHigherPriority) { {"locality1", GetBackendPorts(1, 3), kDefaultLocalityWeight, 1}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); // Second update: // - Priority 0 contains both localities 0 and 1. // - Priority 1 is not present. @@ -5598,9 +5570,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, DefaultEdsServiceName()), 1000)); + std::thread delayed_resource_setter( + std::bind(&BasicTest::SetEdsResourceWithDelay, this, 0, + BuildEdsResource(args, DefaultEdsServiceName()), 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. @@ -5634,7 +5606,7 @@ TEST_P(DropTest, Vanilla) { args.drop_categories = {{kLbDropType, kDropPerMillionForLb}, {kThrottleDropType, kDropPerMillionForThrottle}}; balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); WaitForAllBackends(); // Send kNumRpcs RPCs and count the drops. size_t num_drops = 0; @@ -5674,7 +5646,7 @@ TEST_P(DropTest, DropPerHundred) { args.drop_categories = {{kLbDropType, kDropPerHundredForLb}}; args.drop_denominator = FractionalPercent::HUNDRED; balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); WaitForAllBackends(); // Send kNumRpcs RPCs and count the drops. size_t num_drops = 0; @@ -5713,7 +5685,7 @@ TEST_P(DropTest, DropPerTenThousand) { args.drop_categories = {{kLbDropType, kDropPerTenThousandForLb}}; args.drop_denominator = FractionalPercent::TEN_THOUSAND; balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); WaitForAllBackends(); // Send kNumRpcs RPCs and count the drops. size_t num_drops = 0; @@ -5755,7 +5727,7 @@ TEST_P(DropTest, Update) { }); args.drop_categories = {{kLbDropType, kDropPerMillionForLb}}; balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); WaitForAllBackends(); // Send kNumRpcs RPCs and count the drops. size_t num_drops = 0; @@ -5786,7 +5758,7 @@ TEST_P(DropTest, Update) { args.drop_categories = {{kLbDropType, kDropPerMillionForLb}, {kThrottleDropType, kDropPerMillionForThrottle}}; balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); // 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 = @@ -5844,7 +5816,7 @@ TEST_P(DropTest, DropAll) { args.drop_categories = {{kLbDropType, kDropPerMillionForLb}, {kThrottleDropType, kDropPerMillionForThrottle}}; balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); // Send kNumRpcs RPCs and all of them are dropped. for (size_t i = 0; i < kNumRpcs; ++i) { EchoResponse response; @@ -5868,12 +5840,12 @@ TEST_P(BalancerUpdateTest, UpdateBalancersButKeepUsingOriginalBalancer) { {"locality0", {backends_[0]->port()}}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); args = AdsServiceImpl::EdsResourceArgs({ {"locality0", {backends_[1]->port()}}, }); balancers_[1]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); // Wait until the first backend is ready. WaitForBackend(0); // Send 10 requests. @@ -5931,12 +5903,12 @@ TEST_P(BalancerUpdateTest, Repeated) { {"locality0", {backends_[0]->port()}}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); args = AdsServiceImpl::EdsResourceArgs({ {"locality0", {backends_[1]->port()}}, }); balancers_[1]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); // Wait until the first backend is ready. WaitForBackend(0); // Send 10 requests. @@ -6001,12 +5973,12 @@ TEST_P(BalancerUpdateTest, DeadUpdate) { {"locality0", {backends_[0]->port()}}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); args = AdsServiceImpl::EdsResourceArgs({ {"locality0", {backends_[1]->port()}}, }); balancers_[1]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); // Start servers and send 10 RPCs per server. gpr_log(GPR_INFO, "========= BEFORE FIRST BATCH =========="); CheckRpcSendOk(10); @@ -6096,7 +6068,7 @@ TEST_P(ClientLoadReportingTest, Vanilla) { {"locality0", GetBackendPorts()}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); // Wait until all backends are ready. int num_ok = 0; int num_failure = 0; @@ -6143,7 +6115,7 @@ TEST_P(ClientLoadReportingTest, SendAllClusters) { {"locality0", GetBackendPorts()}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); // Wait until all backends are ready. int num_ok = 0; int num_failure = 0; @@ -6188,7 +6160,7 @@ TEST_P(ClientLoadReportingTest, HonorsClustersRequestedByLrsServer) { {"locality0", GetBackendPorts()}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); // Wait until all backends are ready. int num_ok = 0; int num_failure = 0; @@ -6225,7 +6197,7 @@ TEST_P(ClientLoadReportingTest, BalancerRestart) { {"locality0", GetBackendPorts(0, kNumBackendsFirstPass)}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); // Wait until all backends returned by the balancer are ready. int num_ok = 0; int num_failure = 0; @@ -6263,7 +6235,7 @@ TEST_P(ClientLoadReportingTest, BalancerRestart) { {"locality0", GetBackendPorts(kNumBackendsFirstPass)}, }); balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); // 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) = @@ -6308,7 +6280,7 @@ TEST_P(ClientLoadReportingWithDropTest, Vanilla) { args.drop_categories = {{kLbDropType, kDropPerMillionForLb}, {kThrottleDropType, kDropPerMillionForThrottle}}; balancers_[0]->ads_service()->SetEdsResource( - AdsServiceImpl::BuildEdsResource(args, DefaultEdsServiceName())); + BuildEdsResource(args, DefaultEdsServiceName())); int num_ok = 0; int num_failure = 0; int num_drops = 0; diff --git a/test/cpp/ext/filters/census/stats_plugin_end2end_test.cc b/test/cpp/ext/filters/census/stats_plugin_end2end_test.cc index 1e71910b276..0155cb27b1c 100644 --- a/test/cpp/ext/filters/census/stats_plugin_end2end_test.cc +++ b/test/cpp/ext/filters/census/stats_plugin_end2end_test.cc @@ -81,7 +81,7 @@ class StatsPluginEnd2EndTest : public ::testing::Test { server_ = builder.BuildAndStart(); ASSERT_NE(nullptr, server_); ASSERT_NE(0, port); - server_address_ = absl::StrCat("0.0.0.0:", port); + server_address_ = absl::StrCat("localhost:", port); server_thread_ = std::thread(&StatsPluginEnd2EndTest::RunServerLoop, this); stub_ = EchoTestService::NewStub(::grpc::CreateChannel(