Skip to content

Commit

Permalink
Fix flaky tests ProxyProtoFilterChainMatchIntegrationTest (envoyproxy…
Browse files Browse the repository at this point in the history
…#17689)

Signed-off-by: Greg Greenway <[email protected]>
  • Loading branch information
ggreenway authored Aug 12, 2021
1 parent 4e73a21 commit d5b508b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
34 changes: 16 additions & 18 deletions test/integration/proxy_proto_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -314,30 +314,33 @@ ProxyProtoFilterChainMatchIntegrationTest::ProxyProtoFilterChainMatchIntegration
});
}

void ProxyProtoFilterChainMatchIntegrationTest::send(const std::string& data) {
initialize();

// Set verify to false because it is expected that Envoy will immediately disconnect after
// receiving the PROXY header, and it is a race whether the `write()` will fail due to
// disconnect, or finish the write before receiving the disconnect.
constexpr bool verify = false;

IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("tcp_proxy"));
ASSERT_TRUE(tcp_client->write(data, false, verify));
tcp_client->waitForDisconnect();
}

INSTANTIATE_TEST_SUITE_P(IpVersions, ProxyProtoFilterChainMatchIntegrationTest,
testing::ValuesIn(TestEnvironment::getIpVersionsForTest()),
TestUtility::ipTestParamsToString);

// Validate that source IP and direct source IP match correctly.
TEST_P(ProxyProtoFilterChainMatchIntegrationTest, MatchDirectSourceAndSource) {
initialize();

IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("tcp_proxy"));
ASSERT_TRUE(tcp_client->write("PROXY TCP4 1.2.3.4 254.254.254.254 12345 1234\r\nhello", false));
tcp_client->waitForDisconnect();

send("PROXY TCP4 1.2.3.4 254.254.254.254 12345 1234\r\nhello");
EXPECT_THAT(waitForAccessLog(listener_access_log_name_),
testing::HasSubstr("directsource_localhost_and_source_1.2.3.0/24 -"));
}

// Test that a mismatched direct source prevents matching a filter chain with a matching source.
TEST_P(ProxyProtoFilterChainMatchIntegrationTest, MismatchDirectSourceButMatchSource) {
initialize();

IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("tcp_proxy"));
ASSERT_TRUE(tcp_client->write("PROXY TCP4 5.5.5.5 254.254.254.254 12345 1234\r\nhello", false));
tcp_client->waitForDisconnect();

send("PROXY TCP4 5.5.5.5 254.254.254.254 12345 1234\r\nhello");
EXPECT_THAT(waitForAccessLog(listener_access_log_name_),
testing::HasSubstr(
absl::StrCat("- ", StreamInfo::ResponseCodeDetails::get().FilterChainNotFound)));
Expand All @@ -346,12 +349,7 @@ TEST_P(ProxyProtoFilterChainMatchIntegrationTest, MismatchDirectSourceButMatchSo
// Test that a more specific direct source match prevents matching a filter chain with a less
// specific direct source match but matching source.
TEST_P(ProxyProtoFilterChainMatchIntegrationTest, MoreSpecificDirectSource) {
initialize();

IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("tcp_proxy"));
ASSERT_TRUE(tcp_client->write("PROXY TCP4 6.6.6.6 254.254.254.254 12345 1234\r\nhello", false));
tcp_client->waitForDisconnect();

send("PROXY TCP4 6.6.6.6 254.254.254.254 12345 1234\r\nhello");
EXPECT_THAT(waitForAccessLog(listener_access_log_name_),
testing::HasSubstr(
absl::StrCat("- ", StreamInfo::ResponseCodeDetails::get().FilterChainNotFound)));
Expand Down
2 changes: 2 additions & 0 deletions test/integration/proxy_proto_integration_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class ProxyProtoTcpIntegrationTest : public testing::TestWithParam<Network::Addr
class ProxyProtoFilterChainMatchIntegrationTest : public ProxyProtoTcpIntegrationTest {
public:
ProxyProtoFilterChainMatchIntegrationTest();

void send(const std::string& data);
};

} // namespace Envoy

0 comments on commit d5b508b

Please sign in to comment.