Skip to content

Commit

Permalink
mysql_filter: fix integration test flakes (#6272)
Browse files Browse the repository at this point in the history
This fixes flakes in the MySQL integration tests by introducing an exact
match for server responses.

Signed-off-by: Venil Noronha <veniln@vmware.com>
  • Loading branch information
venilnoronha authored and mattklein123 committed Mar 13, 2019
1 parent c7bd9b0 commit 21130ad
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 33 deletions.
40 changes: 18 additions & 22 deletions test/extensions/filters/network/mysql_proxy/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,24 @@ envoy_extension_cc_test(
],
)

# See https://github.com/envoyproxy/envoy/issues/6162.
#
# TODO(venilnoronha, #6162): uncomment this once this works on all platforms.
#
# envoy_extension_cc_test(
# name = "mysql_integration_test",
# srcs = [
# "mysql_integration_test.cc",
# ],
# data = [
# "mysql_test_config.yaml",
# ],
# extension_name = "envoy.filters.network.mysql_proxy",
# deps = [
# ":mysql_test_utils_lib",
# "//source/common/tcp_proxy",
# "//source/extensions/filters/network/mysql_proxy:config",
# "//source/extensions/filters/network/mysql_proxy:proxy_lib",
# "//source/extensions/filters/network/tcp_proxy:config",
# "//test/integration:integration_lib",
# ],
# )
envoy_extension_cc_test(
name = "mysql_integration_test",
srcs = [
"mysql_integration_test.cc",
],
data = [
"mysql_test_config.yaml",
],
extension_name = "envoy.filters.network.mysql_proxy",
deps = [
":mysql_test_utils_lib",
"//source/common/tcp_proxy",
"//source/extensions/filters/network/mysql_proxy:config",
"//source/extensions/filters/network/mysql_proxy:proxy_lib",
"//source/extensions/filters/network/tcp_proxy:config",
"//test/integration:integration_lib",
],
)

envoy_extension_cc_test(
name = "mysql_command_tests",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ class MySQLIntegrationTest : public testing::TestWithParam<Network::Address::IpV
public MySQLTestUtils,
public BaseIntegrationTest {
std::string mysqlConfig() {
return TestEnvironment::readFileToStringForTest(TestEnvironment::runfilesPath(
"test/extensions/filters/network/mysql_proxy/mysql_test_config.yaml"));
return fmt::format(TestEnvironment::readFileToStringForTest(TestEnvironment::runfilesPath(
"test/extensions/filters/network/mysql_proxy/mysql_test_config.yaml")),
Network::Test::getLoopbackAddressString(GetParam()),
Network::Test::getLoopbackAddressString(GetParam()),
Network::Test::getAnyAddressString(GetParam()));
}

public:
Expand Down Expand Up @@ -74,7 +77,7 @@ TEST_P(MySQLIntegrationTest, MySQLStatsNewSessionTest) {
* - correct number of attempts
* - no failures
*/
TEST_P(MySQLIntegrationTest, MysqLoginTest) {
TEST_P(MySQLIntegrationTest, MySQLLoginTest) {
std::string str;
std::string rcvd_data;
std::string user = "user1";
Expand All @@ -86,7 +89,9 @@ TEST_P(MySQLIntegrationTest, MysqLoginTest) {
// greeting
std::string greeting = encodeServerGreeting(MYSQL_PROTOCOL_10);
ASSERT_TRUE(fake_upstream_connection->write(greeting));
tcp_client->waitForData(str);

str.append(greeting);
tcp_client->waitForData(str, true);

// Client username/password and capabilities
std::string login = encodeClientLogin(MYSQL_CLIENT_CAPAB_41VS320, user, CHALLENGE_SEQ_NUM);
Expand All @@ -97,7 +102,9 @@ TEST_P(MySQLIntegrationTest, MysqLoginTest) {
// Server response OK to username/password
std::string loginok = encodeClientLoginResp(MYSQL_RESP_OK);
ASSERT_TRUE(fake_upstream_connection->write(loginok));
tcp_client->waitForData(str);

str.append(loginok);
tcp_client->waitForData(str, true);

tcp_client->close();
ASSERT_TRUE(fake_upstream_connection->waitForDisconnect());
Expand All @@ -116,9 +123,9 @@ TEST_P(MySQLIntegrationTest, MysqLoginTest) {
TEST_P(MySQLIntegrationTest, MySQLUnitTestMultiClientsLoop) {
int idx;
std::string rcvd_data;
std::string str;

for (idx = 0; idx < CLIENT_NUM; idx++) {
std::string str;
std::string user("user");
user.append(std::to_string(idx));

Expand All @@ -129,7 +136,9 @@ TEST_P(MySQLIntegrationTest, MySQLUnitTestMultiClientsLoop) {
// greeting
std::string greeting = encodeServerGreeting(MYSQL_PROTOCOL_10);
ASSERT_TRUE(fake_upstream_connection->write(greeting));
tcp_client->waitForData(str);

str.append(greeting);
tcp_client->waitForData(str, true);

// Client username/password and capabilities
std::string login = encodeClientLogin(MYSQL_CLIENT_CAPAB_41VS320, user, CHALLENGE_SEQ_NUM);
Expand All @@ -140,7 +149,9 @@ TEST_P(MySQLIntegrationTest, MySQLUnitTestMultiClientsLoop) {
// Server response OK to username/password
std::string loginok = encodeClientLoginResp(MYSQL_RESP_OK);
ASSERT_TRUE(fake_upstream_connection->write(loginok));
tcp_client->waitForData(str);

str.append(loginok);
tcp_client->waitForData(str, true);

tcp_client->close();
ASSERT_TRUE(fake_upstream_connection->waitForDisconnect());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ admin:
access_log_path: /dev/null
address:
socket_address:
address: 127.0.0.1
address: "{}"
port_value: 0
static_resources:
clusters:
Expand All @@ -15,13 +15,13 @@ static_resources:
- endpoint:
address:
socket_address:
address: 127.0.0.1
address: "{}"
port_value: 0
listeners:
name: listener_0
address:
socket_address:
address: 0.0.0.0
address: "{}"
port_value: 0
filter_chains:
- filters:
Expand Down

0 comments on commit 21130ad

Please sign in to comment.