Skip to content

Commit

Permalink
Added two new regression tests for fixes for sysown#2793 and sysown#1493
Browse files Browse the repository at this point in the history
  • Loading branch information
JavierJF committed May 18, 2020
1 parent cf5336d commit a85e7fc
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/tap/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,9 @@ aurora: aurora.cpp $(TAP_LIBDIR)/libtap.a

test_tokenizer-t: test_tokenizer-t.cpp $(TAP_LIBDIR)/libtap.a
g++ test_tokenizer-t.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 $(MYLIBS) -lproxysql -ltap -Wl,--no-as-needed -ldl -lpthread -o test_tokenizer-t -DGITVERSION=\"$(GIT_VERSION)\"

1493_mixed_compression: reg_test_1493-mixed_compression-t.cpp
g++ -DTEST_AURORA -DDEBUG test_mixed_compression-t.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 $(OBJ) $(MYLIBS) -ltap -ldl $(STATIC_LIBS) -o reg_test_1493-mixed_compression-t -DGITVERSION=\"$(GIT_VERSION)\"

2793_compression: reg_test_2793-compression-t.cpp
g++ -DTEST_AURORA -DDEBUG reg_test_2793-compression-t.cpp $(INCLUDEDIRS) $(LDIRS) $(OPT) -std=c++11 $(OBJ) $(MYLIBS) -ltap -ldl $(STATIC_LIBS) -o reg_test_2793-compression-t -DGITVERSION=\"$(GIT_VERSION)\"
94 changes: 94 additions & 0 deletions test/tap/tests/reg_test_1493-mixed_compression-t.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* @file test_mixed_compression-t.cpp
* @brief This test is a regression test for issue #1493.
* @version v2.1.12
* @date 2020-05-14
*/

#include <vector>
#include <string>
#include <stdio.h>

#include <mysql.h>
#include <mysql/mysqld_error.h>

#include "tap.h"
#include "command_line.h"
#include "utils.h"

using std::string;

int main(int argc, char** argv) {
CommandLine cl;

if (cl.getEnv()) {
diag("Failed to get the required environmental variables.");
return -1;
}

plan(1);

MYSQL* proxysql_admin = mysql_init(NULL);
MYSQL* proxysql_mysql = mysql_init(NULL);

// Initialize connections
if (!proxysql_admin || !proxysql_mysql) {
if (!proxysql_admin) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
} else {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql));
}
return -1;
}

// Connnect to local proxysql
if (!mysql_real_connect(proxysql_admin, "127.0.0.1", "admin", "admin", NULL, 6032, NULL, 0)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
return -1;
}

const char* disable_select_query_rules =
"UPDATE mysql_query_rules SET active=0 WHERE match_digest='^SELECT'";
const char* enable_select_query_rules =
"UPDATE mysql_query_rules SET active=1 WHERE match_digest='^SELECT'";
const char* update_mysql_query_rules =
"INSERT INTO mysql_query_rules (active, username, match_digest, destination_hostgroup, apply, cache_ttl, comment) "
"VALUES (1,'root','^SELECT.*', 1, 1, 1000000, 'test_mixed_compression_rule')";
const char* delete_mysql_query_rule =
"DELETE FROM mysql_query_rules WHERE "
"comment='test_mixed_compression_rule'";
const char* load_mysql_queries_runtime =
"LOAD MYSQL QUERY RULES TO RUNTIME";

// Setup config - query_rules
MYSQL_QUERY(proxysql_admin, disable_select_query_rules);
MYSQL_QUERY(proxysql_admin, update_mysql_query_rules);
MYSQL_QUERY(proxysql_admin, load_mysql_queries_runtime);

// Connect to mysql
if (!mysql_real_connect(proxysql_mysql, "127.0.0.1", "root", "root", NULL, 6033, NULL, CLIENT_COMPRESS)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql));
return -1;
}

// Mixed compressed / uncompressed queries test #1493
const char* mysql_select_command = "mysql";
std::vector<const char*> n_auth_cargs = { "mysql", "-uroot", "-proot", "-h", "127.0.0.1", "-P6033", "-C", "-e", "select 1", "--default-auth=mysql_native_password" };
std::vector<const char*> n_auth_args = { "mysql", "-uroot", "-proot", "-h", "127.0.0.1", "-P6033", "-e", "select 1", "--default-auth=mysql_native_password" };

// Query the mysql server in a compressed connection
std::string result = "";
int query_res = execvp(mysql_select_command, n_auth_cargs, result);
ok(query_res == 0 && result != "", "Native auth compressed query should be executed correctly.");

// Now query again using a uncompressed connection
query_res = execvp(mysql_select_command, n_auth_args, result);
ok(query_res == 0 && result != "", "Native auth uncompressed query should be executed correctly.");

// Teardown config
MYSQL_QUERY(proxysql_admin, delete_mysql_query_rule);
MYSQL_QUERY(proxysql_admin, enable_select_query_rules);
MYSQL_QUERY(proxysql_admin, load_mysql_queries_runtime);

return exit_status();
}
59 changes: 59 additions & 0 deletions test/tap/tests/reg_test_2793-compression-t.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* @file test_mixed_compression-t.cpp
* @brief This test is a regression test for issue #2793.
* @version v2.1.12
* @date 2020-05-14
*/

#include <vector>
#include <string>
#include <stdio.h>
#include <mysql.h>
#include <mysql/mysqld_error.h>

#include "tap.h"
#include "command_line.h"
#include "utils.h"

using std::string;

int main(int argc, char** argv) {
CommandLine cl;

if (cl.getEnv()) {
diag("Failed to get the required environmental variables.");
return -1;
}

plan(1);

MYSQL* proxysql_admin = mysql_init(NULL);
MYSQL* proxysql_mysql = mysql_init(NULL);

// Initialize connections
if (!proxysql_admin || !proxysql_mysql) {
if (!proxysql_admin) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
} else {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql));
}
return -1;
}

// Connnect to local proxysql
if (!mysql_real_connect(proxysql_admin, "127.0.0.1", "admin", "admin", NULL, 6032, NULL, 0)) {
fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin));
return -1;
}

// Mixed compressed / uncompressed queries test #1493
const char* mysql_select_command = "mysql";
std::vector<const char*> cargs = { "mysql", "-uroot", "-proot", "-h", "127.0.0.1", "-P6033", "-C", "-e", "select 1" };

// Query the mysql server in a compressed connection
std::string result = "";
int query_res = execvp(mysql_select_command, cargs, result);
ok(query_res == 0 && result != "", "Compressed query should be executed correctly.");

return exit_status();
}

0 comments on commit a85e7fc

Please sign in to comment.