From 9dd6a98ed69a943a1bfe2763788168b90170a9a3 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 8 Feb 2023 14:31:07 -0800 Subject: [PATCH] e2e tests: update regex used for connection failure messages (#32325) * e2e tests: update regex used for connection failure messages * attempt to tweak regex syntax to work on mac --- test/cpp/end2end/client_lb_end2end_test.cc | 14 +++++----- .../end2end/xds/xds_cluster_end2end_test.cc | 26 ++++++------------- test/cpp/end2end/xds/xds_end2end_test_lib.cc | 10 +++++++ test/cpp/end2end/xds/xds_end2end_test_lib.h | 4 +++ .../end2end/xds/xds_ring_hash_end2end_test.cc | 21 +++++---------- .../end2end/xds/xds_routing_end2end_test.cc | 15 +++++------ 6 files changed, 40 insertions(+), 50 deletions(-) diff --git a/test/cpp/end2end/client_lb_end2end_test.cc b/test/cpp/end2end/client_lb_end2end_test.cc index 0c95d5599fe..7d00c72f128 100644 --- a/test/cpp/end2end/client_lb_end2end_test.cc +++ b/test/cpp/end2end/client_lb_end2end_test.cc @@ -568,14 +568,12 @@ class ClientLbEnd2endTest : public ::testing::Test { } static std::string MakeConnectionFailureRegex(absl::string_view prefix) { - return absl::StrCat( - prefix, - "; last error: (UNKNOWN: (ipv6:%5B::1%5D|ipv4:127.0.0.1):[0-9]+: " - "Failed to connect to remote host: Connection refused|" - "UNAVAILABLE: (ipv6:%5B::1%5D|ipv4:127.0.0.1):[0-9]+: " - "Failed to connect to remote host: FD shutdown|" - "UNAVAILABLE: (ipv6:%5B::1%5D|ipv4:127.0.0.1):[0-9]+: " - "(Socket closed|Connection reset by peer))"); + return absl::StrCat(prefix, + "; last error: (UNKNOWN|UNAVAILABLE): " + "(ipv6:%5B::1%5D|ipv4:127.0.0.1):[0-9]+: " + "(Failed to connect to remote host: )?" + "(Connection refused|Connection reset by peer|" + "Socket closed|FD shutdown)"); } const std::string server_host_; diff --git a/test/cpp/end2end/xds/xds_cluster_end2end_test.cc b/test/cpp/end2end/xds/xds_cluster_end2end_test.cc index 693ff415d6b..667de8cec32 100644 --- a/test/cpp/end2end/xds/xds_cluster_end2end_test.cc +++ b/test/cpp/end2end/xds/xds_cluster_end2end_test.cc @@ -499,11 +499,8 @@ TEST_P(EdsTest, AllServersUnreachableFailFast) { // seconds, and we should disocver in that time that the target backend is // down. CheckRpcSendFailure(DEBUG_LOCATION, StatusCode::UNAVAILABLE, - "connections to all backends failing; last error: " - "(UNKNOWN: (ipv6:%5B::1%5D|ipv4:127.0.0.1):[0-9]+: " - "Failed to connect to remote host: Connection refused|" - "UNAVAILABLE: (ipv6:%5B::1%5D|ipv4:127.0.0.1):[0-9]+: " - "Failed to connect to remote host: FD shutdown)", + MakeConnectionFailureRegex( + "connections to all backends failing; last error: "), RpcOptions().set_timeout_ms(kRpcTimeoutMs)); } @@ -526,11 +523,8 @@ TEST_P(EdsTest, BackendsRestart) { ::testing::Eq(GRPC_CHANNEL_CONNECTING))); // RPCs should fail. CheckRpcSendFailure(DEBUG_LOCATION, StatusCode::UNAVAILABLE, - "connections to all backends failing; last error: " - "(UNKNOWN: (ipv6:%5B::1%5D|ipv4:127.0.0.1):[0-9]+: " - "Failed to connect to remote host: Connection refused|" - "UNAVAILABLE: (ipv6:%5B::1%5D|ipv4:127.0.0.1):[0-9]+: " - "Failed to connect to remote host: FD shutdown)"); + MakeConnectionFailureRegex( + "connections to all backends failing; last error: ")); // Restart all backends. RPCs should start succeeding again. StartAllBackends(); CheckRpcSendOk(DEBUG_LOCATION, 1, @@ -1176,14 +1170,9 @@ TEST_P(FailoverTest, UpdateInitialUnavailable) { {"locality1", {MakeNonExistantEndpoint()}, kDefaultLocalityWeight, 1}, }); balancer_->ads_service()->SetEdsResource(BuildEdsResource(args)); - constexpr char kErrorMessageRegex[] = - "connections to all backends failing; last error: " - "(UNKNOWN: (ipv6:%5B::1%5D|ipv4:127.0.0.1):[0-9]+: " - "Failed to connect to remote host: Connection refused|" - "UNAVAILABLE: (ipv6:%5B::1%5D|ipv4:127.0.0.1):[0-9]+: " - "Failed to connect to remote host: FD shutdown)"; CheckRpcSendFailure(DEBUG_LOCATION, StatusCode::UNAVAILABLE, - kErrorMessageRegex); + MakeConnectionFailureRegex( + "connections to all backends failing; last error: ")); args = EdsResourceArgs({ {"locality0", CreateEndpointsForBackends(0, 1), kDefaultLocalityWeight, 0}, @@ -1195,7 +1184,8 @@ TEST_P(FailoverTest, UpdateInitialUnavailable) { if (!result.status.ok()) { EXPECT_EQ(result.status.error_code(), StatusCode::UNAVAILABLE); EXPECT_THAT(result.status.error_message(), - ::testing::MatchesRegex(kErrorMessageRegex)); + ::testing::MatchesRegex(MakeConnectionFailureRegex( + "connections to all backends failing; last error: "))); } }); } diff --git a/test/cpp/end2end/xds/xds_end2end_test_lib.cc b/test/cpp/end2end/xds/xds_end2end_test_lib.cc index 53061468986..e98cbfcee1b 100644 --- a/test/cpp/end2end/xds/xds_end2end_test_lib.cc +++ b/test/cpp/end2end/xds/xds_end2end_test_lib.cc @@ -1038,6 +1038,16 @@ void XdsEnd2endTest::SetProtoDuration( duration_proto->set_nanos(ts.tv_nsec); } +std::string XdsEnd2endTest::MakeConnectionFailureRegex( + absl::string_view prefix) { + return absl::StrCat( + prefix, + "(UNKNOWN|UNAVAILABLE): (ipv6:%5B::1%5D|ipv4:127.0.0.1):[0-9]+: " + "(Failed to connect to remote host: )?" + "(Connection refused|Connection reset by peer|" + "Socket closed|FD shutdown)"); +} + std::string XdsEnd2endTest::ReadFile(const char* file_path) { grpc_slice slice; GPR_ASSERT( diff --git a/test/cpp/end2end/xds/xds_end2end_test_lib.h b/test/cpp/end2end/xds/xds_end2end_test_lib.h index ba8767dddd9..afafe250c4e 100644 --- a/test/cpp/end2end/xds/xds_end2end_test_lib.h +++ b/test/cpp/end2end/xds/xds_end2end_test_lib.h @@ -1046,6 +1046,10 @@ class XdsEnd2endTest : public ::testing::TestWithParam { return num_rpcs; } + // Returns a regex that can be matched against an RPC failure status + // message for a connection failure. + static std::string MakeConnectionFailureRegex(absl::string_view prefix); + // Returns the contents of the specified file. static std::string ReadFile(const char* file_path); diff --git a/test/cpp/end2end/xds/xds_ring_hash_end2end_test.cc b/test/cpp/end2end/xds/xds_ring_hash_end2end_test.cc index 42baff5a8f8..28545a55a0d 100644 --- a/test/cpp/end2end/xds/xds_ring_hash_end2end_test.cc +++ b/test/cpp/end2end/xds/xds_ring_hash_end2end_test.cc @@ -994,11 +994,8 @@ TEST_P(RingHashTest, ReattemptWhenAllEndpointsUnreachable) { ShutdownBackend(0); CheckRpcSendFailure( DEBUG_LOCATION, StatusCode::UNAVAILABLE, - "ring hash cannot find a connected subchannel; first failure: " - "(UNKNOWN: (ipv6:%5B::1%5D|ipv4:127.0.0.1):[0-9]+: " - "Failed to connect to remote host: Connection refused|" - "UNAVAILABLE: (ipv6:%5B::1%5D|ipv4:127.0.0.1):[0-9]+: " - "Failed to connect to remote host: FD shutdown)", + MakeConnectionFailureRegex( + "ring hash cannot find a connected subchannel; first failure: "), RpcOptions().set_metadata(std::move(metadata))); StartBackend(0); // Ensure we are actively connecting without any traffic. @@ -1036,11 +1033,8 @@ TEST_P(RingHashTest, TransientFailureSkipToAvailableReady) { gpr_log(GPR_INFO, "=== SENDING FIRST RPC ==="); CheckRpcSendFailure( DEBUG_LOCATION, StatusCode::UNAVAILABLE, - "ring hash cannot find a connected subchannel; first failure: " - "(UNKNOWN: (ipv6:%5B::1%5D|ipv4:127.0.0.1):[0-9]+: " - "Failed to connect to remote host: Connection refused|" - "UNAVAILABLE: (ipv6:%5B::1%5D|ipv4:127.0.0.1):[0-9]+: " - "Failed to connect to remote host: FD shutdown)", + MakeConnectionFailureRegex( + "ring hash cannot find a connected subchannel; first failure: "), rpc_options); gpr_log(GPR_INFO, "=== DONE WITH FIRST RPC ==="); EXPECT_EQ(GRPC_CHANNEL_TRANSIENT_FAILURE, channel_->GetState(false)); @@ -1075,11 +1069,8 @@ TEST_P(RingHashTest, TransientFailureSkipToAvailableReady) { gpr_log(GPR_INFO, "=== SENDING SECOND RPC ==="); CheckRpcSendFailure( DEBUG_LOCATION, StatusCode::UNAVAILABLE, - "ring hash cannot find a connected subchannel; first failure: " - "(UNKNOWN: (ipv6:%5B::1%5D|ipv4:127.0.0.1):[0-9]+: " - "Failed to connect to remote host: Connection refused|" - "UNAVAILABLE: (ipv6:%5B::1%5D|ipv4:127.0.0.1):[0-9]+: " - "Failed to connect to remote host: FD shutdown)", + MakeConnectionFailureRegex( + "ring hash cannot find a connected subchannel; first failure: "), rpc_options); gpr_log(GPR_INFO, "=== STARTING BACKEND 1 ==="); StartBackend(1); diff --git a/test/cpp/end2end/xds/xds_routing_end2end_test.cc b/test/cpp/end2end/xds/xds_routing_end2end_test.cc index c19eeeb1755..1b61749ffcc 100644 --- a/test/cpp/end2end/xds/xds_routing_end2end_test.cc +++ b/test/cpp/end2end/xds/xds_routing_end2end_test.cc @@ -1473,14 +1473,9 @@ TEST_P(LdsRdsTest, XdsRoutingClusterUpdateClustersWithPickingDelays) { RpcOptions().set_wait_for_ready(true).set_timeout_ms(0)); // Send a non-wait_for_ready RPC, which should fail. This tells us // that the client has received the update and attempted to connect. - constexpr char kErrorMessageRegex[] = - "connections to all backends failing; last error: " - "(UNKNOWN: (ipv6:%5B::1%5D|ipv4:127.0.0.1):[0-9]+: " - "Failed to connect to remote host: Connection refused|" - "UNAVAILABLE: (ipv6:%5B::1%5D|ipv4:127.0.0.1):[0-9]+: " - "Failed to connect to remote host: FD shutdown)"; CheckRpcSendFailure(DEBUG_LOCATION, StatusCode::UNAVAILABLE, - kErrorMessageRegex); + MakeConnectionFailureRegex( + "connections to all backends failing; last error: ")); // Now create a new cluster, pointing to backend 1. const char* kNewClusterName = "new_cluster"; const char* kNewEdsServiceName = "new_eds_service_name"; @@ -1506,8 +1501,10 @@ TEST_P(LdsRdsTest, XdsRoutingClusterUpdateClustersWithPickingDelays) { [&](const RpcResult& result) { if (!result.status.ok()) { EXPECT_EQ(result.status.error_code(), StatusCode::UNAVAILABLE); - EXPECT_THAT(result.status.error_message(), - ::testing::MatchesRegex(kErrorMessageRegex)); + EXPECT_THAT( + result.status.error_message(), + ::testing::MatchesRegex(MakeConnectionFailureRegex( + "connections to all backends failing; last error: "))); } }, WaitForBackendOptions().set_reset_counters(false));