|
|
|
@ -625,6 +625,7 @@ class XdsClientTest : public ::testing::Test { |
|
|
|
|
using ResourceUpdateMap = std::map< |
|
|
|
|
std::pair<std::string /*xds_server*/, std::string /*resource_type*/>, |
|
|
|
|
uint64_t>; |
|
|
|
|
using ServerFailureMap = std::map<std::string /*xds_server*/, uint64_t>; |
|
|
|
|
|
|
|
|
|
const ResourceUpdateMap& resource_updates_valid() const { |
|
|
|
|
return resource_updates_valid_; |
|
|
|
@ -632,6 +633,7 @@ class XdsClientTest : public ::testing::Test { |
|
|
|
|
const ResourceUpdateMap& resource_updates_invalid() const { |
|
|
|
|
return resource_updates_invalid_; |
|
|
|
|
} |
|
|
|
|
const ServerFailureMap& server_failures() const { return server_failures_; } |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
void ReportResourceUpdates(absl::string_view xds_server, |
|
|
|
@ -648,8 +650,13 @@ class XdsClientTest : public ::testing::Test { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ReportServerFailure(absl::string_view xds_server) override { |
|
|
|
|
++server_failures_[std::string(xds_server)]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ResourceUpdateMap resource_updates_valid_; |
|
|
|
|
ResourceUpdateMap resource_updates_invalid_; |
|
|
|
|
ServerFailureMap server_failures_; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
using ResourceCounts = |
|
|
|
@ -876,6 +883,7 @@ TEST_F(XdsClientTest, BasicWatch) { |
|
|
|
|
::testing::ElementsAre()); |
|
|
|
|
EXPECT_THAT(GetResourceCounts(), ::testing::ElementsAre()); |
|
|
|
|
EXPECT_THAT(GetServerConnections(), ::testing::ElementsAre()); |
|
|
|
|
EXPECT_THAT(metrics_reporter_->server_failures(), ::testing::ElementsAre()); |
|
|
|
|
// Start a watch for "foo1".
|
|
|
|
|
auto watcher = StartFooWatch("foo1"); |
|
|
|
|
// Check metrics.
|
|
|
|
@ -2303,6 +2311,7 @@ TEST_F(XdsClientTest, StreamClosedByServerWithoutSeeingResponse) { |
|
|
|
|
// Check metric data.
|
|
|
|
|
EXPECT_THAT(GetServerConnections(), ::testing::ElementsAre(::testing::Pair( |
|
|
|
|
kDefaultXdsServerUrl, true))); |
|
|
|
|
EXPECT_THAT(metrics_reporter_->server_failures(), ::testing::ElementsAre()); |
|
|
|
|
// Watcher should initially not see any resource reported.
|
|
|
|
|
EXPECT_FALSE(watcher->HasEvent()); |
|
|
|
|
// XdsClient should have created an ADS stream.
|
|
|
|
@ -2321,6 +2330,8 @@ TEST_F(XdsClientTest, StreamClosedByServerWithoutSeeingResponse) { |
|
|
|
|
// Check metric data.
|
|
|
|
|
EXPECT_THAT(GetServerConnections(), ::testing::ElementsAre(::testing::Pair( |
|
|
|
|
kDefaultXdsServerUrl, false))); |
|
|
|
|
EXPECT_THAT(metrics_reporter_->server_failures(), |
|
|
|
|
::testing::ElementsAre(::testing::Pair(kDefaultXdsServerUrl, 1))); |
|
|
|
|
// XdsClient should report an error to the watcher.
|
|
|
|
|
auto error = watcher->WaitForNextError(); |
|
|
|
|
ASSERT_TRUE(error.has_value()); |
|
|
|
@ -2344,6 +2355,8 @@ TEST_F(XdsClientTest, StreamClosedByServerWithoutSeeingResponse) { |
|
|
|
|
// Connection still reported as unhappy until we get a response.
|
|
|
|
|
EXPECT_THAT(GetServerConnections(), ::testing::ElementsAre(::testing::Pair( |
|
|
|
|
kDefaultXdsServerUrl, false))); |
|
|
|
|
EXPECT_THAT(metrics_reporter_->server_failures(), |
|
|
|
|
::testing::ElementsAre(::testing::Pair(kDefaultXdsServerUrl, 1))); |
|
|
|
|
// Server now sends the requested resource.
|
|
|
|
|
stream->SendMessageToClient( |
|
|
|
|
ResponseBuilder(XdsFooResourceType::Get()->type_url()) |
|
|
|
@ -2380,6 +2393,7 @@ TEST_F(XdsClientTest, ConnectionFails) { |
|
|
|
|
transport_factory_->SetAutoCompleteMessagesFromClient(false); |
|
|
|
|
// Metrics should initially be empty.
|
|
|
|
|
EXPECT_THAT(GetServerConnections(), ::testing::ElementsAre()); |
|
|
|
|
EXPECT_THAT(metrics_reporter_->server_failures(), ::testing::ElementsAre()); |
|
|
|
|
// Start a watch for "foo1".
|
|
|
|
|
auto watcher = StartFooWatch("foo1"); |
|
|
|
|
// Check metric data.
|
|
|
|
@ -2412,6 +2426,8 @@ TEST_F(XdsClientTest, ConnectionFails) { |
|
|
|
|
// Connection reported as unhappy.
|
|
|
|
|
EXPECT_THAT(GetServerConnections(), ::testing::ElementsAre(::testing::Pair( |
|
|
|
|
kDefaultXdsServerUrl, false))); |
|
|
|
|
EXPECT_THAT(metrics_reporter_->server_failures(), |
|
|
|
|
::testing::ElementsAre(::testing::Pair(kDefaultXdsServerUrl, 1))); |
|
|
|
|
// We should not see a resource-does-not-exist event, because the
|
|
|
|
|
// timer should not be running while the channel is disconnected.
|
|
|
|
|
EXPECT_TRUE(watcher->ExpectNoEvent(absl::Seconds(4))); |
|
|
|
@ -3709,6 +3725,9 @@ TEST_F(XdsClientTest, FederationChannelFailureReportedToWatchers) { |
|
|
|
|
::testing::ElementsAre( |
|
|
|
|
::testing::Pair(kDefaultXdsServerUrl, true), |
|
|
|
|
::testing::Pair(authority_server.server_uri(), false))); |
|
|
|
|
EXPECT_THAT(metrics_reporter_->server_failures(), |
|
|
|
|
::testing::ElementsAre( |
|
|
|
|
::testing::Pair(authority_server.server_uri(), 1))); |
|
|
|
|
// Cancel watch for "foo1".
|
|
|
|
|
CancelFooWatch(watcher.get(), "foo1"); |
|
|
|
|
EXPECT_TRUE(stream->Orphaned()); |
|
|
|
@ -3821,6 +3840,7 @@ TEST_F(XdsClientTest, FallbackAndRecover) { |
|
|
|
|
1))); |
|
|
|
|
EXPECT_THAT(metrics_reporter_->resource_updates_valid(), |
|
|
|
|
::testing::IsEmpty()); |
|
|
|
|
EXPECT_THAT(metrics_reporter_->server_failures(), ::testing::ElementsAre()); |
|
|
|
|
// XdsClient should have created an ADS stream.
|
|
|
|
|
auto stream = WaitForAdsStream(); |
|
|
|
|
ASSERT_TRUE(stream != nullptr); |
|
|
|
@ -3875,11 +3895,15 @@ TEST_F(XdsClientTest, FallbackAndRecover) { |
|
|
|
|
// Result (local): The metrics show the channel as being unhealthy.
|
|
|
|
|
EXPECT_THAT(GetServerConnections(), ::testing::ElementsAre(::testing::Pair( |
|
|
|
|
kDefaultXdsServerUrl, false))); |
|
|
|
|
EXPECT_THAT(metrics_reporter_->server_failures(), |
|
|
|
|
::testing::ElementsAre(::testing::Pair(kDefaultXdsServerUrl, 1))); |
|
|
|
|
// Input: Trigger stream failure.
|
|
|
|
|
stream->MaybeSendStatusToClient(absl::UnavailableError("Stream failure")); |
|
|
|
|
// Result (local): The metrics still show the channel as being unhealthy.
|
|
|
|
|
EXPECT_THAT(GetServerConnections(), ::testing::ElementsAre(::testing::Pair( |
|
|
|
|
kDefaultXdsServerUrl, false))); |
|
|
|
|
EXPECT_THAT(metrics_reporter_->server_failures(), |
|
|
|
|
::testing::ElementsAre(::testing::Pair(kDefaultXdsServerUrl, 1))); |
|
|
|
|
// Result (remote): The client starts a new stream and sends a subscription
|
|
|
|
|
// message. Note that the server does not respond, so the channel will still
|
|
|
|
|
// have non-OK status.
|
|
|
|
@ -3998,6 +4022,8 @@ TEST_F(XdsClientTest, FallbackAndRecover) { |
|
|
|
|
2))); |
|
|
|
|
EXPECT_THAT(GetServerConnections(), ::testing::ElementsAre(::testing::Pair( |
|
|
|
|
kDefaultXdsServerUrl, true))); |
|
|
|
|
EXPECT_THAT(metrics_reporter_->server_failures(), |
|
|
|
|
::testing::ElementsAre(::testing::Pair(kDefaultXdsServerUrl, 1))); |
|
|
|
|
// Result (remote): The stream to the fallback server has been orphaned.
|
|
|
|
|
EXPECT_TRUE(stream2->Orphaned()); |
|
|
|
|
// Result (local): Resources are delivered to watchers.
|
|
|
|
@ -4053,6 +4079,8 @@ TEST_F(XdsClientTest, FallbackReportsError) { |
|
|
|
|
::testing::ElementsAre( |
|
|
|
|
::testing::Pair(kDefaultXdsServerUrl, false), |
|
|
|
|
::testing::Pair(fallback_server.server_uri(), true))); |
|
|
|
|
EXPECT_THAT(metrics_reporter_->server_failures(), |
|
|
|
|
::testing::ElementsAre(::testing::Pair(kDefaultXdsServerUrl, 1))); |
|
|
|
|
// Fallback happens now
|
|
|
|
|
stream = WaitForAdsStream(fallback_server); |
|
|
|
|
ASSERT_NE(stream, nullptr); |
|
|
|
@ -4068,6 +4096,10 @@ TEST_F(XdsClientTest, FallbackReportsError) { |
|
|
|
|
::testing::ElementsAre( |
|
|
|
|
::testing::Pair(kDefaultXdsServerUrl, false), |
|
|
|
|
::testing::Pair(fallback_server.server_uri(), false))); |
|
|
|
|
EXPECT_THAT( |
|
|
|
|
metrics_reporter_->server_failures(), |
|
|
|
|
::testing::ElementsAre(::testing::Pair(kDefaultXdsServerUrl, 1), |
|
|
|
|
::testing::Pair(fallback_server.server_uri(), 1))); |
|
|
|
|
auto error = watcher->WaitForNextError(); |
|
|
|
|
ASSERT_TRUE(error.has_value()); |
|
|
|
|
EXPECT_THAT(error->code(), absl::StatusCode::kUnavailable); |
|
|
|
@ -4117,6 +4149,8 @@ TEST_F(XdsClientTest, FallbackOnStartup) { |
|
|
|
|
::testing::ElementsAre( |
|
|
|
|
::testing::Pair(kDefaultXdsServerUrl, false), |
|
|
|
|
::testing::Pair(fallback_server.server_uri(), true))); |
|
|
|
|
EXPECT_THAT(metrics_reporter_->server_failures(), |
|
|
|
|
::testing::ElementsAre(::testing::Pair(kDefaultXdsServerUrl, 1))); |
|
|
|
|
// XdsClient should have delivered the response to the watcher.
|
|
|
|
|
auto resource = watcher->WaitForNextResource(); |
|
|
|
|
ASSERT_NE(resource, nullptr); |
|
|
|
|