diff --git a/.gitignore b/.gitignore index adcc2774b8..48dd43a834 100644 --- a/.gitignore +++ b/.gitignore @@ -42,7 +42,11 @@ oldcode/tests/connect_speed #pidfile and errorlog *.pid *.log +*.keylog +*.log.* *.err +proxy-audit.* +proxy-event* #binary src/proxysql diff --git a/test/tap/tap/command_line.cpp b/test/tap/tap/command_line.cpp index 13d6827099..5864cc2518 100644 --- a/test/tap/tap/command_line.cpp +++ b/test/tap/tap/command_line.cpp @@ -9,6 +9,7 @@ #include "tap.h" #include "command_line.h" +#include "utils.h" #include "json.hpp" #include "dotenv.h" @@ -17,7 +18,12 @@ using nlohmann::json; using dotenv::env; -CommandLine::CommandLine() {} +CommandLine::CommandLine() { + if (getEnv()) { + diag("Failed to get the required environmental variables."); + exit(-1); + } +} CommandLine::~CommandLine() { if (host) @@ -125,12 +131,38 @@ int CommandLine::getEnv() { { // load environment char temp[PATH_MAX]; - ssize_t len = readlink("/proc/self/exe", temp, sizeof(temp)); - std::string exe_path = (len > 0) ? std::string(temp, len) : std::string(""); + ssize_t len = 0; +// ssize_t len = readlink("/proc/self/exe", temp, sizeof(temp)); + { + FILE* fp = fopen("/proc/self/cmdline", "r"); // Linux + if (!fp) + fp = fopen("/proc/curproc/cmdline", "r"); // FreeBSD, needs procfs mounted + assert(fp); // MacOS ? + len = strlen(fgets(temp, PATH_MAX, fp)); + assert(len); + fclose(fp); + } + std::string cmd_line = std::string(temp, len); + std::string cmd_path = cmd_line.substr(0, cmd_line.find_last_of('/')); + if (cmd_line.find('/') == std::string::npos) + cmd_path = "."; + std::string cmd_name = cmd_line.substr(cmd_line.find_last_of('/')+1); + +// diag(">>> cmd_line = %s <<<", cmd_line.c_str()); +// diag(">>> cmd_path = %s <<<", cmd_path.c_str()); +// diag(">>> cmd_name = %s <<<", cmd_name.c_str()); + + len = strlen(realpath(cmd_path.c_str(), temp)); + std::string exe_path = (len > 0) ? std::string(temp, len) + "/" + cmd_name : std::string(""); std::string exe_name = exe_path.substr(exe_path.find_last_of('/') + 1); std::string dir_path = exe_path.substr(0, exe_path.find_last_of('/')); std::string dir_name = dir_path.substr(dir_path.find_last_of('/') + 1); +// diag(">>> exe_path = %s <<<", exe_path.c_str()); +// diag(">>> exe_name = %s <<<", exe_name.c_str()); +// diag(">>> dir_path = %s <<<", dir_path.c_str()); +// diag(">>> dir_name = %s <<<", dir_name.c_str()); + env.load_dotenv((dir_path + "/.env").c_str(), true); bool loaded1 = env.loaded; @@ -140,28 +172,46 @@ int CommandLine::getEnv() { env.load_dotenv((exe_path + ".env").c_str(), true); bool loaded3 = env.loaded; - bool quiet = (bool) getenv("TAP_QUIET_ENVLOAD"); - if (loaded1 && ! quiet) + bool verbose = get_env_bool("TAP_VERBOSE_ENVLOAD", 0); + if (loaded1 && verbose) { diag("loaded: %s", (dir_path + "/.env").c_str()); - if (loaded2 && ! quiet) + FILE* fp = fopen((dir_path + "/.env").c_str(), "r"); + while (fgets(temp, PATH_MAX, fp)) + printf("# %s", temp); + fclose(fp); + } + if (loaded2 && verbose) { diag("loaded: %s", (dir_path + "/" + dir_name + ".env").c_str()); - if (loaded3 && ! quiet) + FILE* fp = fopen((dir_path + "/" + dir_name + ".env").c_str(), "r"); + while (fgets(temp, PATH_MAX, fp)) + printf("# %s", temp); + fclose(fp); + } + if (loaded3 && verbose) { diag("loaded: %s", (exe_path + ".env").c_str()); + FILE* fp = fopen((exe_path + ".env").c_str(), "r"); + while (fgets(temp, PATH_MAX, fp)) + printf("# %s", temp); + fclose(fp); + } } - int env_port = 0; + int env_int = 0; { // unprivileged test connection value = getenv("TAP_HOST"); if (value) replace_str_field(&this->host, value); - value = getenv("TAP_PORT"); - if (value) { - env_port = strtol(value, NULL, 10); - if (env_port > 0 && env_port < 65536) - port = env_port; - } +// value = getenv("TAP_PORT"); +// if (value) { +// env_int = strtol(value, NULL, 10); +// if (env_int > 0 && env_int < 65536) +// port = env_int; +// } + env_int = get_env_int("TAP_PORT", 0); + if (env_int > 0 && env_int < 65536) + port = env_int; value = getenv("TAP_USERNAME"); if (value) @@ -178,12 +228,15 @@ int CommandLine::getEnv() { if (value) replace_str_field(&this->root_host, value); - value = getenv("TAP_ROOTPORT"); - if (value) { - env_port = strtol(value, NULL, 10); - if (env_port > 0 && env_port < 65536) - root_port = env_port; - } +// value = getenv("TAP_ROOTPORT"); +// if (value) { +// env_int = strtol(value, NULL, 10); +// if (env_int > 0 && env_int < 65536) +// root_port = env_int; +// } + env_int = get_env_int("TAP_ROOTPORT", 0); + if (env_int > 0 && env_int < 65536) + root_port = env_int; value = getenv("TAP_ROOTUSERNAME"); if (value) @@ -200,12 +253,15 @@ int CommandLine::getEnv() { if (value) replace_str_field(&this->admin_host, value); - value = getenv("TAP_ADMINPORT"); - if (value) { - env_port = strtol(value, NULL, 10); - if (env_port > 0 && env_port < 65536) - admin_port = env_port; - } +// value = getenv("TAP_ADMINPORT"); +// if (value) { +// env_int = strtol(value, NULL, 10); +// if (env_int > 0 && env_int < 65536) +// admin_port = env_int; +// } + env_int = get_env_int("TAP_ADMINPORT", 0); + if (env_int > 0 && env_int < 65536) + admin_port = env_int; value = getenv("TAP_ADMINUSERNAME"); if (value) @@ -222,12 +278,15 @@ int CommandLine::getEnv() { if (value) replace_str_field(&this->mysql_host, value); - value = getenv("TAP_MYSQLPORT"); - if (value) { - env_port = strtol(value, NULL, 10); - if (env_port > 0 && env_port < 65536) - mysql_port = env_port; - } +// value = getenv("TAP_MYSQLPORT"); +// if (value) { +// env_int = strtol(value, NULL, 10); +// if (env_int > 0 && env_int < 65536) +// mysql_port = env_int; +// } + env_int = get_env_int("TAP_MYSQLPORT", 0); + if (env_int > 0 && env_int < 65536) + mysql_port = env_int; value = getenv("TAP_MYSQLUSERNAME"); if (value) @@ -238,29 +297,45 @@ int CommandLine::getEnv() { replace_str_field(&this->mysql_password, value); } - - value = getenv("TAP_WORKDIR"); - if (value) - replace_str_field(&this->workdir, value); - - value = getenv("TAP_CLIENT_FLAGS"); - if (value) { - char* end = NULL; - uint64_t env_c_flags = strtoul(value, &end, 10); - - const char* errmsg { NULL }; - - if (env_c_flags == 0 && value == end) { - errmsg = "Invalid string to parse"; - } else if (env_c_flags == ULONG_MAX && errno == ERANGE) { - errmsg = strerror(errno); - } - - if (errmsg) { - fprintf(stderr, "Failed to parse env variable 'CLIENT_FLAGS' with error: '%s'\n", strerror(errno)); - return -1; - } else { - this->client_flags = env_c_flags; + { + // various + value = getenv("TAP_WORKDIR"); + if (value) + replace_str_field(&this->workdir, value); + +// value = getenv("TAP_USE_SSL"); +// if (value) { +// env_int = strtol(value, NULL, 0); +// use_ssl = (bool) env_int; +// } + use_ssl = get_env_bool("TAP_USE_SSL", 0); + +// value = getenv("TAP_COMPRESSION"); +// if (value) { +// env_int = strtol(value, NULL, 0); +// compression = (bool) env_int; +// } + compression = get_env_bool("TAP_COMPRESSION", 0); + + value = getenv("TAP_CLIENT_FLAGS"); + if (value) { + char* end = NULL; + uint64_t env_c_flags = strtoul(value, &end, 10); + + const char* errmsg { NULL }; + + if (env_c_flags == 0 && value == end) { + errmsg = "Invalid string to parse"; + } else if (env_c_flags == ULONG_MAX && errno == ERANGE) { + errmsg = strerror(errno); + } + + if (errmsg) { + fprintf(stderr, "Failed to parse env variable 'CLIENT_FLAGS' with error: '%s'\n", strerror(errno)); + return -1; + } else { + this->client_flags = env_c_flags; + } } } diff --git a/test/tap/tap/command_line.h b/test/tap/tap/command_line.h index b60b28cc30..fe2a454952 100644 --- a/test/tap/tap/command_line.h +++ b/test/tap/tap/command_line.h @@ -38,8 +38,10 @@ class CommandLine { char* mysql_username = strdup("root"); char* mysql_password = strdup("root"); + // various char* workdir = strdup("./"); - + bool use_ssl = 0; + bool compression = 0; uint64_t client_flags = 0; int getEnv(); diff --git a/test/tap/tap/utils.cpp b/test/tap/tap/utils.cpp index e025ee9a1d..279c166bc1 100644 --- a/test/tap/tap/utils.cpp +++ b/test/tap/tap/utils.cpp @@ -844,7 +844,9 @@ string tap_curtime() { return s; } -int get_proxysql_cpu_usage(const CommandLine& cl, uint32_t intv, double& cpu_usage) { +int get_proxysql_cpu_usage(uint32_t intv, double& cpu_usage) { + // cl must be a TAP test global + extern CommandLine cl; // check if proxysql process is consuming higher cpu than it should MYSQL* proxysql_admin = mysql_init(NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { diff --git a/test/tap/tap/utils.h b/test/tap/tap/utils.h index 5206c6016a..26f4d9ffb0 100644 --- a/test/tap/tap/utils.h +++ b/test/tap/tap/utils.h @@ -277,7 +277,7 @@ std::string tap_curtime(); * 'ms' in the specified interval. * @return 0 if success, -1 in case of error. */ -int get_proxysql_cpu_usage(const CommandLine& cl, uint32_t intv, double& cpu_usage); +int get_proxysql_cpu_usage(uint32_t intv, double& cpu_usage); /** * @brief Helper struct holding connection options for helper functions creating MySQL connections. diff --git a/test/tap/tests/.env b/test/tap/tests/.env index 3e4e264904..3d2f2fb8d4 100644 --- a/test/tap/tests/.env +++ b/test/tap/tests/.env @@ -1,7 +1,5 @@ TAP_ENV_VAR1=.env -# suppress env load messages -TAP_QUIET_ENVLOAD=1 -# override the default for this PR -TAP_USERNAME=testuser -TAP_PASSWORD=testuser +# enable env load messages +# may break some tests parsing helpers output +#TAP_VERBOSE_ENVLOAD=1 diff --git a/test/tap/tests/admin-listen_on_unix-t.cpp b/test/tap/tests/admin-listen_on_unix-t.cpp index 94c6d0f2dd..324d2614d3 100644 --- a/test/tap/tests/admin-listen_on_unix-t.cpp +++ b/test/tap/tests/admin-listen_on_unix-t.cpp @@ -14,6 +14,8 @@ using std::string; +CommandLine cl; + std::string get_admin_mysql_ifaces(MYSQL *admin) { std::string ret = ""; const char * query = (const char *)"SELECT variable_value FROM runtime_global_variables WHERE variable_name='admin-mysql_ifaces';"; @@ -41,21 +43,24 @@ std::string get_admin_mysql_ifaces(MYSQL *admin) { int main(int argc, char** argv) { - CommandLine cl; - - plan(13); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } + plan(2+2 + 13); MYSQL* proxysql_admin = mysql_init(NULL); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } + { std::string current = get_admin_mysql_ifaces(proxysql_admin); char * expected = (char *)"0.0.0.0:6032;0.0.0.0:6031;/tmp/proxysql_admin.sock"; @@ -77,11 +82,22 @@ int main(int argc, char** argv) { { diag("Connecting on Unix Socket"); + MYSQL* proxysql_admin2 = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin2, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin2, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin2, NULL, cl.admin_username, cl.admin_password, NULL, 0, "/tmp/proxysql_admin.sock", 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin2)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin2); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin2->net.compress, "Compression: (%d)", proxysql_admin2->net.compress); } + std::string current = get_admin_mysql_ifaces(proxysql_admin2); char * expected = (char *)"0.0.0.0:6032;/tmp/proxysql_admin.sock"; ok(strcmp(current.c_str(),expected)==0, "Line: %d , Current admin-mysql_ifaces = %s . Expected = %s", __LINE__, current.c_str(), expected); @@ -103,7 +119,14 @@ int main(int argc, char** argv) { { diag("Connecting on Unix Socket. It should fail"); MYSQL* proxysql_admin2 = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin2, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin2, MYSQL_OPT_COMPRESS, NULL); MYSQL * ret = mysql_real_connect(proxysql_admin2, NULL, cl.admin_username, cl.admin_password, NULL, 0, "/tmp/proxysql_admin.sock", 0); + if (ret) + mysql_close(proxysql_admin2); ok(ret == NULL, "Connection to Unix Socket should fail with error: %s", mysql_error(proxysql_admin2)); } diff --git a/test/tap/tests/admin_show_create_table-t.cpp b/test/tap/tests/admin_show_create_table-t.cpp index 5a995b1a6b..d699d5c33b 100644 --- a/test/tap/tests/admin_show_create_table-t.cpp +++ b/test/tap/tests/admin_show_create_table-t.cpp @@ -15,6 +15,8 @@ using std::string; +CommandLine cl; + /* this test: * enables mysql-have_ssl * retrieves all tables in the most important schemas @@ -22,24 +24,20 @@ using std::string; */ int main() { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - MYSQL* proxysql_admin = mysql_init(NULL); - // Initialize connections - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return -1; - } - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } MYSQL_QUERY(proxysql_admin, "SET mysql-have_ssl='true'"); @@ -65,23 +63,31 @@ int main() { mysql_free_result(proxy_res); } mysql_close(proxysql_admin); - plan(tables.size() + 1); + plan(2+2 + tables.size() + 1); ok(tables.size() > 40 , "Number of tables to check: %ld" , tables.size()); - proxysql_admin = mysql_init(NULL); // redefined locally - mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, CLIENT_SSL|CLIENT_COMPRESS)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(proxysql_admin->net.compress == 1, "Compression: (%d)", proxysql_admin->net.compress); } - const char * c = mysql_get_ssl_cipher(proxysql_admin); + for (std::vector::iterator it = tables.begin(); it != tables.end(); it++) { std::string q = "SHOW CREATE TABLE " + *it; MYSQL_QUERY(proxysql_admin, q.c_str()); MYSQL_RES* proxy_res = mysql_store_result(proxysql_admin); unsigned long rows = proxy_res->row_count; - ok(c != NULL && proxysql_admin->net.compress == 1 && rows==1, "cipher %s and compression (%d) used while reading %lu row(s) from %s", c, proxysql_admin->net.compress, rows, it->c_str()); + ok(rows == 1 , "Number of rows in %s = %lu", it->c_str(), rows); +// ok(proxysql_admin->net.compress == 1 && rows==1, "cipher %s and compression (%d) used while reading %lu row(s) from %s", c, proxysql_admin->net.compress, rows, it->c_str()); MYSQL_ROW row; while ((row = mysql_fetch_row(proxy_res))) { diag("%s", row[1]); diff --git a/test/tap/tests/admin_show_fields_from-t.cpp b/test/tap/tests/admin_show_fields_from-t.cpp index 8252bafd46..66888ff3b7 100644 --- a/test/tap/tests/admin_show_fields_from-t.cpp +++ b/test/tap/tests/admin_show_fields_from-t.cpp @@ -15,30 +15,28 @@ using std::string; +CommandLine cl; + /* this test: * enables mysql-have_ssl * retrieves all tables in the most important schemas */ int main() { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - MYSQL* proxysql_admin = mysql_init(NULL); - // Initialize connections - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return -1; - } - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } MYSQL_QUERY(proxysql_admin, "SET mysql-have_ssl='true'"); @@ -64,16 +62,26 @@ int main() { "show fields from %s", "ShOw fields FrOm %s", }; - plan(tables.size()*queries.size()); + plan(2 + tables.size() * (2 + queries.size())); for (std::vector::iterator it = tables.begin(); it != tables.end(); it++) { + MYSQL* proxysql_admin = mysql_init(NULL); // redefined locally - mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, CLIENT_SSL|CLIENT_COMPRESS)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(proxysql_admin->net.compress == 1, "Compression: (%d)", proxysql_admin->net.compress); } + char *query = (char *) malloc(strlen(queries[0]) + it->length() + 8); for (std::vector::iterator it2 = queries.begin(); it2 != queries.end(); it2++) { sprintf(query,*it2, it->c_str()); diff --git a/test/tap/tests/admin_show_table_status-t.cpp b/test/tap/tests/admin_show_table_status-t.cpp index 0727e023c2..f7612f2138 100644 --- a/test/tap/tests/admin_show_table_status-t.cpp +++ b/test/tap/tests/admin_show_table_status-t.cpp @@ -15,30 +15,28 @@ using std::string; +CommandLine cl; + /* this test: * enables mysql-have_ssl * retrieves all tables in the most important schemas */ int main() { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - MYSQL* proxysql_admin = mysql_init(NULL); - // Initialize connections - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return -1; - } - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } MYSQL_QUERY(proxysql_admin, "SET mysql-have_ssl='true'"); @@ -64,16 +62,27 @@ int main() { "SHOW table status like '%s'", "show TABLE status LIKE '%s'", }; - plan(tables.size()*queries.size()); + + plan(2 + tables.size() * (2 + queries.size())); for (std::vector::iterator it = tables.begin(); it != tables.end(); it++) { + MYSQL* proxysql_admin = mysql_init(NULL); // redefined locally - mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, CLIENT_SSL|CLIENT_COMPRESS)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(proxysql_admin->net.compress == 1, "Compression: (%d)", proxysql_admin->net.compress); } + char *query = (char *) malloc(strlen(queries[0]) + it->length() + 8); for (std::vector::iterator it2 = queries.begin(); it2 != queries.end(); it2++) { sprintf(query,*it2, it->c_str()); diff --git a/test/tap/tests/admin_various_commands-t.cpp b/test/tap/tests/admin_various_commands-t.cpp index cbc2ea3c9b..1178d49976 100644 --- a/test/tap/tests/admin_various_commands-t.cpp +++ b/test/tap/tests/admin_various_commands-t.cpp @@ -15,30 +15,28 @@ using std::string; +CommandLine cl; + /* this test: * enables mysql-have_ssl * retrieves all tables in the most important schemas */ int main() { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - MYSQL* proxysql_admin = mysql_init(NULL); - // Initialize connections - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return -1; - } - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } MYSQL_QUERY(proxysql_admin, "SET mysql-have_ssl='true'"); @@ -92,21 +90,24 @@ int main() { { , "" }, */ }; - plan(1+queries.size()); + plan(2 + 2 + queries.size()); proxysql_admin = mysql_init(NULL); - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return -1; - } - mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, CLIENT_SSL|CLIENT_COMPRESS)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(proxysql_admin->net.compress == 1, "Compression: (%d)", proxysql_admin->net.compress); } - const char * c = mysql_get_ssl_cipher(proxysql_admin); - ok(c != NULL && proxysql_admin->net.compress == 1, "cipher %s and compression (%d) used", c, proxysql_admin->net.compress); + for (std::vector>::iterator it2 = queries.begin(); it2 != queries.end(); it2++) { MYSQL_QUERY(proxysql_admin, it2->second); MYSQL_RES* proxy_res = mysql_store_result(proxysql_admin); diff --git a/test/tap/tests/admin_various_commands2-t.cpp b/test/tap/tests/admin_various_commands2-t.cpp index 94081b1e67..cbf5fa0e61 100644 --- a/test/tap/tests/admin_various_commands2-t.cpp +++ b/test/tap/tests/admin_various_commands2-t.cpp @@ -15,6 +15,8 @@ using std::string; +CommandLine cl; + /* this test: * enables mysql-have_ssl * execute various command @@ -108,24 +110,20 @@ int run_q(MYSQL *mysql, const char *q) { return 0; } int main() { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - MYSQL* proxysql_admin = mysql_init(NULL); - // Initialize connections - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return -1; - } - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } MYSQL_QUERY(proxysql_admin, "SET mysql-have_ssl='true'"); @@ -152,7 +150,7 @@ int main() { add_commands_set1(queries , "SQLITESERVER VARIABLES", false); add_commands_set1(queries , "CLICKHOUSE VARIABLES", false); add_commands_set1(queries , "CLICKHOUSE USERS", false); - unsigned int p = queries.size(); + unsigned int p = 2 + 3 * queries.size(); for (std::vector::iterator it2 = queries.begin(); it2 != queries.end(); it2++) { if ( (strncasecmp(it2->c_str(), "SELECT ", 7)==0) @@ -169,16 +167,22 @@ int main() { for (std::vector::iterator it2 = queries.begin(); it2 != queries.end(); it2++) { + MYSQL* proxysql_admin = mysql_init(NULL); // local scope - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return -1; - } - mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, CLIENT_SSL|CLIENT_COMPRESS)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(proxysql_admin->net.compress == 1, "Compression: (%d)", proxysql_admin->net.compress); } + int rc = run_q(proxysql_admin, it2->c_str()); ok(rc==0, "Query: %s" , it2->c_str()); if ( diff --git a/test/tap/tests/admin_various_commands3-t.cpp b/test/tap/tests/admin_various_commands3-t.cpp index db86720d81..282ecf98b8 100644 --- a/test/tap/tests/admin_various_commands3-t.cpp +++ b/test/tap/tests/admin_various_commands3-t.cpp @@ -15,6 +15,8 @@ using std::string; +CommandLine cl; + /* this test: * enables mysql-have_ssl * execute various command @@ -42,15 +44,8 @@ int run_q(MYSQL *mysql, const char *q) { return 0; } int main() { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } srandom(123); - for (auto it = vals.begin() ; it != vals.end() ; it++) { std::string q = "PROXYSQLTEST 1 " + std::to_string(*it); @@ -73,15 +68,18 @@ int main() { MYSQL* proxysql_admin = mysql_init(NULL); - // Initialize connections - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return -1; - } - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } MYSQL_QUERY(proxysql_admin, "SET mysql-have_ssl='true'"); @@ -90,7 +88,7 @@ int main() { - unsigned int p = queries.size(); + unsigned int p = 2 + 3 * queries.size(); for (std::vector::iterator it2 = queries.begin(); it2 != queries.end(); it2++) { if ( (strncasecmp(it2->c_str(), "SELECT ", 7)==0) @@ -104,16 +102,22 @@ int main() { for (std::vector::iterator it2 = queries.begin(); it2 != queries.end(); it2++) { + MYSQL* proxysql_admin = mysql_init(NULL); // local scope - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return -1; - } - mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, CLIENT_SSL|CLIENT_COMPRESS)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(proxysql_admin->net.compress == 1, "Compression: (%d)", proxysql_admin->net.compress); } + int rc = run_q(proxysql_admin, it2->c_str()); ok(rc==0, "Query: %s" , it2->c_str()); if ( diff --git a/test/tap/tests/basic-t.cpp b/test/tap/tests/basic-t.cpp index d8acfb1034..671c7036da 100644 --- a/test/tap/tests/basic-t.cpp +++ b/test/tap/tests/basic-t.cpp @@ -16,18 +16,21 @@ #include #include "tap.h" +#include "command_line.h" + +CommandLine cl; int main() { - plan(5); - ok(1 == 1, "testing basic functions"); - ok(2 == 2, " "); - ok1(3 == 3); - if (1 == 1) - skip(2, "Sensa fragoli"); - else { - ok(1 == 2, "Should not be run at all"); - ok(1, "This one neither"); - } - return exit_status(); + plan(5); + ok(1 == 1, "testing basic functions"); + ok(2 == 2, " "); + ok1(3 == 3); + if (1 == 1) { + skip(2, "Sensa fragoli"); + } else { + ok(1 == 2, "Should not be run at all"); + ok(1, "This one neither"); + } + return exit_status(); } diff --git a/test/tap/tests/charset_unsigned_int-t.cpp b/test/tap/tests/charset_unsigned_int-t.cpp index fafc557d48..d8eef4041e 100644 --- a/test/tap/tests/charset_unsigned_int-t.cpp +++ b/test/tap/tests/charset_unsigned_int-t.cpp @@ -10,13 +10,11 @@ #include "command_line.h" #include "utils.h" -int main(int argc, char** argv) { - CommandLine cl; +CommandLine cl; - if(cl.getEnv()) - return exit_status(); +int main(int argc, char** argv) { - plan(6); + plan(2+2+2+2+2 + 6); diag("Testing correct collation set with proxysql"); std::string var_collation_connection = "collation_connection"; @@ -25,23 +23,46 @@ int main(int argc, char** argv) { /* setup global variables * HANDLE_UNKNOWN_CHARSET__REPLACE_WITH_DEFAULT_VERBOSE */ - MYSQL* mysqlAdmin = mysql_init(NULL); - if (!mysqlAdmin) return exit_status(); - if (!mysql_real_connect(mysqlAdmin, cl.host, "admin", "admin", NULL, 6032, NULL, 0)) return exit_status(); - set_admin_global_variable(mysqlAdmin, "mysql-handle_unknown_charset", "1"); - set_admin_global_variable(mysqlAdmin, "mysql-default_charset", "utf8mb4"); - set_admin_global_variable(mysqlAdmin, "mysql-default_character_set_client", "utf8mb4"); - set_admin_global_variable(mysqlAdmin, "mysql-default_character_set_results", "utf8mb4"); - set_admin_global_variable(mysqlAdmin, "mysql-default_character_set_connection", "utf8mb4"); - set_admin_global_variable(mysqlAdmin, "mysql-default_character_set_database", "utf8mb4"); - set_admin_global_variable(mysqlAdmin, "mysql-default_collation_connection", "utf8mb4_general_ci"); - if (mysql_query(mysqlAdmin, "load mysql variables to runtime")) return exit_status(); - if (mysql_query(mysqlAdmin, "save mysql variables to disk")) return exit_status(); + MYSQL* proxysql_admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); + return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); + } + + set_admin_global_variable(proxysql_admin, "mysql-handle_unknown_charset", "1"); + set_admin_global_variable(proxysql_admin, "mysql-default_charset", "utf8mb4"); + set_admin_global_variable(proxysql_admin, "mysql-default_character_set_client", "utf8mb4"); + set_admin_global_variable(proxysql_admin, "mysql-default_character_set_results", "utf8mb4"); + set_admin_global_variable(proxysql_admin, "mysql-default_character_set_connection", "utf8mb4"); + set_admin_global_variable(proxysql_admin, "mysql-default_character_set_database", "utf8mb4"); + set_admin_global_variable(proxysql_admin, "mysql-default_collation_connection", "utf8mb4_general_ci"); + if (mysql_query(proxysql_admin, "load mysql variables to runtime")) return exit_status(); + if (mysql_query(proxysql_admin, "save mysql variables to disk")) return exit_status(); /* Check that set names can set collation > 255 */ MYSQL* mysql = mysql_init(NULL); - if (!mysql) return exit_status(); - if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) return exit_status(); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); + return -1; + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); + } if (mysql_query(mysql, "set names 'utf8'")) return exit_status(); show_variable(mysql, var_collation_connection, var_value); @@ -62,8 +83,19 @@ int main(int argc, char** argv) { /* Check that default collation can be configures through admin */ std::string var_name="mysql-default_charset"; MYSQL * mysql_a = mysql_init(NULL); - if (!mysql) return exit_status(); - if (!mysql_real_connect(mysql_a, cl.host, "admin", "admin", NULL, 6032, NULL, 0)) return exit_status(); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql_a, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql_a, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(mysql_a, cl.admin_host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql_a)); + return -1; + } else { + const char * c = mysql_get_ssl_cipher(mysql_a); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql_a->net.compress, "Compression: (%d)", mysql_a->net.compress); + } if (mysql_query(mysql_a, "update global_variables set variable_value='latin1' where variable_name='mysql-default_charset'")) return exit_status(); if (mysql_query(mysql_a, "load mysql variables to runtime")) return exit_status(); @@ -83,8 +115,19 @@ int main(int argc, char** argv) { MYSQL* mysql_b = mysql_init(NULL); - if (!mysql_b) return exit_status(); - if (!mysql_real_connect(mysql_b, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) return exit_status(); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql_b, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql_b, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(mysql_b, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql_b)); + return -1; + } else { + const char * c = mysql_get_ssl_cipher(mysql_b); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql_b->net.compress, "Compression: (%d)", mysql_b->net.compress); + } get_server_version(mysql_b, version); if (version.data()[0] == '5') { @@ -99,12 +142,23 @@ int main(int argc, char** argv) { /* check initial options */ - //set_admin_global_variable(mysqlAdmin, "mysql-default_collation_connection", "utf8mb4_general_ci"); - //if (mysql_query(mysqlAdmin, "load mysql variables to runtime")) return exit_status(); + //set_admin_global_variable(proxysql_admin, "mysql-default_collation_connection", "utf8mb4_general_ci"); + //if (mysql_query(proxysql_admin, "load mysql variables to runtime")) return exit_status(); MYSQL * mysql_c = mysql_init(NULL); - if (!mysql_c) return exit_status(); - if (mysql_options(mysql_c, MYSQL_SET_CHARSET_NAME, "utf8mb4")) return exit_status(); - if (!mysql_real_connect(mysql_c, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) return exit_status(); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + mysql_options(mysql_c, MYSQL_SET_CHARSET_NAME, "utf8mb4"); + if (cl.use_ssl) + mysql_ssl_set(mysql_c, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql_c, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(mysql_c, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql_c)); + return -1; + } else { + const char * c = mysql_get_ssl_cipher(mysql_c); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql_c->net.compress, "Compression: (%d)", mysql_c->net.compress); + } if (get_server_version(mysql_c, version)) return exit_status(); if (version.data()[0] == '5') { diff --git a/test/tap/tests/clickhouse_php_conn-t.php b/test/tap/tests/clickhouse_php_conn-t.php index bb5d9aec34..ac47ea66d2 100644 --- a/test/tap/tests/clickhouse_php_conn-t.php +++ b/test/tap/tests/clickhouse_php_conn-t.php @@ -37,7 +37,7 @@ echo ":: Creating ProxySQL Admin connection...".PHP_EOL; $proxy_admin = new mysqli("127.0.0.1", $admin_user, $admin_pass, "", $admin_port); if ($proxy_admin->connect_errno) { - die("PorxySQL connect failed: " . $proxy->connect_error); + die("ProxySQL connect failed: " . $proxy->connect_error); } echo ":: ProxySQL ProxySQL Admin connection completed".PHP_EOL; @@ -49,7 +49,7 @@ echo ":: Creating ProxySQL connection...".PHP_EOL; $proxy = new mysqli("127.0.0.1", $username, $password, "", $port); if ($proxy->connect_errno) { - die("PorxySQL connect failed: " . $proxy->connect_error); + die("ProxySQL connect failed: " . $proxy->connect_error); } echo ":: ProxySQL connection completed".PHP_EOL; diff --git a/test/tap/tests/envvars-t.cpp b/test/tap/tests/envvars-t.cpp index eb9f67d0ca..4fe304cf5d 100644 --- a/test/tap/tests/envvars-t.cpp +++ b/test/tap/tests/envvars-t.cpp @@ -4,8 +4,9 @@ #include "tap.h" #include "command_line.h" +CommandLine cl; + int main(int argc, char** argv) { - CommandLine cl; char* value = NULL; @@ -19,11 +20,6 @@ int main(int argc, char** argv) { // echo 'TAP_ENV_VAR2=tests.env' > tests.env // echo 'TAP_ENV_VAR3=envvars-t.env' > envvars-t.env - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - plan(3); value = getenv("TAP_ENV_VAR1"); diff --git a/test/tap/tests/firewall_commands1-t.cpp b/test/tap/tests/firewall_commands1-t.cpp index 6aa56cf61d..a5fd3d4a88 100644 --- a/test/tap/tests/firewall_commands1-t.cpp +++ b/test/tap/tests/firewall_commands1-t.cpp @@ -15,6 +15,8 @@ using std::string; +CommandLine cl; + /* this test: * enables mysql-have_ssl * execute various command @@ -56,24 +58,20 @@ int run_q(MYSQL *mysql, const char *q) { return 0; } int main() { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - MYSQL* proxysql_admin = mysql_init(NULL); - // Initialize connections - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return -1; - } - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } MYSQL_QUERY(proxysql_admin, "SET mysql-have_ssl='true'"); @@ -82,19 +80,25 @@ int main() { - plan(queries.size()); + plan(2 + 3 * queries.size()); for (std::vector::iterator it2 = queries.begin(); it2 != queries.end(); it2++) { + MYSQL* proxysql_admin = mysql_init(NULL); // local scope . We intentionally create new connections - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return -1; - } - mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, CLIENT_SSL|CLIENT_COMPRESS)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(proxysql_admin->net.compress == 1, "Compression: (%d)", proxysql_admin->net.compress); } + int rc = run_q(proxysql_admin, it2->c_str()); ok(rc==0, "Query: %s" , it2->c_str()); if (strncasecmp(it2->c_str(), "SELECT", 6)==0) { diff --git a/test/tap/tests/kill_connection-t.cpp b/test/tap/tests/kill_connection-t.cpp index 5f964a959d..b52472289a 100644 --- a/test/tap/tests/kill_connection-t.cpp +++ b/test/tap/tests/kill_connection-t.cpp @@ -9,6 +9,7 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; /* This test verifies a variety of things: @@ -28,34 +29,37 @@ int run_q(MYSQL *mysql, const char *q) { } int main(int argc, char** argv) { - CommandLine cl; - int np = NUM_CONNS ; // for last insert id + int np = 0; + np += 2 * NUM_CONNS; // connections + np += NUM_CONNS ; // for last insert id np += NUM_CONNS -1 ; // to compare all last insert id np += NUM_CONNS ; // to get connection id np += NUM_CONNS -1 ; // failed query on killed connection plan(np); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - MYSQL * conns[NUM_CONNS]; unsigned long long last_id[NUM_CONNS]; unsigned long mythreadid[NUM_CONNS]; + for (int i = 0; i < NUM_CONNS ; i++) { - MYSQL * mysql = mysql_init(NULL); - if (!mysql) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); - return exit_status(); - } + MYSQL * mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } + conns[i] = mysql; } diff --git a/test/tap/tests/kill_connection2-t.cpp b/test/tap/tests/kill_connection2-t.cpp index 947c9d9cf5..27e1e8c3fc 100644 --- a/test/tap/tests/kill_connection2-t.cpp +++ b/test/tap/tests/kill_connection2-t.cpp @@ -9,6 +9,7 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; /* This test verifies that client connections are dropped because of: @@ -26,18 +27,24 @@ int run_q(MYSQL *mysql, const char *q) { MYSQL * conns[NUM_CONNS]; unsigned long mythreadid[NUM_CONNS]; -int create_connections(CommandLine& cl) { +int create_connections() { for (int i = 0; i < NUM_CONNS ; i++) { - MYSQL * mysql = mysql_init(NULL); - if (!mysql) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); - return exit_status(); - } + MYSQL * mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } + conns[i] = mysql; } return 0; @@ -62,11 +69,12 @@ int find_tids() { } int main(int argc, char** argv) { - CommandLine cl; - int np = 0; + int np = 2; + np += 2 * NUM_CONNS ; // connection np += NUM_CONNS ; // to get connection id np += NUM_CONNS ; // failed query on killed connection due to timeout + np += 2 * NUM_CONNS ; // connection np += NUM_CONNS ; // to get connection id np += NUM_CONNS ; // to run BEGIN np += NUM_CONNS ; // to run first DO 1 @@ -74,22 +82,20 @@ int main(int argc, char** argv) { plan(np); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - MYSQL* proxysql_admin = mysql_init(NULL); - // Initialize connections - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return -1; - } - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } MYSQL_QUERY(proxysql_admin, "SET mysql-have_ssl='true'"); @@ -99,7 +105,7 @@ int main(int argc, char** argv) { MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME"); int rc = 0; - rc = create_connections(cl); + rc = create_connections(); if (rc != 0) { return exit_status(); } @@ -141,7 +147,7 @@ int main(int argc, char** argv) { MYSQL_QUERY(proxysql_admin, "SET mysql-max_transaction_time=17000"); // to force a close on transaction MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME"); - rc = create_connections(cl); + rc = create_connections(); if (rc != 0) { return exit_status(); } diff --git a/test/tap/tests/kill_connection3-t.cpp b/test/tap/tests/kill_connection3-t.cpp index ef28ac6cb6..b62e0d471a 100644 --- a/test/tap/tests/kill_connection3-t.cpp +++ b/test/tap/tests/kill_connection3-t.cpp @@ -9,6 +9,7 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; /* This test verifies that client connections are dropped because of: @@ -26,18 +27,24 @@ int run_q(MYSQL *mysql, const char *q) { MYSQL * conns[NUM_CONNS]; unsigned long mythreadid[NUM_CONNS]; -int create_connections(CommandLine& cl) { +int create_connections() { for (int i = 0; i < NUM_CONNS ; i++) { - MYSQL * mysql = mysql_init(NULL); - if (!mysql) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); - return exit_status(); - } + MYSQL * mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } + conns[i] = mysql; } return 0; @@ -62,13 +69,14 @@ int find_tids() { } int main(int argc, char** argv) { - CommandLine cl; - int np = 0; + int np = 2; // conection admin np += 2; // for processlist + np += 2 * NUM_CONNS ; // connection np += NUM_CONNS ; // to get connection id np += 1; // for processlist np += NUM_CONNS ; // to kill connections + np += 2 * NUM_CONNS ; // connection np += NUM_CONNS ; // to run first DO 1 np += NUM_CONNS ; // to get connection id np += 1; // for processlist @@ -79,22 +87,20 @@ int main(int argc, char** argv) { plan(np); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - MYSQL* proxysql_admin = mysql_init(NULL); - // Initialize connections - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return -1; - } - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } MYSQL_QUERY(proxysql_admin, "SET mysql-have_ssl='true'"); @@ -104,7 +110,7 @@ int main(int argc, char** argv) { MYSQL_RES* proxy_res; int rc = 0; - rc = create_connections(cl); + rc = create_connections(); if (rc != 0) { return exit_status(); } @@ -159,7 +165,7 @@ int main(int argc, char** argv) { MYSQL_QUERY(proxysql_admin, "SET mysql-show_processlist_extended=2"); MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME"); - rc = create_connections(cl); + rc = create_connections(); if (rc != 0) { return exit_status(); } diff --git a/test/tap/tests/max_connections_ff-t.cpp b/test/tap/tests/max_connections_ff-t.cpp index f85a66f330..94ceefd170 100644 --- a/test/tap/tests/max_connections_ff-t.cpp +++ b/test/tap/tests/max_connections_ff-t.cpp @@ -41,18 +41,30 @@ using hrc = std::chrono::high_resolution_clock; using nlohmann::json; -int create_n_trxs(const CommandLine& cl, size_t n, vector& out_conns, int client_flags = 0) { +CommandLine cl; + +int create_n_trxs(size_t n, vector& out_conns, int client_flags = 0) { diag("Creating '%ld' transactions to test 'max_connections'", n); vector res_conns {}; for (size_t i = 0; i < n; i++) { + MYSQL* proxy_mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, client_flags)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_mysql)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_mysql->net.compress, "Compression: (%d)", proxy_mysql->net.compress); } - + mysql_query(proxy_mysql, "BEGIN"); res_conns.push_back(proxy_mysql); @@ -140,7 +152,7 @@ int conn_pool_hg_stats(MYSQL* proxy_admin, int hg_id, vector& out_stats) return err; } -int test_ff_sess_exceeds_max_conns(const CommandLine& cl, MYSQL* proxy_admin, long srv_conn_to, int max_conns) { +int test_ff_sess_exceeds_max_conns(MYSQL* proxy_admin, long srv_conn_to, int max_conns) { // We assume 'regular infra' and use hardcoded hg '0' and username 'sbtest1' for this test const int tg_hg = 0; const string username = "sbtest1"; @@ -209,7 +221,7 @@ int test_ff_sess_exceeds_max_conns(const CommandLine& cl, MYSQL* proxy_admin, lo } // See 'IMPORTANT-NOTE' on file @details. - my_err = create_n_trxs(cl, max_conns, trx_conns, CLIENT_IGNORE_SPACE); + my_err = create_n_trxs(max_conns, trx_conns, CLIENT_IGNORE_SPACE); if (my_err) { diag("Failed to create the required '%d' transactions", max_conns); res = EXIT_FAILURE; @@ -219,10 +231,19 @@ int test_ff_sess_exceeds_max_conns(const CommandLine& cl, MYSQL* proxy_admin, lo // Create a new ff connection and check that a query expires after 'connection' { MYSQL* proxy_ff = mysql_init(NULL); + diag("Connecting: username='%s' cl.use_ssl=%d cl.compression=%d", username.c_str(), cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_ff, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_ff, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_ff, cl.host, username.c_str(), username.c_str(), NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_ff)); res = EXIT_FAILURE; goto cleanup; + } else { + const char * c = mysql_get_ssl_cipher(proxy_ff); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_ff->net.compress, "Compression: (%d)", proxy_ff->net.compress); } std::chrono::nanoseconds duration; @@ -272,7 +293,7 @@ int test_ff_sess_exceeds_max_conns(const CommandLine& cl, MYSQL* proxy_admin, lo return EXIT_SUCCESS; } -int test_ff_only_one_free_conn(const CommandLine& cl, MYSQL* proxy_admin, int max_conns) { +int test_ff_only_one_free_conn(MYSQL* proxy_admin, int max_conns) { if (proxy_admin == NULL || max_conns == 0) { diag("'test_ff_only_one_free_conn' received invalid params."); return EINVAL; @@ -321,7 +342,7 @@ int test_ff_only_one_free_conn(const CommandLine& cl, MYSQL* proxy_admin, int ma } mysql_free_result(mysql_store_result(proxy_admin)); - my_err = create_n_trxs(cl, max_conns, trx_conns); + my_err = create_n_trxs(max_conns, trx_conns); if (my_err) { diag("Failed to create the required '%d' transactions", max_conns); res = EXIT_FAILURE; @@ -368,10 +389,19 @@ int test_ff_only_one_free_conn(const CommandLine& cl, MYSQL* proxy_admin, int ma diag("Creating new 'fast_forward' connection using user '%s'", username.c_str()); MYSQL* proxy_ff = mysql_init(NULL); + diag("Connecting: username='%s' cl.use_ssl=%d cl.compression=%d", username.c_str(), cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_ff, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_ff, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_ff, cl.host, username.c_str(), username.c_str(), NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_ff)); res = EXIT_FAILURE; goto cleanup; + } else { + const char * c = mysql_get_ssl_cipher(proxy_ff); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_ff->net.compress, "Compression: (%d)", proxy_ff->net.compress); } // 3.1 Issue a simple query into the new 'fast_forward' connection @@ -433,35 +463,37 @@ int test_ff_only_one_free_conn(const CommandLine& cl, MYSQL* proxy_admin, int ma } int main(int argc, char** argv) { - CommandLine cl; - - // 'test_ff_sess_exceeds_max_conns' performs '1' check, 'test_ff_only_one_free_conn' performs '2' checks - plan(1 * 2 + 2 * 2); - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } plan( - 1*2 + // 'test_ff_sess_exceeds_max_conns' - 2*2 // 'test_ff_only_one_free_conn' + 2 + // connection admin + 4+8+4+8 + // connection user + 1*2 + // 'test_ff_sess_exceeds_max_conns' + 2*2 // 'test_ff_only_one_free_conn' ); MYSQL* proxy_admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_admin->net.compress, "Compression: (%d)", proxy_admin->net.compress); } // 1. Test for: '4000' timeout, '1' max_connections - test_ff_sess_exceeds_max_conns(cl, proxy_admin, 8000, 1); + test_ff_sess_exceeds_max_conns(proxy_admin, 8000, 1); // 2. Test for: '2000' timeout, '3' max_connections - test_ff_sess_exceeds_max_conns(cl, proxy_admin, 2000, 3); + test_ff_sess_exceeds_max_conns(proxy_admin, 2000, 3); // 3. Test for only one 'FreeConn' that should be destroyed due to incoming 'fast_forward' conn - MaxConn: 1 - test_ff_only_one_free_conn(cl, proxy_admin, 1); + test_ff_only_one_free_conn(proxy_admin, 1); // 3. Test for only one 'FreeConn' that should be destroyed due to incoming 'fast_forward' conn - MaxConn: 3 - test_ff_only_one_free_conn(cl, proxy_admin, 3); + test_ff_only_one_free_conn(proxy_admin, 3); mysql_close(proxy_admin); diff --git a/test/tap/tests/multiple_prepared_statements-t.cpp b/test/tap/tests/multiple_prepared_statements-t.cpp index ea3bed6035..e3b58809c9 100644 --- a/test/tap/tests/multiple_prepared_statements-t.cpp +++ b/test/tap/tests/multiple_prepared_statements-t.cpp @@ -29,6 +29,8 @@ It stresses how proxysql managers prepared statements, specifically: #include "tap.h" //#include "utils.h" +CommandLine cl; + int g_seed = 0; inline int fastrand() { @@ -126,24 +128,30 @@ int execute_stmt(int idx) { } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - plan(6); + plan( + 1*2 + // connection admin + 6*2 + // connection user + 6 // tests + ); - MYSQL* proxysql_admin = mysql_init(NULL); memset(bind, 0, sizeof(bind)); diag("Creating connections"); for (int i=0; inet.compress, "Compression: (%d)", conns[i]->net.compress); } } @@ -152,9 +160,20 @@ int main(int argc, char** argv) { for (int i=0; inet.compress, "Compression: (%d)", proxysql_admin->net.compress); } diag("Preparing statements"); diff --git a/test/tap/tests/mysql-fast_forward-t.cpp b/test/tap/tests/mysql-fast_forward-t.cpp index 6fa29c4eb0..dcf89ca6a9 100644 --- a/test/tap/tests/mysql-fast_forward-t.cpp +++ b/test/tap/tests/mysql-fast_forward-t.cpp @@ -9,6 +9,7 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; /* This test verifies that client connections are dropped because of: @@ -27,18 +28,24 @@ int run_q(MYSQL *mysql, const char *q) { MYSQL * conns[NUM_CONNS]; unsigned long mythreadid[NUM_CONNS]; -int create_connections(CommandLine& cl) { +int create_connections() { for (int i = 0; i < NUM_CONNS ; i++) { - MYSQL * mysql = mysql_init(NULL); - if (!mysql) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); - return exit_status(); - } + MYSQL * mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } + conns[i] = mysql; mythreadid[i] = mysql_thread_id(conns[i]); } @@ -47,11 +54,13 @@ int create_connections(CommandLine& cl) { int main(int argc, char** argv) { - CommandLine cl; int np = 0; + np += 2; // admin create connection ssl? compress? np += 3; // for processlist + np += 2*NUM_CONNS ; // create user connections ssl? compress? np += NUM_CONNS ; // to kill connections + np += 2*NUM_CONNS ; // create user connection ssl? compress? np += NUM_CONNS ; // to run first DO 1 np += 1; // for processlist np += NUM_CONNS ; // to run BEGIN @@ -62,22 +71,20 @@ int main(int argc, char** argv) { plan(np); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - MYSQL* proxysql_admin = mysql_init(NULL); - // Initialize connections - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return -1; - } - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } MYSQL_QUERY(proxysql_admin, "SET mysql-have_ssl='true'"); @@ -89,7 +96,7 @@ int main(int argc, char** argv) { MYSQL_RES* proxy_res; int rc = 0; - rc = create_connections(cl); + rc = create_connections(); if (rc != 0) { return exit_status(); } @@ -142,7 +149,7 @@ int main(int argc, char** argv) { MYSQL_QUERY(proxysql_admin, "SET mysql-show_processlist_extended=2"); MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME"); - rc = create_connections(cl); + rc = create_connections(); if (rc != 0) { return exit_status(); } diff --git a/test/tap/tests/mysql-init_connect-1-t.cpp b/test/tap/tests/mysql-init_connect-1-t.cpp index 65dc2202b4..4ca58ab6a7 100644 --- a/test/tap/tests/mysql-init_connect-1-t.cpp +++ b/test/tap/tests/mysql-init_connect-1-t.cpp @@ -11,6 +11,8 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + /* This TAP test validate the use of mysql-init_connect. It uses 2 valid init_connect, and 2 invalid ones that trigger PMC-10003. @@ -24,32 +26,39 @@ inline unsigned long long monotonic_time() { } int main(int argc, char** argv) { - CommandLine cl; - - if(cl.getEnv()) - return exit_status(); - plan(8); + plan(2+2+2+2+2 + 8); MYSQL* mysqladmin = mysql_init(NULL); - if (!mysqladmin) - return exit_status(); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysqladmin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysqladmin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysqladmin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysqladmin)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysqladmin)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysqladmin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysqladmin->net.compress, "Compression: (%d)", mysqladmin->net.compress); } MYSQL* mysql = mysql_init(NULL); - if (!mysql) - return exit_status(); - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - fprintf(stderr, "Failed to connect to database: Error: %s\n", - mysql_error(mysql)); + fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } + diag("Setting mysql-init_connect to DO 1"); MYSQL_QUERY(mysqladmin, "UPDATE global_variables SET variable_value='DO 1' WHERE variable_name = 'mysql-init_connect'"); MYSQL_QUERY(mysqladmin, "load mysql variables to runtime"); @@ -91,13 +100,20 @@ int main(int argc, char** argv) { { // reconnect MYSQL* mysql = mysql_init(NULL); - if (!mysql) - return exit_status(); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - fprintf(stderr, "Failed to connect to database: Error: %s\n", - mysql_error(mysql)); + fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } + const char *q = "SELECT /* create_new_connection=1 */ 300"; diag("Running query: %s", q); unsigned long long begin = monotonic_time(); @@ -118,13 +134,20 @@ int main(int argc, char** argv) { { // reconnect MYSQL* mysql = mysql_init(NULL); - if (!mysql) - return exit_status(); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - fprintf(stderr, "Failed to connect to database: Error: %s\n", - mysql_error(mysql)); + fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } + const char *q = "SELECT /* create_new_connection=1 */ 400"; diag("Running query: %s", q); int rc=mysql_query(mysql,q); @@ -141,13 +164,20 @@ int main(int argc, char** argv) { { // reconnect MYSQL* mysql = mysql_init(NULL); - if (!mysql) - return exit_status(); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - fprintf(stderr, "Failed to connect to database: Error: %s\n", - mysql_error(mysql)); + fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } + const char *q = "SELECT /* create_new_connection=1 */ 500"; diag("Running query: %s", q); MYSQL_QUERY(mysql, q); diff --git a/test/tap/tests/mysql-init_connect-2-t.cpp b/test/tap/tests/mysql-init_connect-2-t.cpp index 705869c70c..2695173841 100644 --- a/test/tap/tests/mysql-init_connect-2-t.cpp +++ b/test/tap/tests/mysql-init_connect-2-t.cpp @@ -11,6 +11,8 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + /* This TAP test validate the use of mysql-init_connect. It uses 2 valid init_connect, and 2 invalid ones that trigger PMC-10003. @@ -28,32 +30,41 @@ inline unsigned long long monotonic_time() { } int main(int argc, char** argv) { - CommandLine cl; - - if(cl.getEnv()) - return exit_status(); - plan(8); + plan(2+2+2+2+2 + 8); MYSQL* mysqladmin = mysql_init(NULL); - if (!mysqladmin) - return exit_status(); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysqladmin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysqladmin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysqladmin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysqladmin)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysqladmin)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysqladmin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysqladmin->net.compress, "Compression: (%d)", mysqladmin->net.compress); } - MYSQL* mysql = mysql_init(NULL); - if (!mysql) - return exit_status(); + MYSQL* mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } + diag("Setting mysql_hostgroup_attributes.init_connect to DO 1"); MYSQL_QUERY(mysqladmin, "DELETE FROM mysql_hostgroup_attributes"); MYSQL_QUERY(mysqladmin, "INSERT INTO mysql_hostgroup_attributes(hostgroup_id, init_connect) VALUES (1,'DO 1')"); @@ -101,13 +112,21 @@ int main(int argc, char** argv) { { // reconnect MYSQL* mysql = mysql_init(NULL); - if (!mysql) - return exit_status(); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } + const char *q = "SELECT /* create_new_connection=1 */ 300"; diag("Running query: %s", q); unsigned long long begin = monotonic_time(); @@ -130,13 +149,21 @@ int main(int argc, char** argv) { { // reconnect MYSQL* mysql = mysql_init(NULL); - if (!mysql) - return exit_status(); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } + const char *q = "SELECT /* create_new_connection=1 */ 400"; diag("Running query: %s", q); int rc=mysql_query(mysql,q); @@ -155,13 +182,21 @@ int main(int argc, char** argv) { { // reconnect MYSQL* mysql = mysql_init(NULL); - if (!mysql) - return exit_status(); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } + const char *q = "SELECT /* create_new_connection=1 */ 500"; diag("Running query: %s", q); MYSQL_QUERY(mysql, q); diff --git a/test/tap/tests/mysql-last_insert_id-t.cpp b/test/tap/tests/mysql-last_insert_id-t.cpp index 1e8e9d18b1..962a08d87b 100644 --- a/test/tap/tests/mysql-last_insert_id-t.cpp +++ b/test/tap/tests/mysql-last_insert_id-t.cpp @@ -11,12 +11,7 @@ #include "command_line.h" #include "utils.h" -inline unsigned long long monotonic_time() { - struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000); -} - +CommandLine cl; std::string queries[4] = { "SELECT LAST_INSERT_ID() LIMIT 1", @@ -25,27 +20,31 @@ std::string queries[4] = { "SELECT @@IDENTITY" }; - +inline unsigned long long monotonic_time() { + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000); +} int main(int argc, char** argv) { - CommandLine cl; - if(cl.getEnv()) - return exit_status(); - - plan(8); + plan(2 + 8); MYSQL* mysql = mysql_init(NULL); - if (!mysql) - return exit_status(); - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - fprintf(stderr, "Failed to connect to database: Error: %s\n", - mysql_error(mysql)); + fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } - if (create_table_test_sbtest1(500,mysql)) { fprintf(stderr, "File %s, line %d, Error: create_table_test_sbtest1() failed\n", __FILE__, __LINE__); return exit_status(); diff --git a/test/tap/tests/mysql-mirror1-t.cpp b/test/tap/tests/mysql-mirror1-t.cpp index 54e63488f7..e669a785ee 100644 --- a/test/tap/tests/mysql-mirror1-t.cpp +++ b/test/tap/tests/mysql-mirror1-t.cpp @@ -9,6 +9,7 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; /* This app tests mirroring @@ -32,48 +33,51 @@ int run_q(MYSQL *mysql, const char *q) { MYSQL * conns[NUM_CONNS]; unsigned long mythreadid[NUM_CONNS]; -int create_connections(CommandLine& cl) { +int create_connections() { for (int i = 0; i < NUM_CONNS ; i++) { - MYSQL * mysql = mysql_init(NULL); - if (!mysql) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); - return exit_status(); - } + MYSQL * mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } + conns[i] = mysql; } return 0; } int main(int argc, char** argv) { - CommandLine cl; - int np = 0; + int np = 2; np += 6; - np += NUM_CONNS; // new admin connections + np += 4 * NUM_CONNS; // new user connections + np += 3 * NUM_CONNS; // new admin connections plan(np); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - - - MYSQL* proxysql_admin = mysql_init(NULL); - // Initialize connections - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return -1; - } - + MYSQL* proxysql_admin = mysql_init(NULL); // Initialize connections + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } MYSQL_QUERY(proxysql_admin, "SET mysql-have_ssl='true'"); @@ -95,7 +99,7 @@ int main(int argc, char** argv) { MYSQL_RES* proxy_res; int rc = 0; - rc = create_connections(cl); + rc = create_connections(); if (rc != 0) { return exit_status(); } @@ -152,7 +156,7 @@ int main(int argc, char** argv) { MYSQL * mysql = conns[i]; mysql_close(mysql); } - rc = create_connections(cl); + rc = create_connections(); if (rc != 0) { return exit_status(); } @@ -161,15 +165,20 @@ int main(int argc, char** argv) { for (int i = 0 ; i < NUM_CONNS ; i++) { MYSQL* proxysql_admin = mysql_init(NULL); // local scope - // Initialize connections - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return -1; - } + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; - } + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); + } + rc = run_q(proxysql_admin, "SELECT * FROM stats_mysql_processlist"); ok(rc == 0 , "SELECT FROM stats_mysql_processlist"); proxy_res = mysql_store_result(proxysql_admin); diff --git a/test/tap/tests/mysql-set_transaction-t.cpp b/test/tap/tests/mysql-set_transaction-t.cpp index 1948bafb40..36fd0266f3 100644 --- a/test/tap/tests/mysql-set_transaction-t.cpp +++ b/test/tap/tests/mysql-set_transaction-t.cpp @@ -11,6 +11,8 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + struct transaction_param { struct next_transaction { std::string set_transaction_val; @@ -117,21 +119,22 @@ int check_transaction_access_mode(MYSQL* mysql) { } int main(int argc, char** argv) { - CommandLine cl; - - if(cl.getEnv()) - return exit_status(); - plan(48); + plan(2 + 48); MYSQL* mysql = mysql_init(NULL); - if (!mysql) - return exit_status(); - -// if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { + diag("Connecting: cl.root_username='%s' cl.use_ssl=%d cl.compression=%d", cl.root_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.root_host, cl.root_username, cl.root_password, NULL, cl.root_port, NULL, 0)) { fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } if (create_table_test_sbtest1(0,mysql)) { diff --git a/test/tap/tests/mysql-sql_log_bin-error-t.cpp b/test/tap/tests/mysql-sql_log_bin-error-t.cpp index 8311372a6b..d5f3ff4cee 100644 --- a/test/tap/tests/mysql-sql_log_bin-error-t.cpp +++ b/test/tap/tests/mysql-sql_log_bin-error-t.cpp @@ -11,22 +11,25 @@ #include "command_line.h" #include "utils.h" -int main(int argc, char** argv) { - CommandLine cl; +CommandLine cl; - if(cl.getEnv()) - return exit_status(); +int main(int argc, char** argv) { - plan(1); + plan(2 + 1); MYSQL* mysql = mysql_init(NULL); - if (!mysql) - return exit_status(); - + diag("Connecting: username='%s' cl.use_ssl=%d cl.compression=%d", "sbtest1", cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, "sbtest1", "sbtest1", NULL, cl.port, NULL, 0)) { - fprintf(stderr, "Failed to connect to database: Error: %s\n", - mysql_error(mysql)); + fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } diag("Running 'SET sql_log_bin=0' for a not privileged user: sbtest1"); diff --git a/test/tap/tests/mysql-test_ssl_CA-t.cpp b/test/tap/tests/mysql-test_ssl_CA-t.cpp index b09d659e03..01307d7f1a 100644 --- a/test/tap/tests/mysql-test_ssl_CA-t.cpp +++ b/test/tap/tests/mysql-test_ssl_CA-t.cpp @@ -12,6 +12,8 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + /* This TAP test: - configures SSL on various hostgroups @@ -26,11 +28,6 @@ inline unsigned long long monotonic_time() { } int main(int argc, char** argv) { - CommandLine cl; - - if(cl.getEnv()) - return exit_status(); - char * p_infra_datadir = std::getenv("REGULAR_INFRA_DATADIR"); if (p_infra_datadir == NULL) { @@ -70,13 +67,18 @@ int main(int argc, char** argv) { } MYSQL* mysqladmin = mysql_init(NULL); - if (!mysqladmin) - return exit_status(); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysqladmin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysqladmin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysqladmin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysqladmin)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysqladmin)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysqladmin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysqladmin->net.compress, "Compression: (%d)", mysqladmin->net.compress); } MYSQL_RES *res; @@ -99,10 +101,10 @@ int main(int argc, char** argv) { } if (hgs.size() > 0 ) { - plan(hgs.size()*pemfiles.size()); + plan(2 + 3 * hgs.size()*pemfiles.size()); } else { // quick exit - plan(1); + plan(2 + 1); ok(0, "No hostgroups found"); return exit_status(); } @@ -130,15 +132,23 @@ int main(int argc, char** argv) { diag("Running shell command: %s", cmd.c_str()); system(cmd.c_str()); for (int i=0; inet.compress, "Compression: (%d)", mysql->net.compress); } + std::string q = "SELECT /* hostgroup=" + std::to_string(hgs[i]) + ";create_new_connection=1 */ 200"; diag("Running query: %s", q.c_str()); int rc=mysql_query(mysql,q.c_str()); diff --git a/test/tap/tests/mysql_hostgroup_attributes-servers_defaults-t.cpp b/test/tap/tests/mysql_hostgroup_attributes-servers_defaults-t.cpp index 51d5300f96..5e31251b18 100644 --- a/test/tap/tests/mysql_hostgroup_attributes-servers_defaults-t.cpp +++ b/test/tap/tests/mysql_hostgroup_attributes-servers_defaults-t.cpp @@ -28,6 +28,8 @@ using nlohmann::json; using std::string; using std::fstream; +CommandLine cl; + int update_and_check_servers_defaults(MYSQL* admin, const json& j_servers_defaults) { const string INSERT_QUERY { "INSERT INTO mysql_hostgroup_attributes (hostgroup_id, servers_defaults)" @@ -106,14 +108,8 @@ void check_matching_logline(fstream& f_log, string regex) { } int main(int, char**) { - plan(12); - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } + plan(2 + 12); // Open the error log and fetch the final position const string f_path { get_env("REGULAR_INFRA_DATADIR") + "/proxysql.log" }; @@ -126,10 +122,18 @@ int main(int, char**) { } MYSQL* admin = mysql_init(NULL); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == admin->net.compress, "Compression: (%d)", admin->net.compress); } // Cleanup diff --git a/test/tap/tests/mysql_stmt_send_long_data-t.cpp b/test/tap/tests/mysql_stmt_send_long_data-t.cpp index 92722c5bf8..9fee4a91d1 100644 --- a/test/tap/tests/mysql_stmt_send_long_data-t.cpp +++ b/test/tap/tests/mysql_stmt_send_long_data-t.cpp @@ -9,6 +9,8 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + const int NUM_EXECUTIONS = 10; std::string select_query = "SELECT /* hostgroup=0 */ * FROM test.sbtest1 WHERE id = ?"; @@ -28,29 +30,27 @@ int idx2 = 0; int k = 0; int main(int argc, char** argv) { - CommandLine cl; - int plans = 4 * 3; // 4 INSERT queries each of them triggers a SELECT and a data comparison - plans *= NUM_EXECUTIONS; + int plans = 2; // connection + plans += 4 * 3 * NUM_EXECUTIONS; // 4 INSERT queries each of them triggers a SELECT and a data comparison plans += 5; // prepares plans += (4 * NUM_EXECUTIONS / 5); //mysql_stmt_reset() plan(plans); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - MYSQL* mysql = mysql_init(NULL); - if (!mysql) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); - return exit_status(); - } - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } idx = 1000; diff --git a/test/tap/tests/mysql_stmt_send_long_data_large-t.cpp b/test/tap/tests/mysql_stmt_send_long_data_large-t.cpp index e0e504e5bf..9e8fc70d1f 100644 --- a/test/tap/tests/mysql_stmt_send_long_data_large-t.cpp +++ b/test/tap/tests/mysql_stmt_send_long_data_large-t.cpp @@ -9,6 +9,8 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + /* mysql_stmt_send_long_data_large-t.cpp is almost identical to mysql_stmt_send_long_data-t.cpp but it uses very large buffers. @@ -39,29 +41,27 @@ int idx2 = 0; int k = 0; int main(int argc, char** argv) { - CommandLine cl; - int plans = 2 * 3; // 4 INSERT queries each of them triggers a SELECT and a data comparison - plans *= NUM_EXECUTIONS; + int plans = 2; // connect + plans += 2 * 3 * NUM_EXECUTIONS; // 4 INSERT queries each of them triggers a SELECT and a data comparison plans += 3; // prepares plans += (2 * NUM_EXECUTIONS / 5); //mysql_stmt_reset() plan(plans); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - MYSQL* mysql = mysql_init(NULL); - if (!mysql) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); - return exit_status(); - } - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } idx = 1000; diff --git a/test/tap/tests/prepare_statement_err3024-t.cpp b/test/tap/tests/prepare_statement_err3024-t.cpp index 3938d4cf1e..ff0568db1d 100644 --- a/test/tap/tests/prepare_statement_err3024-t.cpp +++ b/test/tap/tests/prepare_statement_err3024-t.cpp @@ -18,6 +18,8 @@ #include "proxysql_utils.h" #include "utils.h" +CommandLine cl; + const int NUM_EXECUTIONS = 5; std::string select_query[3] = { @@ -125,30 +127,35 @@ int create_table_test_sbtest1(int num_rows, MYSQL *mysql) { using std::string; int main(int argc, char** argv) { - CommandLine cl; - - plan(3 + NUM_EXECUTIONS*3*2); // 3 prepare + 3 * execution * 2 (execute + store) - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } + plan(2 + 3 + NUM_EXECUTIONS*3*2); // 3 prepare + 3 * execution * 2 (execute + store) MYSQL* mysql = mysql_init(NULL); - if (!mysql) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); - return exit_status(); - } - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); #if defined(ASYNC_API) && !defined(LIBMYSQL_HELPER) + diag("mysql_options: MYSQL_OPT_NONBLOCK"); mysql_options(mysql, MYSQL_OPT_NONBLOCK, 0); #endif - + if (cl.use_ssl) { + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); +#ifdef LIBMYSQL_HELPER + } else { + enum mysql_ssl_mode ssl_mode = SSL_MODE_DISABLED; + mysql_options(mysql, MYSQL_OPT_SSL_MODE, &ssl_mode); +#endif + } + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } + if (create_table_test_sbtest1(1000,mysql)) { fprintf(stderr, "File %s, line %d, Error: create_table_test_sbtest1() failed\n", __FILE__, __LINE__); return exit_status(); diff --git a/test/tap/tests/reg_test_1493-mixed_compression-t.cpp b/test/tap/tests/reg_test_1493-mixed_compression-t.cpp index 473d3288cf..a87c62ec2b 100644 --- a/test/tap/tests/reg_test_1493-mixed_compression-t.cpp +++ b/test/tap/tests/reg_test_1493-mixed_compression-t.cpp @@ -17,13 +17,9 @@ using std::string; -int main(int argc, char** argv) { - CommandLine cl; +CommandLine cl; - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } +int main(int argc, char** argv) { plan(2); diff --git a/test/tap/tests/reg_test_1574-mariadb_read_stmt_execute_response-t.cpp b/test/tap/tests/reg_test_1574-mariadb_read_stmt_execute_response-t.cpp index 0a78523c7c..d68a22c1a1 100644 --- a/test/tap/tests/reg_test_1574-mariadb_read_stmt_execute_response-t.cpp +++ b/test/tap/tests/reg_test_1574-mariadb_read_stmt_execute_response-t.cpp @@ -28,16 +28,12 @@ using std::string; +CommandLine cl; + const int STRING_SIZE=32; const int NUM_TEST_TABLES = 50; int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } plan(50); diff --git a/test/tap/tests/reg_test_1574-stmt_metadata-t.cpp b/test/tap/tests/reg_test_1574-stmt_metadata-t.cpp index fb61d6a474..50916bdfe3 100644 --- a/test/tap/tests/reg_test_1574-stmt_metadata-t.cpp +++ b/test/tap/tests/reg_test_1574-stmt_metadata-t.cpp @@ -29,6 +29,8 @@ using std::string; +CommandLine cl; + const int STRING_SIZE=32; int g_seed = 0; @@ -52,12 +54,6 @@ void gen_random_str(char *s, const int len) { } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } plan(3); diff --git a/test/tap/tests/reg_test_2793-compression-t.cpp b/test/tap/tests/reg_test_2793-compression-t.cpp index 7256094746..0ce9e9f6ef 100644 --- a/test/tap/tests/reg_test_2793-compression-t.cpp +++ b/test/tap/tests/reg_test_2793-compression-t.cpp @@ -16,13 +16,9 @@ using std::string; -int main(int argc, char** argv) { - CommandLine cl; +CommandLine cl; - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } +int main(int argc, char** argv) { plan(1); diff --git a/test/tap/tests/reg_test_3184-set_wait_timeout-t.cpp b/test/tap/tests/reg_test_3184-set_wait_timeout-t.cpp index d3eddc8d40..dcc3185b97 100644 --- a/test/tap/tests/reg_test_3184-set_wait_timeout-t.cpp +++ b/test/tap/tests/reg_test_3184-set_wait_timeout-t.cpp @@ -23,6 +23,8 @@ using std::string; using namespace nlohmann; +CommandLine cl; + /** * @brief Valid variations of 'SET wait_timeout' supported * by ProxySQL to be ignored. @@ -58,12 +60,6 @@ std::vector valids_set_wait_timeout { }; int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } plan(2 * valids_set_wait_timeout.size()); diff --git a/test/tap/tests/reg_test_3223-restapi_return_codes-t.cpp b/test/tap/tests/reg_test_3223-restapi_return_codes-t.cpp index 6eac9c9d73..b34234fddd 100644 --- a/test/tap/tests/reg_test_3223-restapi_return_codes-t.cpp +++ b/test/tap/tests/reg_test_3223-restapi_return_codes-t.cpp @@ -31,6 +31,8 @@ using std::vector; using hrc = std::chrono::high_resolution_clock; using nlohmann::json; +CommandLine cl; + const string base_address { "http://localhost:6070/sync/" }; const vector honest_requests { @@ -119,12 +121,6 @@ int count_exp_tests(const vector& v1, const vector& const uint32_t PROXY_GRACE_PERIOD = 1000 + 3000; int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } plan(count_exp_tests(honest_requests, invalid_requests)); diff --git a/test/tap/tests/reg_test_3247-mycli_support-t.cpp b/test/tap/tests/reg_test_3247-mycli_support-t.cpp index 4116bd621d..d868f22563 100644 --- a/test/tap/tests/reg_test_3247-mycli_support-t.cpp +++ b/test/tap/tests/reg_test_3247-mycli_support-t.cpp @@ -17,6 +17,8 @@ using std::string; +CommandLine cl; + std::vector split(const std::string& s, char delimiter) { std::vector tokens; @@ -30,12 +32,6 @@ std::vector split(const std::string& s, char delimiter) } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } plan(2); diff --git a/test/tap/tests/reg_test_3273_ssl_con-t.cpp b/test/tap/tests/reg_test_3273_ssl_con-t.cpp index 1b0c8b55cb..276848597b 100644 --- a/test/tap/tests/reg_test_3273_ssl_con-t.cpp +++ b/test/tap/tests/reg_test_3273_ssl_con-t.cpp @@ -38,6 +38,8 @@ using std::string; using std::vector; +CommandLine cl; + /* Helper function to do the waiting for events on the socket. */ static int wait_for_mysql(MYSQL *mysql, int status) { struct pollfd pfd; @@ -77,12 +79,6 @@ const vector tc_rules { }; int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } // temporary disable the whole test plan(1); @@ -93,7 +89,7 @@ int main(int argc, char** argv) { diag("Checking ProxySQL idle CPU usage"); double idle_cpu = 0; - int ret_i_cpu = get_proxysql_cpu_usage(cl, REPORT_INTV_SEC, idle_cpu); + int ret_i_cpu = get_proxysql_cpu_usage(REPORT_INTV_SEC, idle_cpu); if (ret_i_cpu) { diag("Getting initial CPU usage failed with error - %d", ret_i_cpu); diag("Aborting further testing"); @@ -189,7 +185,7 @@ int main(int argc, char** argv) { } double final_cpu_usage = 0; - int ret_f_cpu = get_proxysql_cpu_usage(cl, REPORT_INTV_SEC, final_cpu_usage); + int ret_f_cpu = get_proxysql_cpu_usage(REPORT_INTV_SEC, final_cpu_usage); diag("Getting the final CPU usage returned - %d", ret_f_cpu); ok( diff --git a/test/tap/tests/reg_test_3317-lock_hostgroup_special_queries-t.cpp b/test/tap/tests/reg_test_3317-lock_hostgroup_special_queries-t.cpp index 5eadc264fb..71f90959d6 100644 --- a/test/tap/tests/reg_test_3317-lock_hostgroup_special_queries-t.cpp +++ b/test/tap/tests/reg_test_3317-lock_hostgroup_special_queries-t.cpp @@ -19,6 +19,8 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + /** * @brief Checks that 'SET NAMES' is being executed properly in the backend connection. * @param proxysql_mysql A MYSQL handle to an already stablished MySQL connection. @@ -212,12 +214,6 @@ std::vector>> special_queries }; int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } plan(special_queries_checks.size() * 2); int check_num = 0; diff --git a/test/tap/tests/reg_test_3327-process_query_set_status_flags-t.cpp b/test/tap/tests/reg_test_3327-process_query_set_status_flags-t.cpp index 98a0983dbc..6fe67ea709 100644 --- a/test/tap/tests/reg_test_3327-process_query_set_status_flags-t.cpp +++ b/test/tap/tests/reg_test_3327-process_query_set_status_flags-t.cpp @@ -19,6 +19,8 @@ using std::string; using namespace nlohmann; +CommandLine cl; + void parse_result_json_column(MYSQL_RES *result, json& j) { if(!result) return; MYSQL_ROW row; @@ -29,12 +31,6 @@ void parse_result_json_column(MYSQL_RES *result, json& j) { } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } MYSQL* proxysql_mysql = mysql_init(NULL); diff --git a/test/tap/tests/reg_test_3427-stmt_first_comment1-t.cpp b/test/tap/tests/reg_test_3427-stmt_first_comment1-t.cpp index a4eec522b3..eec7127e6c 100644 --- a/test/tap/tests/reg_test_3427-stmt_first_comment1-t.cpp +++ b/test/tap/tests/reg_test_3427-stmt_first_comment1-t.cpp @@ -38,6 +38,8 @@ #include "utils.h" #include "errno.h" +CommandLine cl; + /** * @brief String size of the columns created for the testing table. */ @@ -60,13 +62,6 @@ const uint32_t WRITER_HOSTGROUP_ID = 0; int main(int argc, char** argv) { int res = EXIT_SUCCESS; - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - plan(5*RESET_CONNECTION_QUERIES); bool param = false; diff --git a/test/tap/tests/reg_test_3434-text_stmt_mix-t.cpp b/test/tap/tests/reg_test_3434-text_stmt_mix-t.cpp index 6fc4bdac3d..a3b1b5abcc 100644 --- a/test/tap/tests/reg_test_3434-text_stmt_mix-t.cpp +++ b/test/tap/tests/reg_test_3434-text_stmt_mix-t.cpp @@ -26,6 +26,8 @@ using std::string; +CommandLine cl; + const int STRING_SIZE=32; int g_seed = 0; @@ -54,10 +56,7 @@ void gen_random_str(char *s, const int len) { s[len] = 0; } -int perform_text_select( - const CommandLine& cl, - const std::string& query -) { +int perform_text_select(const std::string& query) { MYSQL* proxysql_text = mysql_init(NULL); if (!proxysql_text) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_text)); @@ -76,11 +75,7 @@ int perform_text_select( return EXIT_SUCCESS; } -int perform_stmt_select( - const CommandLine& cl, - const std::string& query, - uint32_t num_query_params -) { +int perform_stmt_select(const std::string& query, uint32_t num_query_params) { int res = EXIT_SUCCESS; MYSQL* proxysql_mysql = mysql_init(NULL); @@ -250,12 +245,6 @@ uint32_t ITERATIONS = 10; uint32_t HOSTGROUP = 0; int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } plan(1); @@ -345,9 +334,9 @@ int main(int argc, char** argv) { text_query_1 = query_1.substr(0, pos); } - query_res = perform_stmt_select(cl, query_1, SELECT_PARAM_NUM); + query_res = perform_stmt_select(query_1, SELECT_PARAM_NUM); if (query_res != EXIT_SUCCESS) { break; } - query_res = perform_text_select(cl, text_query_1); + query_res = perform_text_select(text_query_1); if (query_res != EXIT_SUCCESS) { break; } std::string query_2 { @@ -361,7 +350,7 @@ int main(int argc, char** argv) { text_query_2 = query_1.substr(0, pos); } - query_res = perform_stmt_select(cl, query_2, SELECT_PARAM_NUM); + query_res = perform_stmt_select(query_2, SELECT_PARAM_NUM); if (query_res != EXIT_SUCCESS) { break; } } diff --git a/test/tap/tests/reg_test_3493-USE_with_comment-t.cpp b/test/tap/tests/reg_test_3493-USE_with_comment-t.cpp index 66f509296c..1c6d9dca15 100644 --- a/test/tap/tests/reg_test_3493-USE_with_comment-t.cpp +++ b/test/tap/tests/reg_test_3493-USE_with_comment-t.cpp @@ -33,6 +33,8 @@ using nlohmann::json; +CommandLine cl; + void parse_result_json_column(MYSQL_RES *result, json& j) { if(!result) return; MYSQL_ROW row; @@ -159,12 +161,6 @@ int test_use_queries(MYSQL* proxysql_mysql, bool enabled_digests) { } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } MYSQL* proxysql_mysql = mysql_init(NULL); @@ -186,15 +182,8 @@ int main(int argc, char** argv) { plan(db_query.size() * 2); - if ( - !mysql_real_connect( - proxysql_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0 - ) - ) { - fprintf( - stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, - mysql_error(proxysql_mysql) - ); + if (!mysql_real_connect( proxysql_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); return EXIT_FAILURE; } diff --git a/test/tap/tests/reg_test_3504-change_user-t.cpp b/test/tap/tests/reg_test_3504-change_user-t.cpp index 29b0bcb1fb..61846e3fbb 100644 --- a/test/tap/tests/reg_test_3504-change_user-t.cpp +++ b/test/tap/tests/reg_test_3504-change_user-t.cpp @@ -34,6 +34,8 @@ using nlohmann::json; using test_opts = std::tuple; +CommandLine cl; + const std::vector tests_defs { std::make_tuple("mysql_clear_password", false, false), std::make_tuple("mysql_native_password", false, false), @@ -145,21 +147,10 @@ void perform_helper_test( } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } MYSQL* proxysql_admin = mysql_init(NULL); - if ( - !mysql_real_connect( - proxysql_admin, "127.0.0.1", cl.admin_username, cl.admin_password, - "information_schema", cl.admin_port, NULL, 0 - ) - ) { + if (!mysql_real_connect(proxysql_admin, "127.0.0.1", cl.admin_username, cl.admin_password, "information_schema", cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return EXIT_FAILURE; } diff --git a/test/tap/tests/reg_test_3504-change_user_helper.cpp b/test/tap/tests/reg_test_3504-change_user_helper.cpp index ee6ba80dbb..88c5634fc6 100644 --- a/test/tap/tests/reg_test_3504-change_user_helper.cpp +++ b/test/tap/tests/reg_test_3504-change_user_helper.cpp @@ -38,12 +38,15 @@ #include "json.hpp" #include "tap.h" #include "utils.h" +#include "command_line.h" using nlohmann::json; using std::vector; using std::string; +CommandLine cl; + void parse_result_json_column(MYSQL_RES *result, json& j) { if(!result) return; MYSQL_ROW row; @@ -204,33 +207,18 @@ int main(int argc, char** argv) { mysql_options(&mysql, MYSQL_OPT_SSL_MODE, &ssl_mode); } - if ( - !mysql_real_connect( - &mysql, "127.0.0.1", user.c_str(), pass.c_str(), "information_schema", - port, NULL, 0 - ) - ) { - string_format( - "Failed to connect to database: Error: %s\n", err_msg, - mysql_error(&mysql) - ); + if (!mysql_real_connect(&mysql, "127.0.0.1", user.c_str(), pass.c_str(), "information_schema", port, NULL, 0)) { + string_format("Failed to connect to database: Error: %s\n", err_msg, mysql_error(&mysql)); output["err_msg"] = err_msg; res = EXIT_FAILURE; - goto exit; } #else if (SSL == true) { mysql_ssl_set(&mysql, NULL, NULL, NULL, NULL, NULL); - conn_res = mysql_real_connect( - &mysql, "127.0.0.1", user.c_str(), pass.c_str(), "information_schema", - port, NULL, CLIENT_SSL - ); + conn_res = mysql_real_connect(&mysql, "127.0.0.1", user.c_str(), pass.c_str(), "information_schema", port, NULL, CLIENT_SSL ); } else { - conn_res = mysql_real_connect( - &mysql, "127.0.0.1", user.c_str(), pass.c_str(), "information_schema", - port, NULL, 0 - ); + conn_res = mysql_real_connect(&mysql, "127.0.0.1", user.c_str(), pass.c_str(), "information_schema", port, NULL, 0 ); } if (!conn_res) { diff --git a/test/tap/tests/reg_test_3546-stmt_empty_params-t.cpp b/test/tap/tests/reg_test_3546-stmt_empty_params-t.cpp index 86a148cd4f..cfc83f59ea 100644 --- a/test/tap/tests/reg_test_3546-stmt_empty_params-t.cpp +++ b/test/tap/tests/reg_test_3546-stmt_empty_params-t.cpp @@ -29,6 +29,8 @@ #include "utils.h" #include "errno.h" +CommandLine cl; + /** * @brief String size of the columns created for the testing table. */ @@ -80,15 +82,8 @@ int prepare_stmt( int main(int argc, char** argv) { - CommandLine cl; - plan(ITERATIONS); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - MYSQL* proxysql_mysql = mysql_init(NULL); MYSQL* proxysql_admin = mysql_init(NULL); diff --git a/test/tap/tests/reg_test_3549-autocommit_tracking-t.cpp b/test/tap/tests/reg_test_3549-autocommit_tracking-t.cpp index 42980c22b5..8d6fe62f84 100644 --- a/test/tap/tests/reg_test_3549-autocommit_tracking-t.cpp +++ b/test/tap/tests/reg_test_3549-autocommit_tracking-t.cpp @@ -24,6 +24,8 @@ using nlohmann::json; using query_spec = std::tuple; +CommandLine cl; + void fetch_and_discard_results(MYSQL_RES* result, bool verbose=false) { MYSQL_ROW row = nullptr; unsigned int num_fields = 0; @@ -275,12 +277,6 @@ void execute_test_definition(MYSQL* proxysql, std::pair } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } plan(test_definitions.size()); diff --git a/test/tap/tests/reg_test_3585-stmt_metadata-t.cpp b/test/tap/tests/reg_test_3585-stmt_metadata-t.cpp index f40e959a39..d44ac5d378 100644 --- a/test/tap/tests/reg_test_3585-stmt_metadata-t.cpp +++ b/test/tap/tests/reg_test_3585-stmt_metadata-t.cpp @@ -14,6 +14,8 @@ using std::string; +CommandLine cl; + const int STRING_SIZE=32; int g_seed = 0; @@ -307,12 +309,6 @@ int insert_and_check(MYSQL_STMT *stmti, MYSQL_STMT *stmts, int id, char *name1, } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } int np = 4; // init + prepare np += 25*2; // number of INSERT+SELECT diff --git a/test/tap/tests/reg_test_3591-restapi_num_fds-t.cpp b/test/tap/tests/reg_test_3591-restapi_num_fds-t.cpp index 13bb29142e..55d84ba092 100644 --- a/test/tap/tests/reg_test_3591-restapi_num_fds-t.cpp +++ b/test/tap/tests/reg_test_3591-restapi_num_fds-t.cpp @@ -29,15 +29,12 @@ using nlohmann::json; using std::string; +CommandLine cl; + const int NUM_CONNECTIONS = 2047; int main(int argc, char** argv) { - CommandLine cl; - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } struct rlimit limits { 0, 0 }; getrlimit(RLIMIT_NOFILE, &limits); diag("Old process limits: { %ld, %ld }", limits.rlim_cur, limits.rlim_max); @@ -67,15 +64,8 @@ int main(int argc, char** argv) { for (int i = 0; i < NUM_CONNECTIONS; i++) { MYSQL* proxy = mysql_init(NULL); - if ( - !mysql_real_connect( - proxy, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0 - ) - ) { - fprintf( - stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, - mysql_error(proxy) - ); + if (!mysql_real_connect(proxy, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy)); return EXIT_FAILURE; } mysql_connections.push_back(proxy); diff --git a/test/tap/tests/reg_test_3603-stmt_metadata-t.cpp b/test/tap/tests/reg_test_3603-stmt_metadata-t.cpp index 8afc9a8614..8ea92cc75b 100644 --- a/test/tap/tests/reg_test_3603-stmt_metadata-t.cpp +++ b/test/tap/tests/reg_test_3603-stmt_metadata-t.cpp @@ -37,6 +37,8 @@ using std::string; +CommandLine cl; + int update_and_check( MYSQL_STMT *stmti, MYSQL_STMT *stmts, int64_t id, char *cll_num, char *dst_num, int64_t* dur, MYSQL_TIME *end_time, char *lst_msg, char *lst_st, int *mapping_id, @@ -503,12 +505,6 @@ int update_and_check( } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } int np = 4; // init + prepare np += 5*2; // number of INSERT+SELECT diff --git a/test/tap/tests/reg_test_3606-mysql_warnings-t.cpp b/test/tap/tests/reg_test_3606-mysql_warnings-t.cpp index b5a1fc3166..ef9cb867da 100644 --- a/test/tap/tests/reg_test_3606-mysql_warnings-t.cpp +++ b/test/tap/tests/reg_test_3606-mysql_warnings-t.cpp @@ -31,6 +31,8 @@ using std::vector; using std::tuple; using std::string; +CommandLine cl; + enum query_type { TEXT_SELECT_WARNING = 0, TEXT_SELECT_NO_WARNING, @@ -81,7 +83,6 @@ int create_testing_tables(MYSQL* mysql_server) { } int main(int argc, char** argv) { - CommandLine cl; uint32_t c_operations = 500; @@ -94,11 +95,6 @@ int main(int argc, char** argv) { floor(((double)c_operations - 1.0) * (1.0 / 2.0)); // Number of updates checks plan(plan_val); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - MYSQL* proxy_mysql = mysql_init(NULL); MYSQL* proxy_admin = mysql_init(NULL); @@ -112,10 +108,7 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - if ( - !mysql_real_connect(proxy_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, - CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS) - ) { + if (!mysql_real_connect(proxy_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_mysql)); return EXIT_FAILURE; } diff --git a/test/tap/tests/reg_test_3625-sqlite3_session_client_error_limit-t.cpp b/test/tap/tests/reg_test_3625-sqlite3_session_client_error_limit-t.cpp index 70d6106819..e4c1b48c4f 100644 --- a/test/tap/tests/reg_test_3625-sqlite3_session_client_error_limit-t.cpp +++ b/test/tap/tests/reg_test_3625-sqlite3_session_client_error_limit-t.cpp @@ -22,12 +22,13 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + using query_spec = std::tuple; const int sqlite3_port = 0; int main(int argc, char** argv) { - CommandLine cl; // plan as many tests as queries plan( @@ -39,24 +40,11 @@ int main(int argc, char** argv) { 1 ); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - MYSQL* proxysql_admin = mysql_init(NULL); // Connect to ProxySQL Admin and check current SQLite3 configuration - if ( - !mysql_real_connect( - proxysql_admin, cl.host, cl.admin_username, cl.admin_password, - NULL, cl.admin_port, NULL, 0 - ) - ) { - fprintf( - stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, - mysql_error(proxysql_admin) - ); + if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return EXIT_FAILURE; } @@ -83,12 +71,7 @@ int main(int argc, char** argv) { // Connect with invalid username std::string inv_user_err {}; bool failed_to_connect = false; - if ( - !mysql_real_connect( - proxysql_sqlite3, host_port.first.c_str(), "foobar_user", cl.password, - NULL, host_port.second, NULL, 0 - ) - ) { + if (!mysql_real_connect(proxysql_sqlite3, host_port.first.c_str(), "foobar_user", cl.password, NULL, host_port.second, NULL, 0)) { inv_user_err = mysql_error(proxysql_sqlite3); failed_to_connect = true; } @@ -106,12 +89,7 @@ int main(int argc, char** argv) { // Connect with invalid password std::string inv_pass_err {}; failed_to_connect = false; - if ( - !mysql_real_connect( - proxysql_sqlite3, host_port.first.c_str(), cl.username, "foobar_pass", - NULL, host_port.second, NULL, 0 - ) - ) { + if (!mysql_real_connect(proxysql_sqlite3, host_port.first.c_str(), cl.username, "foobar_pass", NULL, host_port.second, NULL, 0)) { inv_pass_err = mysql_error(proxysql_sqlite3); failed_to_connect = true; } @@ -130,12 +108,7 @@ int main(int argc, char** argv) { // Perform the valid connection { // Correctly connect to SQLite3 server - MYSQL* connect_errno = - mysql_real_connect( - proxysql_sqlite3, host_port.first.c_str(), cl.username, cl.password, - NULL, host_port.second, NULL, 0 - ); - + MYSQL* connect_errno = mysql_real_connect(proxysql_sqlite3, host_port.first.c_str(), cl.username, cl.password, NULL, host_port.second, NULL, 0); ok( connect_errno != NULL, "Connection should succeed when using a valid 'username:password' (%s:%s)", diff --git a/test/tap/tests/reg_test_3690-admin_large_pkts-t.cpp b/test/tap/tests/reg_test_3690-admin_large_pkts-t.cpp index 83687245fc..927ebce750 100644 --- a/test/tap/tests/reg_test_3690-admin_large_pkts-t.cpp +++ b/test/tap/tests/reg_test_3690-admin_large_pkts-t.cpp @@ -26,6 +26,8 @@ using std::string; using std::vector; +CommandLine cl; + string create_testing_table_query(int col_num) { string test_table_query { "CREATE TABLE reg_test_3690_table (id INT" }; @@ -150,12 +152,6 @@ uint32_t COLUMN_NUM = 10; uint32_t ROW_NUM = 10; int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } MYSQL* proxysql_admin = mysql_init(NULL); diff --git a/test/tap/tests/reg_test_3765_ssl_pollout-t.cpp b/test/tap/tests/reg_test_3765_ssl_pollout-t.cpp index 4a42904d97..774e0a8d3b 100644 --- a/test/tap/tests/reg_test_3765_ssl_pollout-t.cpp +++ b/test/tap/tests/reg_test_3765_ssl_pollout-t.cpp @@ -26,6 +26,8 @@ using std::string; using std::vector; +CommandLine cl; + /** * @brief TODO: Refactor this into utils, also used in another PR. */ @@ -61,9 +63,9 @@ const uint32_t MYSQL_CONN_NUM = 100; const uint32_t REPORT_INTV_SEC = 5; double MAX_ALLOWED_CPU_USAGE = (double) get_env_int("TAP_MAX_ALLOWED_CPU_USAGE", 13); -int get_idle_conns_cpu_usage(CommandLine& cl, uint64_t mode, double& idle_cpu_ms, double& final_cpu_ms) { +int get_idle_conns_cpu_usage(uint64_t mode, double& idle_cpu_ms, double& final_cpu_ms) { // get ProxySQL idle cpu usage - int idle_err = get_proxysql_cpu_usage(cl, REPORT_INTV_SEC, idle_cpu_ms); + int idle_err = get_proxysql_cpu_usage(REPORT_INTV_SEC, idle_cpu_ms); if (idle_err) { diag("File %s, line %d, Error: '%s'", __FILE__, __LINE__, "Unable to get 'idle_cpu' usage."); return idle_err; @@ -87,7 +89,7 @@ int get_idle_conns_cpu_usage(CommandLine& cl, uint64_t mode, double& idle_cpu_ms return EXIT_FAILURE; } - int final_err = get_proxysql_cpu_usage(cl, REPORT_INTV_SEC, final_cpu_ms); + int final_err = get_proxysql_cpu_usage(REPORT_INTV_SEC, final_cpu_ms); if (final_err) { diag("File %s, line %d, Error: '%s'", __FILE__, __LINE__, "Unable to get 'idle_cpu' usage."); return idle_err; @@ -100,12 +102,6 @@ int get_idle_conns_cpu_usage(CommandLine& cl, uint64_t mode, double& idle_cpu_ms } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return exit_status(); - } plan(6); @@ -123,7 +119,7 @@ int main(int argc, char** argv) { mysql_close(proxysql_admin); diag("Testing regular connections..."); - int ret_cpu_usage = get_idle_conns_cpu_usage(cl, 0, idle_cpu_ms, final_cpu_ms); + int ret_cpu_usage = get_idle_conns_cpu_usage(0, idle_cpu_ms, final_cpu_ms); if (ret_cpu_usage != EXIT_SUCCESS) { return EXIT_FAILURE; } ok( @@ -139,7 +135,7 @@ int main(int argc, char** argv) { ); diag("Testing SSL connections..."); - ret_cpu_usage = get_idle_conns_cpu_usage(cl, CLIENT_SSL, idle_cpu_ms, final_cpu_ms); + ret_cpu_usage = get_idle_conns_cpu_usage(CLIENT_SSL, idle_cpu_ms, final_cpu_ms); if (ret_cpu_usage != EXIT_SUCCESS) { return EXIT_FAILURE; } ok( @@ -155,7 +151,7 @@ int main(int argc, char** argv) { ); diag("Testing SSL and compressed connections..."); - ret_cpu_usage = get_idle_conns_cpu_usage(cl, CLIENT_SSL|CLIENT_COMPRESS, idle_cpu_ms, final_cpu_ms); + ret_cpu_usage = get_idle_conns_cpu_usage(CLIENT_SSL|CLIENT_COMPRESS, idle_cpu_ms, final_cpu_ms); if (ret_cpu_usage != EXIT_SUCCESS) { return EXIT_FAILURE; } ok( diff --git a/test/tap/tests/reg_test_3838-restapi_eintr-t.cpp b/test/tap/tests/reg_test_3838-restapi_eintr-t.cpp index b890a43d8c..fe1b117754 100644 --- a/test/tap/tests/reg_test_3838-restapi_eintr-t.cpp +++ b/test/tap/tests/reg_test_3838-restapi_eintr-t.cpp @@ -34,6 +34,8 @@ using std::string; using std::vector; +CommandLine cl; + const int SIGNAL_NUM = 5; const string base_address { "http://localhost:6070/sync/" }; @@ -49,12 +51,6 @@ vector> endpoint_requests { }; int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } plan(endpoint_requests.size()); diff --git a/test/tap/tests/reg_test_3847_admin_lock-t.cpp b/test/tap/tests/reg_test_3847_admin_lock-t.cpp index e110a7874b..b3815daf51 100644 --- a/test/tap/tests/reg_test_3847_admin_lock-t.cpp +++ b/test/tap/tests/reg_test_3847_admin_lock-t.cpp @@ -21,12 +21,12 @@ using std::string; using std::vector; +CommandLine cl; + int main(int argc, char** argv) { - CommandLine cl; const char* WORKSPACE = getenv("WORKSPACE"); - - if (cl.getEnv() || WORKSPACE == nullptr) { + if (WORKSPACE == nullptr) { diag("Failed to get the required environmental variables."); return EXIT_FAILURE; } @@ -53,7 +53,7 @@ int main(int argc, char** argv) { int launch_res = -1; - std::thread launch_sec_proxy = std::thread([&WORKSPACE,&cl] (int& err_code) -> void { + std::thread launch_sec_proxy = std::thread([&WORKSPACE] (int& err_code) -> void { to_opts_t wexecvp_opts {}; wexecvp_opts.poll_to_us = 100*1000; wexecvp_opts.waitpid_delay_us = 500*1000; @@ -109,7 +109,7 @@ int main(int argc, char** argv) { MYSQL_QUERY(s_proxy_admin, "SET admin-cluster_mysql_variables_diffs_before_sync=1"); MYSQL_QUERY(s_proxy_admin, "LOAD ADMIN VARIABLES TO RUNTIME"); - std::thread th_load_mysql_vars([&cl] (bool& stop, int& load_res) -> void { + std::thread th_load_mysql_vars([] (bool& stop, int& load_res) -> void { MYSQL* admin = mysql_init(NULL); if (!mysql_real_connect(admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { @@ -143,7 +143,7 @@ int main(int argc, char** argv) { mysql_close(admin); }, std::ref(stop), std::ref(q_load_res)); - std::thread th_query_globals([&cl] (bool& stop, int& save_res) -> void { + std::thread th_query_globals([] (bool& stop, int& save_res) -> void { MYSQL* admin = mysql_init(NULL); if (!mysql_real_connect(admin, cl.host, cl.admin_username, cl.admin_password, NULL, 26081, NULL, 0)) { diff --git a/test/tap/tests/reg_test_3992_fast_forward_malformed_packet-mysqlsh-t.cpp b/test/tap/tests/reg_test_3992_fast_forward_malformed_packet-mysqlsh-t.cpp index b19e38edc2..8e62755e70 100644 --- a/test/tap/tests/reg_test_3992_fast_forward_malformed_packet-mysqlsh-t.cpp +++ b/test/tap/tests/reg_test_3992_fast_forward_malformed_packet-mysqlsh-t.cpp @@ -17,14 +17,10 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + int main(int argc, char** argv) { - CommandLine cl; - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - const std::vector> users { {"mariadbuserff", "mariadbuserff"}, {"mariadbuser", "mariadbuser"} }; diff --git a/test/tap/tests/reg_test_3992_fast_forward_malformed_packet-t.cpp b/test/tap/tests/reg_test_3992_fast_forward_malformed_packet-t.cpp index 128fdec549..990773dd64 100644 --- a/test/tap/tests/reg_test_3992_fast_forward_malformed_packet-t.cpp +++ b/test/tap/tests/reg_test_3992_fast_forward_malformed_packet-t.cpp @@ -17,18 +17,14 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + int main(int argc, char** argv) { - CommandLine cl; - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - std::vector conns; - + const std::vector> users { {"mariadbuserff", "mariadbuserff"}, - {"mariadbuser", "mariadbuser"} }; + {"mariadbuser", "mariadbuser"} }; const std::vector queries {"SHOW DATABASES", "SELECT 1"}; diff --git a/test/tap/tests/reg_test_4001-restapi_scripts_num_fds-t.cpp b/test/tap/tests/reg_test_4001-restapi_scripts_num_fds-t.cpp index b035d8c40d..4a88da052a 100644 --- a/test/tap/tests/reg_test_4001-restapi_scripts_num_fds-t.cpp +++ b/test/tap/tests/reg_test_4001-restapi_scripts_num_fds-t.cpp @@ -34,6 +34,8 @@ using nlohmann::json; using std::string; using std::vector; +CommandLine cl; + const int NUM_CONNECTIONS = 1300; const string base_address { "http://localhost:6070/sync/" }; @@ -49,12 +51,6 @@ const vector honest_requests { }; int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } diag("Setting new process limits beyond 'FD_SETSIZE'"); struct rlimit limits { 0, 0 }; diff --git a/test/tap/tests/reg_test_4055_restapi-t.cpp b/test/tap/tests/reg_test_4055_restapi-t.cpp index 73564c73be..c477593179 100644 --- a/test/tap/tests/reg_test_4055_restapi-t.cpp +++ b/test/tap/tests/reg_test_4055_restapi-t.cpp @@ -26,18 +26,14 @@ using std::string; +CommandLine cl; + /* This is an estimation of the supported number of metrics as for '2022-12-15' */ uint32_t SUPPORTED_METRICS = 148; int main(int argc, char** argv) { - plan(5); - - CommandLine cl; - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } + plan(5); MYSQL* admin = mysql_init(NULL); diff --git a/test/tap/tests/reg_test_4072-show-warnings-t.cpp b/test/tap/tests/reg_test_4072-show-warnings-t.cpp index b4f60e2e03..a799602e10 100644 --- a/test/tap/tests/reg_test_4072-show-warnings-t.cpp +++ b/test/tap/tests/reg_test_4072-show-warnings-t.cpp @@ -13,13 +13,9 @@ #include "command_line.h" #include "utils.h" -int main(int argc, char** argv) { - CommandLine cl; +CommandLine cl; - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } +int main(int argc, char** argv) { plan(1); diff --git a/test/tap/tests/reg_test_4158_change_user-t.cpp b/test/tap/tests/reg_test_4158_change_user-t.cpp index e7d7a86957..2a0c810c1c 100644 --- a/test/tap/tests/reg_test_4158_change_user-t.cpp +++ b/test/tap/tests/reg_test_4158_change_user-t.cpp @@ -99,11 +99,6 @@ int main(int, char**) { plan(loop1 * (loop2 + 2)); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - /* // PLACEHOLDER MYSQL* admin = mysql_init(NULL); diff --git a/test/tap/tests/reg_test_4264-commit_rollback-t.cpp b/test/tap/tests/reg_test_4264-commit_rollback-t.cpp index 1c5c6585ab..2f3aff7a00 100644 --- a/test/tap/tests/reg_test_4264-commit_rollback-t.cpp +++ b/test/tap/tests/reg_test_4264-commit_rollback-t.cpp @@ -63,6 +63,8 @@ const uint32_t TG_HG_1 = 1047; const uint32_t TG_HG_2 = 1048; const string TG_HG_STR { to_string(TG_HG_1) }; +CommandLine cl; + /** * @details Flow for explicit and persistent trxs: * - BEGIN -> Starts a trx, in default hostgroup. @@ -74,7 +76,7 @@ const string TG_HG_STR { to_string(TG_HG_1) }; * + Check that query have been executed in the 'BEGIN' hostgroup. * + Check that ConnUsed have decreased after query. */ -int explicit_trx_persist(CommandLine& cl, MYSQL* admin, MYSQL* proxy, const string& trx_cmd) { +int explicit_trx_persist(MYSQL* admin, MYSQL* proxy, const string& trx_cmd) { const vector tg_hgs { DF_HG }; const pair pre_pool_state_res { fetch_conn_stats(admin, tg_hgs) }; if (pre_pool_state_res.first) { return EXIT_FAILURE; } @@ -105,7 +107,7 @@ int explicit_trx_persist(CommandLine& cl, MYSQL* admin, MYSQL* proxy, const stri * @details Same check as 'explicit_trx_persist' but trx is created in random hostgroup. * Ensures that default hostgroup routing works as non-default routing. */ -int explicit_trx_persist_2(CommandLine& cl, MYSQL* admin, MYSQL* proxy, const string& trx_cmd) { +int explicit_trx_persist_2(MYSQL* admin, MYSQL* proxy, const string& trx_cmd) { const vector tg_hgs { DF_HG, TG_HG_1 }; const pair pre_pool_state_res { fetch_conn_stats(admin, tg_hgs) }; if (pre_pool_state_res.first) { return EXIT_FAILURE; } @@ -137,23 +139,23 @@ int explicit_trx_persist_2(CommandLine& cl, MYSQL* admin, MYSQL* proxy, const st * 'transaction_persistent=1' should disable routing, and all operations * should be done in the same backend connection. */ -int explicit_trx_persist_c(CommandLine& cl, MYSQL* admin, MYSQL* proxy) { - return explicit_trx_persist(cl, admin, proxy, "COMMIT"); +int explicit_trx_persist_c(MYSQL* admin, MYSQL* proxy) { + return explicit_trx_persist(admin, proxy, "COMMIT"); } -int explicit_trx_persist_r(CommandLine& cl, MYSQL* admin, MYSQL* proxy) { - return explicit_trx_persist(cl, admin, proxy, "ROLLBACK"); +int explicit_trx_persist_r(MYSQL* admin, MYSQL* proxy) { + return explicit_trx_persist(admin, proxy, "ROLLBACK"); } -int explicit_trx_persist_2_c(CommandLine& cl, MYSQL* admin, MYSQL* proxy) { - return explicit_trx_persist_2(cl, admin, proxy, "COMMIT"); +int explicit_trx_persist_2_c(MYSQL* admin, MYSQL* proxy) { + return explicit_trx_persist_2(admin, proxy, "COMMIT"); } -int explicit_trx_persist_2_r(CommandLine& cl, MYSQL* admin, MYSQL* proxy) { - return explicit_trx_persist_2(cl, admin, proxy, "ROLLBACK"); +int explicit_trx_persist_2_r(MYSQL* admin, MYSQL* proxy) { + return explicit_trx_persist_2(admin, proxy, "ROLLBACK"); } -int implicit_trx_persist(CommandLine& cl, MYSQL* admin, MYSQL* proxy, const string& trx_cmd) { +int implicit_trx_persist(MYSQL* admin, MYSQL* proxy, const string& trx_cmd) { const vector tg_hgs { DF_HG, TG_HG_1 }; const pair pre_pool_state_res { fetch_conn_stats(admin, tg_hgs) }; if (pre_pool_state_res.first) { return EXIT_FAILURE; } @@ -183,15 +185,15 @@ int implicit_trx_persist(CommandLine& cl, MYSQL* admin, MYSQL* proxy, const stri return EXIT_SUCCESS; } -int implicit_trx_persist_c(CommandLine& cl, MYSQL* admin, MYSQL* proxy) { - return implicit_trx_persist(cl, admin, proxy, "COMMIT"); +int implicit_trx_persist_c(MYSQL* admin, MYSQL* proxy) { + return implicit_trx_persist(admin, proxy, "COMMIT"); } -int implicit_trx_persist_r(CommandLine& cl, MYSQL* admin, MYSQL* proxy) { - return implicit_trx_persist(cl, admin, proxy, "ROLLBACK"); +int implicit_trx_persist_r(MYSQL* admin, MYSQL* proxy) { + return implicit_trx_persist(admin, proxy, "ROLLBACK"); } -int explicit_trx_persist_no_def_hg(CommandLine& cl, MYSQL* admin, MYSQL* proxy, const string& trx_cmd) { +int explicit_trx_persist_no_def_hg(MYSQL* admin, MYSQL* proxy, const string& trx_cmd) { const vector tg_hgs { TG_HG_1 }; const pair pre_pool_state_res { fetch_conn_stats(admin, tg_hgs) }; if (pre_pool_state_res.first) { return EXIT_FAILURE; } @@ -214,15 +216,15 @@ int explicit_trx_persist_no_def_hg(CommandLine& cl, MYSQL* admin, MYSQL* proxy, return EXIT_SUCCESS; } -int explicit_trx_persist_no_def_hg_c(CommandLine& cl, MYSQL* admin, MYSQL* proxy) { - return explicit_trx_persist_no_def_hg(cl, admin, proxy, "COMMIT"); +int explicit_trx_persist_no_def_hg_c(MYSQL* admin, MYSQL* proxy) { + return explicit_trx_persist_no_def_hg(admin, proxy, "COMMIT"); } -int explicit_trx_persist_no_def_hg_r(CommandLine& cl, MYSQL* admin, MYSQL* proxy) { - return explicit_trx_persist_no_def_hg(cl, admin, proxy, "ROLLBACK"); +int explicit_trx_persist_no_def_hg_r(MYSQL* admin, MYSQL* proxy) { + return explicit_trx_persist_no_def_hg(admin, proxy, "ROLLBACK"); } -int implicit_trx_persist_no_def_hg(CommandLine& cl, MYSQL* admin, MYSQL* proxy, const string& trx_cmd) { +int implicit_trx_persist_no_def_hg(MYSQL* admin, MYSQL* proxy, const string& trx_cmd) { const vector tg_hgs { DF_HG, TG_HG_1 }; const pair pre_pool_state_res { fetch_conn_stats(admin, tg_hgs) }; if (pre_pool_state_res.first) { return EXIT_FAILURE; } @@ -249,12 +251,12 @@ int implicit_trx_persist_no_def_hg(CommandLine& cl, MYSQL* admin, MYSQL* proxy, return EXIT_SUCCESS; } -int implicit_trx_persist_no_def_hg_c(CommandLine& cl, MYSQL* admin, MYSQL* proxy) { - return implicit_trx_persist_no_def_hg(cl, admin, proxy, "COMMIT"); +int implicit_trx_persist_no_def_hg_c(MYSQL* admin, MYSQL* proxy) { + return implicit_trx_persist_no_def_hg(admin, proxy, "COMMIT"); } -int implicit_trx_persist_no_def_hg_r(CommandLine& cl, MYSQL* admin, MYSQL* proxy) { - return implicit_trx_persist_no_def_hg(cl, admin, proxy, "ROLLBACK"); +int implicit_trx_persist_no_def_hg_r(MYSQL* admin, MYSQL* proxy) { + return implicit_trx_persist_no_def_hg(admin, proxy, "ROLLBACK"); } /** @@ -268,7 +270,7 @@ int implicit_trx_persist_no_def_hg_r(CommandLine& cl, MYSQL* admin, MYSQL* proxy * + Check that query have been executed in the 'BEGIN' hostgroup. * + Check that ConnUsed have decreased after query. */ -int explicit_trx_no_persist(CommandLine& cl, MYSQL* admin, MYSQL*, const string& trx_cmd) { +int explicit_trx_no_persist(MYSQL* admin, MYSQL*, const string& trx_cmd) { MYSQL* proxy_sbtest = mysql_init(NULL); if (!mysql_real_connect(proxy_sbtest, cl.host, "sbtest1", "sbtest1", NULL, cl.port, NULL, 0)) { @@ -307,7 +309,7 @@ int explicit_trx_no_persist(CommandLine& cl, MYSQL* admin, MYSQL*, const string& * @details Same check as 'explicit_trx_no_persist' but trx is created in random hostgroup. * Ensures that default hostgroup routing works as non-default routing. */ -int explicit_trx_no_persist_2(CommandLine& cl, MYSQL* admin, MYSQL*, const string& trx_cmd) { +int explicit_trx_no_persist_2(MYSQL* admin, MYSQL*, const string& trx_cmd) { MYSQL* sbtest = mysql_init(NULL); if (!mysql_real_connect(sbtest, cl.host, "sbtest1", "sbtest1", NULL, cl.port, NULL, 0)) { @@ -343,23 +345,23 @@ int explicit_trx_no_persist_2(CommandLine& cl, MYSQL* admin, MYSQL*, const strin return EXIT_SUCCESS; } -int explicit_trx_no_persist_c(CommandLine& cl, MYSQL* admin, MYSQL*) { - return explicit_trx_no_persist(cl, admin, nullptr, "COMMIT"); +int explicit_trx_no_persist_c(MYSQL* admin, MYSQL*) { + return explicit_trx_no_persist(admin, nullptr, "COMMIT"); } -int explicit_trx_no_persist_r(CommandLine& cl, MYSQL* admin, MYSQL*) { - return explicit_trx_no_persist(cl, admin, nullptr, "ROLLBACK"); +int explicit_trx_no_persist_r(MYSQL* admin, MYSQL*) { + return explicit_trx_no_persist(admin, nullptr, "ROLLBACK"); } -int explicit_trx_no_persist_2_c(CommandLine& cl, MYSQL* admin, MYSQL* proxy) { - return explicit_trx_no_persist_2(cl, admin, proxy, "COMMIT"); +int explicit_trx_no_persist_2_c(MYSQL* admin, MYSQL* proxy) { + return explicit_trx_no_persist_2(admin, proxy, "COMMIT"); } -int explicit_trx_no_persist_2_r(CommandLine& cl, MYSQL* admin, MYSQL* proxy) { - return explicit_trx_no_persist_2(cl, admin, proxy, "ROLLBACK"); +int explicit_trx_no_persist_2_r(MYSQL* admin, MYSQL* proxy) { + return explicit_trx_no_persist_2(admin, proxy, "ROLLBACK"); } -int explicit_trx_no_persist_no_def_hg(CommandLine& cl, MYSQL* admin, MYSQL*, const string& trx_cmd) { +int explicit_trx_no_persist_no_def_hg(MYSQL* admin, MYSQL*, const string& trx_cmd) { MYSQL* proxy_sbtest = mysql_init(NULL); if (!mysql_real_connect(proxy_sbtest, cl.host, "sbtest1", "sbtest1", NULL, cl.port, NULL, 0)) { @@ -394,19 +396,19 @@ int explicit_trx_no_persist_no_def_hg(CommandLine& cl, MYSQL* admin, MYSQL*, con return EXIT_SUCCESS; }; -int explicit_trx_no_persist_no_def_hg_c(CommandLine& cl, MYSQL* admin, MYSQL*) { - return explicit_trx_no_persist_no_def_hg(cl, admin, nullptr, "COMMIT"); +int explicit_trx_no_persist_no_def_hg_c(MYSQL* admin, MYSQL*) { + return explicit_trx_no_persist_no_def_hg(admin, nullptr, "COMMIT"); } -int explicit_trx_no_persist_no_def_hg_r(CommandLine& cl, MYSQL* admin, MYSQL*) { - return explicit_trx_no_persist_no_def_hg(cl, admin, nullptr, "ROLLBACK"); +int explicit_trx_no_persist_no_def_hg_r(MYSQL* admin, MYSQL*) { + return explicit_trx_no_persist_no_def_hg(admin, nullptr, "ROLLBACK"); } /** * @details Checks that implicit transactions with no persistence execute the rollback in the correct * hostgroup. */ -int implicit_trx_no_persist_no_def_hg(CommandLine& cl, MYSQL* admin, MYSQL*, const string& trx_cmd) { +int implicit_trx_no_persist_no_def_hg(MYSQL* admin, MYSQL*, const string& trx_cmd) { MYSQL* proxy_sbtest = mysql_init(NULL); if (!mysql_real_connect(proxy_sbtest, cl.host, "sbtest1", "sbtest1", NULL, cl.port, NULL, 0)) { @@ -459,12 +461,12 @@ int implicit_trx_no_persist_no_def_hg(CommandLine& cl, MYSQL* admin, MYSQL*, con return EXIT_SUCCESS; }; -int implicit_trx_no_persist_no_def_hg_c(CommandLine& cl, MYSQL* admin, MYSQL*) { - return implicit_trx_no_persist_no_def_hg(cl, admin, nullptr, "COMMIT"); +int implicit_trx_no_persist_no_def_hg_c(MYSQL* admin, MYSQL*) { + return implicit_trx_no_persist_no_def_hg(admin, nullptr, "COMMIT"); } -int implicit_trx_no_persist_no_def_hg_r(CommandLine& cl, MYSQL* admin, MYSQL*) { - return implicit_trx_no_persist_no_def_hg(cl, admin, nullptr, "ROLLBACK"); +int implicit_trx_no_persist_no_def_hg_r(MYSQL* admin, MYSQL*) { + return implicit_trx_no_persist_no_def_hg(admin, nullptr, "ROLLBACK"); } /** @@ -481,7 +483,7 @@ int implicit_trx_no_persist_no_def_hg_r(CommandLine& cl, MYSQL* admin, MYSQL*) { * + Check that conns used have decreased in hg. */ int explicit_unknown_trx_persist_no_def_hg( - CommandLine& cl, MYSQL* admin, MYSQL* proxy, const string& trx_cmd + MYSQL* admin, MYSQL* proxy, const string& trx_cmd ) { diag("Ensure 'autocommit=1' for reused connection"); MYSQL_QUERY_T(proxy, "SET autocommit=1"); @@ -524,12 +526,12 @@ int explicit_unknown_trx_persist_no_def_hg( return EXIT_SUCCESS; } -int explicit_unknown_trx_persist_no_def_hg_c(CommandLine& cl, MYSQL* admin, MYSQL* proxy) { - return explicit_unknown_trx_persist_no_def_hg(cl, admin, proxy, "COMMIT"); +int explicit_unknown_trx_persist_no_def_hg_c(MYSQL* admin, MYSQL* proxy) { + return explicit_unknown_trx_persist_no_def_hg(admin, proxy, "COMMIT"); } -int explicit_unknown_trx_persist_no_def_hg_r(CommandLine& cl, MYSQL* admin, MYSQL* proxy) { - return explicit_unknown_trx_persist_no_def_hg(cl, admin, proxy, "ROLLBACK"); +int explicit_unknown_trx_persist_no_def_hg_r(MYSQL* admin, MYSQL* proxy) { + return explicit_unknown_trx_persist_no_def_hg(admin, proxy, "ROLLBACK"); } /** @@ -545,7 +547,7 @@ int explicit_unknown_trx_persist_no_def_hg_r(CommandLine& cl, MYSQL* admin, MYSQ * + Check that conns used have decreased in hg. */ int implicit_unknown_trx_persist_no_def_hg( - CommandLine& cl, MYSQL* admin, MYSQL* proxy, const string& trx_cmd + MYSQL* admin, MYSQL* proxy, const string& trx_cmd ) { diag("Ensure 'autocommit=1' for reused connection"); MYSQL_QUERY_T(proxy, "SET autocommit=1"); @@ -587,12 +589,12 @@ int implicit_unknown_trx_persist_no_def_hg( return EXIT_SUCCESS; } -int implicit_unknown_trx_persist_no_def_hg_c(CommandLine& cl, MYSQL* admin, MYSQL*) { - return implicit_unknown_trx_persist_no_def_hg(cl, admin, nullptr, "COMMIT"); +int implicit_unknown_trx_persist_no_def_hg_c(MYSQL* admin, MYSQL*) { + return implicit_unknown_trx_persist_no_def_hg(admin, nullptr, "COMMIT"); } -int implicit_unknown_trx_persist_no_def_hg_r(CommandLine& cl, MYSQL* admin, MYSQL*) { - return implicit_unknown_trx_persist_no_def_hg(cl, admin, nullptr, "ROLLBACK"); +int implicit_unknown_trx_persist_no_def_hg_r(MYSQL* admin, MYSQL*) { + return implicit_unknown_trx_persist_no_def_hg(admin, nullptr, "ROLLBACK"); } /** @@ -605,7 +607,7 @@ int implicit_unknown_trx_persist_no_def_hg_r(CommandLine& cl, MYSQL* admin, MYSQ * + Should be executed in trx with 'unknown_transaction_status'. */ int explicit_and_unknown_trx_no_persist_no_def_hg( - CommandLine& cl, MYSQL* admin, MYSQL*, const string& trx_cmd + MYSQL* admin, MYSQL*, const string& trx_cmd ) { MYSQL* proxy_sbtest = mysql_init(NULL); @@ -661,12 +663,12 @@ int explicit_and_unknown_trx_no_persist_no_def_hg( return EXIT_SUCCESS; } -int explicit_and_unknown_trx_no_persist_no_def_hg_c(CommandLine& cl, MYSQL* admin, MYSQL*) { - return explicit_and_unknown_trx_no_persist_no_def_hg(cl, admin, nullptr, "COMMIT"); +int explicit_and_unknown_trx_no_persist_no_def_hg_c(MYSQL* admin, MYSQL*) { + return explicit_and_unknown_trx_no_persist_no_def_hg(admin, nullptr, "COMMIT"); } -int explicit_and_unknown_trx_no_persist_no_def_hg_r(CommandLine& cl, MYSQL* admin, MYSQL*) { - return explicit_and_unknown_trx_no_persist_no_def_hg(cl, admin, nullptr, "ROLLBACK"); +int explicit_and_unknown_trx_no_persist_no_def_hg_r(MYSQL* admin, MYSQL*) { + return explicit_and_unknown_trx_no_persist_no_def_hg(admin, nullptr, "ROLLBACK"); } /** @@ -680,7 +682,7 @@ int explicit_and_unknown_trx_no_persist_no_def_hg_r(CommandLine& cl, MYSQL* admi * + Should be executed in trx with 'unknown_transaction_status', hg 'M'. */ int implicit_and_unknown_trx_no_persist_no_def_hg( - CommandLine& cl, MYSQL* admin, MYSQL*, const string& trx_cmd + MYSQL* admin, MYSQL*, const string& trx_cmd ) { MYSQL* sbtest = mysql_init(NULL); @@ -744,12 +746,12 @@ int implicit_and_unknown_trx_no_persist_no_def_hg( return EXIT_SUCCESS; } -int implicit_and_unknown_trx_no_persist_no_def_hg_c(CommandLine& cl, MYSQL* admin, MYSQL*) { - return implicit_and_unknown_trx_no_persist_no_def_hg(cl, admin, nullptr, "COMMIT"); +int implicit_and_unknown_trx_no_persist_no_def_hg_c(MYSQL* admin, MYSQL*) { + return implicit_and_unknown_trx_no_persist_no_def_hg(admin, nullptr, "COMMIT"); } -int implicit_and_unknown_trx_no_persist_no_def_hg_r(CommandLine& cl, MYSQL* admin, MYSQL*) { - return implicit_and_unknown_trx_no_persist_no_def_hg(cl, admin, nullptr, "ROLLBACK"); +int implicit_and_unknown_trx_no_persist_no_def_hg_r(MYSQL* admin, MYSQL*) { + return implicit_and_unknown_trx_no_persist_no_def_hg(admin, nullptr, "ROLLBACK"); } /** @@ -768,7 +770,7 @@ int implicit_and_unknown_trx_no_persist_no_def_hg_r(CommandLine& cl, MYSQL* admi * * Third command hits the conn with 'unknown trx' status. */ int implicit_trx_and_savepoints_no_persist_no_def_hg_( - CommandLine& cl, MYSQL* admin, MYSQL*, const string& trx_cmd + MYSQL* admin, MYSQL*, const string& trx_cmd ) { MYSQL* sbtest = mysql_init(NULL); @@ -970,7 +972,7 @@ int implicit_trx_and_savepoints_no_persist_no_def_hg_( * * Third command hits the conn with 'unknown trx' status. */ int implicit_trx_and_savepoints_no_persist_no_def_hg( - CommandLine& cl, MYSQL* admin, MYSQL*, const string& trx_cmd + MYSQL* admin, MYSQL*, const string& trx_cmd ) { MYSQL* sbtest = mysql_init(NULL); @@ -1056,17 +1058,17 @@ int implicit_trx_and_savepoints_no_persist_no_def_hg( return EXIT_SUCCESS; } -int implicit_trx_and_savepoints_no_persist_no_def_hg_c(CommandLine& cl, MYSQL* admin, MYSQL*) { - return implicit_trx_and_savepoints_no_persist_no_def_hg_(cl, admin, nullptr, "COMMIT"); +int implicit_trx_and_savepoints_no_persist_no_def_hg_c(MYSQL* admin, MYSQL*) { + return implicit_trx_and_savepoints_no_persist_no_def_hg_(admin, nullptr, "COMMIT"); } -int implicit_trx_and_savepoints_no_persist_no_def_hg_r(CommandLine& cl, MYSQL* admin, MYSQL*) { - return implicit_trx_and_savepoints_no_persist_no_def_hg(cl, admin, nullptr, "ROLLBACK"); +int implicit_trx_and_savepoints_no_persist_no_def_hg_r(MYSQL* admin, MYSQL*) { + return implicit_trx_and_savepoints_no_persist_no_def_hg(admin, nullptr, "ROLLBACK"); } struct test_case_t { string name; - function fn; + function fn; }; #define create_test_case(name) { #name, name } @@ -1156,15 +1158,9 @@ int prepare_tables_and_config(MYSQL* admin, MYSQL* proxy) { } int main(int argc, char** argv) { - CommandLine cl; plan(313); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - MYSQL* proxy = mysql_init(NULL); if (!mysql_real_connect(proxy, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy)); @@ -1185,7 +1181,7 @@ int main(int argc, char** argv) { for (const auto test : test_cases) { fprintf(stderr, "\n"); diag("Starting test '%s'", test.name.c_str()); - test.fn(cl, admin, proxy); + test.fn(admin, proxy); } cleanup: diff --git a/test/tap/tests/reg_test_4300-dollar_quote_check-t.cpp b/test/tap/tests/reg_test_4300-dollar_quote_check-t.cpp index 9e6828e621..cbef991dc1 100644 --- a/test/tap/tests/reg_test_4300-dollar_quote_check-t.cpp +++ b/test/tap/tests/reg_test_4300-dollar_quote_check-t.cpp @@ -25,6 +25,8 @@ using std::vector; using std::string; +CommandLine cl; + const vector versions { "5.6", "5.7", "8.0", "8.1.0", "8.1", "8.1.4" }; int test_supports_dollar_quote(MYSQL* conn, int v_idx, int v8_1_0_idx) { @@ -86,7 +88,7 @@ int test_versions_mysql(MYSQL* admin, MYSQL* proxy, const vector& versio return EXIT_SUCCESS; } -int test_versions_admin(CommandLine& cl, MYSQL* admin, const vector& versions) { +int test_versions_admin(MYSQL* admin, const vector& versions) { const int64_t v8_1_0_idx { get_elem_idx(string { "8.1.0" }, versions) }; assert(v8_1_0_idx != -1 && "Invalid test payload, no '8.1.0' present in tested versions"); @@ -114,15 +116,9 @@ int test_versions_admin(CommandLine& cl, MYSQL* admin, const vector& ver } int main(int argc, char** argv) { - CommandLine cl; plan((versions.size()*2 + 1)*2); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - MYSQL* proxy = mysql_init(NULL); MYSQL* admin = mysql_init(NULL); @@ -139,7 +135,7 @@ int main(int argc, char** argv) { int rc = test_versions_mysql(admin, proxy, versions); ok(rc == EXIT_SUCCESS, "Multiple 'mysql-server_version' tested correctly against MySQL interface"); - rc = test_versions_admin(cl, admin, versions); + rc = test_versions_admin(admin, versions); ok(rc == EXIT_SUCCESS, "Multiple 'mysql-server_version' tested correctly against Admin interface"); mysql_close(proxy); diff --git a/test/tap/tests/reg_test_compression_split_packets-t.cpp b/test/tap/tests/reg_test_compression_split_packets-t.cpp index 085b6e1a17..ea7cc9170a 100644 --- a/test/tap/tests/reg_test_compression_split_packets-t.cpp +++ b/test/tap/tests/reg_test_compression_split_packets-t.cpp @@ -24,6 +24,8 @@ using std::string; using std::vector; using std::size_t; +CommandLine cl; + /** * @brief Generate random string of only letters of the supplied size, we do this to ensure no-escaped sequences. * @param size Target size of the string to generate. @@ -58,9 +60,7 @@ int mysql_query_p(MYSQL* mysql, const char* query) { } \ } while(0) -int test_compress_split_packets( - const CommandLine& cl, const vector test_payload_sizes, int last_insert_id = 0 -) { +int test_compress_split_packets(const vector test_payload_sizes, int last_insert_id = 0) { diag("Create new conn to ProxySQL and ensure new backend conn is used for serving this queries"); MYSQL* proxy = mysql_init(NULL); @@ -193,16 +193,10 @@ const vector test_payload_sizes { }; int main(int argc, char** argv) { - CommandLine cl; // '4' tests per payload, times '2' due to compression/non-compression on backend servers plan(test_payload_sizes.size() * 4 * 2 + 2); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - MYSQL* admin = mysql_init(NULL); if (!mysql_real_connect(admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(admin)); @@ -232,7 +226,7 @@ int main(int argc, char** argv) { MYSQL_QUERY_P(admin, "LOAD MYSQL SERVERS TO RUNTIME"); diag("TEST: Check compressed split packets through ProxySQL with backend conns with 'compression=0'"); - int last_insert_id = test_compress_split_packets(cl, test_payload_sizes); + int last_insert_id = test_compress_split_packets(test_payload_sizes); if (last_insert_id != test_payload_sizes.size()) { diag("Failed tests for 'compression=0' aborting further testing"); goto cleanup; @@ -243,7 +237,7 @@ int main(int argc, char** argv) { MYSQL_QUERY_P(admin, "LOAD MYSQL SERVERS TO RUNTIME"); diag("TEST: Check compressed split packets through ProxySQL with backend conns with 'compression=1'"); - test_compress_split_packets(cl, test_payload_sizes, last_insert_id); + test_compress_split_packets(test_payload_sizes, last_insert_id); cleanup: mysql_close(admin); diff --git a/test/tap/tests/reg_test_fast_forward_split_packet-t.cpp b/test/tap/tests/reg_test_fast_forward_split_packet-t.cpp index 626545055b..41fc941c66 100644 --- a/test/tap/tests/reg_test_fast_forward_split_packet-t.cpp +++ b/test/tap/tests/reg_test_fast_forward_split_packet-t.cpp @@ -24,17 +24,13 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + const int NUM_CONNS = 35; MYSQL* conns[NUM_CONNS]; int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } // One query that should succeed per-connection plan(NUM_CONNS); diff --git a/test/tap/tests/reg_test_mariadb_stmt_store_result-t.cpp b/test/tap/tests/reg_test_mariadb_stmt_store_result-t.cpp index 292f98f137..1c476d5e17 100644 --- a/test/tap/tests/reg_test_mariadb_stmt_store_result-t.cpp +++ b/test/tap/tests/reg_test_mariadb_stmt_store_result-t.cpp @@ -19,6 +19,8 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + #ifndef LIBMYSQL_HELPER /* Helper function to do the waiting for events on the socket. */ static int wait_for_mysql(MYSQL *mysql, int status) { @@ -124,7 +126,6 @@ using std::string; const int TWO_EXECUTIONS = 2; int main(int argc, char** argv) { - CommandLine cl; plan(1 + TWO_EXECUTIONS*2); // 1 prepare + executions * 2 (execute + store) bool use_async = false; @@ -133,11 +134,6 @@ int main(int argc, char** argv) { use_async = true; } - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - MYSQL* mysql = mysql_init(NULL); if (!mysql) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); diff --git a/test/tap/tests/reg_test_sql_calc_found_rows-t.cpp b/test/tap/tests/reg_test_sql_calc_found_rows-t.cpp index 674a1f9b74..75cb644540 100644 --- a/test/tap/tests/reg_test_sql_calc_found_rows-t.cpp +++ b/test/tap/tests/reg_test_sql_calc_found_rows-t.cpp @@ -27,6 +27,8 @@ using std::pair; using nlohmann::json; +CommandLine cl; + int get_stmt_result(MYSQL_STMT* stmt, int64_t& out_data) { MYSQL_BIND bind[1]; int64_t data_c; @@ -56,12 +58,6 @@ int get_stmt_result(MYSQL_STMT* stmt, int64_t& out_data) { } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } plan(6); diff --git a/test/tap/tests/reg_test_stmt_resultset_err_no_rows-t.cpp b/test/tap/tests/reg_test_stmt_resultset_err_no_rows-t.cpp index f02fc7fd95..d86368f93d 100644 --- a/test/tap/tests/reg_test_stmt_resultset_err_no_rows-t.cpp +++ b/test/tap/tests/reg_test_stmt_resultset_err_no_rows-t.cpp @@ -28,6 +28,8 @@ using std::string; using std::vector; using std::tuple; +CommandLine cl; + using test_case_t = tuple; const uint32_t STRING_SIZE = 1024; @@ -40,13 +42,6 @@ int main(int argc, char** argv) { plan(TEST_CASES.size()); - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - MYSQL* proxy = mysql_init(NULL); MYSQL* admin = mysql_init(NULL); diff --git a/test/tap/tests/reg_test_stmt_resultset_err_no_rows_php-t.cpp b/test/tap/tests/reg_test_stmt_resultset_err_no_rows_php-t.cpp index bd7a0cf19d..f7537ab246 100644 --- a/test/tap/tests/reg_test_stmt_resultset_err_no_rows_php-t.cpp +++ b/test/tap/tests/reg_test_stmt_resultset_err_no_rows_php-t.cpp @@ -16,6 +16,8 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + using std::string; int main(int argc, char** argv) { @@ -23,11 +25,6 @@ int main(int argc, char** argv) { CommandLine cl {}; - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - string php_stdout {}; string php_stderr {}; const string php_path { string{ cl.workdir } + "./reg_test_stmt_resultset_err_no_rows.php" }; diff --git a/test/tap/tests/repro_3404-mysql_close_fd_leak.cpp b/test/tap/tests/repro_3404-mysql_close_fd_leak.cpp index 5e0ec91332..03d2bae587 100644 --- a/test/tap/tests/repro_3404-mysql_close_fd_leak.cpp +++ b/test/tap/tests/repro_3404-mysql_close_fd_leak.cpp @@ -63,6 +63,7 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; /* Helper function to do the waiting for events on the socket. */ static int wait_for_mysql(MYSQL *mysql, int status) { @@ -93,12 +94,6 @@ static int wait_for_mysql(MYSQL *mysql, int status) { } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } bool create_leak = false; diff --git a/test/tap/tests/repro_test_leak_3350.cpp b/test/tap/tests/repro_test_leak_3350.cpp index bc0644f6e2..fde27b3151 100644 --- a/test/tap/tests/repro_test_leak_3350.cpp +++ b/test/tap/tests/repro_test_leak_3350.cpp @@ -18,18 +18,14 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + const int NUM_EXECUTIONS = 10000; int main(int argc, char** argv) { - CommandLine cl; plan(NUM_EXECUTIONS); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - MYSQL* mysql = mysql_init(NULL); if (!mysql) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); diff --git a/test/tap/tests/repro_test_leak_3525.cpp b/test/tap/tests/repro_test_leak_3525.cpp index c4b50932cd..b7c53a2d38 100644 --- a/test/tap/tests/repro_test_leak_3525.cpp +++ b/test/tap/tests/repro_test_leak_3525.cpp @@ -13,11 +13,9 @@ #include "command_line.h" #include "utils.h" -int main(int argc, char** argv) { - CommandLine cl; +CommandLine cl; - if(cl.getEnv()) - return exit_status(); +int main(int argc, char** argv) { plan(1); diff --git a/test/tap/tests/savepoint-3749-t.cpp b/test/tap/tests/savepoint-3749-t.cpp index e8202d900d..75aab754c2 100644 --- a/test/tap/tests/savepoint-3749-t.cpp +++ b/test/tap/tests/savepoint-3749-t.cpp @@ -20,6 +20,32 @@ #include "command_line.h" +CommandLine cl; + +bool debug_diag = true; +unsigned int num_threads = 5; +int count = 10; +char *schema = (char *)"information_schema"; +int silent = 0; +int sysbench = 0; +int transactions = 200; +int uniquequeries = 0; +int histograms = -1; + +unsigned int g_passed = 0; +unsigned int g_failed = 0; + +std::atomic cnt_transactions; +std::atomic cnt_SELECT_outside_transactions; +std::atomic cnt_expected_errors; + +unsigned int status_connections = 0; +unsigned int connect_phase_completed = 0; +unsigned int query_phase_completed = 0; + +__thread int g_seed; +std::mutex mtx_; + unsigned long long monotonic_time() { struct timespec ts; //clock_gettime(CLOCK_MONOTONIC_COARSE, &ts); // this is faster, but not precise @@ -36,55 +62,26 @@ struct cpu_timer { unsigned long long end = monotonic_time(); std::cerr << double( end - begin ) / 1000000 << " secs.\n" ; - begin=end-begin; + begin = end-begin; }; unsigned long long begin; }; -bool debug_diag = true; -unsigned int num_threads=5; -int count=10; -char *username=NULL; -char *password=NULL; -char *host=(char *)"localhost"; -int port=3306; -char *schema=(char *)"information_schema"; -int silent = 0; -int sysbench = 0; -int local=0; -int transactions=200; -int uniquequeries=0; -int histograms=-1; - -unsigned int g_passed=0; -unsigned int g_failed=0; - -std::atomic cnt_transactions; -std::atomic cnt_SELECT_outside_transactions; -std::atomic cnt_expected_errors; - -unsigned int status_connections = 0; -unsigned int connect_phase_completed = 0; -unsigned int query_phase_completed = 0; - -__thread int g_seed; -std::mutex mtx_; - inline int fastrand() { g_seed = (214013*g_seed+2531011); return (g_seed>>16)&0x7FFF; } void gen_random(char *s, const int len) { - static const char alphanum[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz"; + static const char alphanum[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz"; - for (int i = 0; i < len; ++i) { - s[i] = alphanum[fastrand() % (sizeof(alphanum) - 1)]; - } + for (int i = 0; i < len; ++i) { + s[i] = alphanum[fastrand() % (sizeof(alphanum) - 1)]; + } - s[len] = 0; + s[len] = 0; } void * my_conn_thread(void *arg) { @@ -100,18 +97,22 @@ void * my_conn_thread(void *arg) { for (i=0; inet.compress, "Compression: (%d)", mysql->net.compress); } + mysqlconns[i]=mysql; __sync_add_and_fetch(&status_connections,1); } @@ -366,29 +367,23 @@ int main(int argc, char *argv[]) { cnt_transactions = 0; cnt_SELECT_outside_transactions = 0; cnt_expected_errors = 0; - CommandLine cl; - - if(cl.getEnv()) - return exit_status(); - - username = cl.username; - password = cl.password; - host = cl.host; - port = cl.port; { - MYSQL *mysql=mysql_init(NULL); - - if (mysql==NULL) { - exit(EXIT_FAILURE); - } - MYSQL *rc=mysql_real_connect(mysql, host, username, password, schema, (local ? 0 : port) , NULL, 0); - if (rc==NULL) { - if (silent==0) { - fprintf(stderr,"%s\n", mysql_error(mysql)); - } + MYSQL* mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); exit(EXIT_FAILURE); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } + MYSQL_QUERY(mysql, "CREATE DATABASE IF NOT EXISTS test"); MYSQL_QUERY(mysql, "CREATE TABLE IF NOT EXISTS test.test_savepoint(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=INNODB"); MYSQL_QUERY(mysql, "DELETE FROM test.test_savepoint"); @@ -396,15 +391,22 @@ int main(int argc, char *argv[]) { mysql_close(mysql); } - MYSQL* mysqladmin = mysql_init(NULL); - if (!mysqladmin) - return exit_status(); - if (!mysql_real_connect(mysqladmin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysqladmin)); + MYSQL* mysqladmin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysqladmin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysqladmin, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(mysqladmin, cl.admin_host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysqladmin)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysqladmin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysqladmin->net.compress, "Compression: (%d)", mysqladmin->net.compress); } + MYSQL_QUERY(mysqladmin, "update global_variables set variable_value='false' where variable_name='mysql-enforce_autocommit_on_reads'"); MYSQL_QUERY(mysqladmin, "LOAD MYSQL VARIABLES TO RUNTIME"); MYSQL_QUERY(mysqladmin, "DROP TABLE IF EXISTS mysql_query_rules_948"); @@ -440,7 +442,7 @@ int main(int argc, char *argv[]) { //count = 10; // plan(transactions * num_threads + 1); // this was too verbose - plan(1); + plan(2+2+2*num_threads*count + 1); if (debug_diag==true) { diag("Running test with debug enabled. Set debug_diag=false for less verbosity"); @@ -448,9 +450,6 @@ int main(int argc, char *argv[]) { diag("Running test with debug disabled. Set debug_diag=true for more verbosity"); } - if (strcmp(host,"localhost")==0) { - local = 1; - } pthread_t *thi=(pthread_t *)malloc(sizeof(pthread_t)*num_threads); if (thi==NULL) return exit_status(); diff --git a/test/tap/tests/savepoint-948-t.cpp b/test/tap/tests/savepoint-948-t.cpp index a174ed2fc2..196b3e35b7 100644 --- a/test/tap/tests/savepoint-948-t.cpp +++ b/test/tap/tests/savepoint-948-t.cpp @@ -23,28 +23,25 @@ using nlohmann::json; +CommandLine cl; + bool debug_diag=true; -unsigned int num_threads=4; -int count=10; -int transactions=200; +unsigned int num_threads = 4; +int count = 10; +int transactions = 200; /* -unsigned int num_threads=1; -int count=1; -int transactions=5; +unsigned int num_threads = 1; +int count = 1; +int transactions = 5; */ -char *username=NULL; -char *password=NULL; -char *host=(char *)"localhost"; -int port=3306; -char *schema=(char *)"information_schema"; +char *schema = (char *)"information_schema"; int silent = 0; int sysbench = 0; -int local=0; -int uniquequeries=0; -int histograms=-1; +int uniquequeries = 0; +int histograms = -1; -unsigned int g_passed=0; -unsigned int g_failed=0; +unsigned int g_passed = 0; +unsigned int g_failed = 0; std::atomic cnt_transactions; std::atomic cnt_SELECT_outside_transactions; @@ -62,15 +59,15 @@ inline int fastrand() { } void gen_random(char *s, const int len) { - static const char alphanum[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz"; + static const char alphanum[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz"; - for (int i = 0; i < len; ++i) { - s[i] = alphanum[fastrand() % (sizeof(alphanum) - 1)]; - } + for (int i = 0; i < len; ++i) { + s[i] = alphanum[fastrand() % (sizeof(alphanum) - 1)]; + } - s[len] = 0; + s[len] = 0; } void * my_conn_thread(void *arg) { @@ -87,18 +84,22 @@ void * my_conn_thread(void *arg) { for (i=0; inet.compress, "Compression: (%d)", mysql->net.compress); } + mysqlconns[i]=mysql; __sync_add_and_fetch(&status_connections,1); ac[i]=true; @@ -336,29 +337,23 @@ void print_global_status(MYSQL *mysqladmin) { int main(int argc, char *argv[]) { cnt_transactions = 0; cnt_SELECT_outside_transactions = 0; - CommandLine cl; - - if(cl.getEnv()) - return exit_status(); - - username = cl.username; - password = cl.password; - host = cl.host; - port = cl.port; { - MYSQL *mysql=mysql_init(NULL); - - if (mysql==NULL) { - exit(EXIT_FAILURE); - } - MYSQL *rc=mysql_real_connect(mysql, host, username, password, schema, (local ? 0 : port) , NULL, 0); - if (rc==NULL) { - if (silent==0) { - fprintf(stderr,"%s\n", mysql_error(mysql)); - } + MYSQL* mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); exit(EXIT_FAILURE); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } + MYSQL_QUERY(mysql, "CREATE DATABASE IF NOT EXISTS test"); MYSQL_QUERY(mysql, "CREATE TABLE IF NOT EXISTS test.test_savepoint(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=INNODB"); MYSQL_QUERY(mysql, "DELETE FROM test.test_savepoint"); @@ -366,15 +361,22 @@ int main(int argc, char *argv[]) { mysql_close(mysql); } - MYSQL* mysqladmin = mysql_init(NULL); - if (!mysqladmin) - return exit_status(); + MYSQL* mysqladmin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysqladmin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysqladmin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysqladmin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysqladmin)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysqladmin)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysqladmin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysqladmin->net.compress, "Compression: (%d)", mysqladmin->net.compress); } + MYSQL_QUERY(mysqladmin, "update global_variables set variable_value='false' where variable_name='mysql-enforce_autocommit_on_reads'"); MYSQL_QUERY(mysqladmin, "LOAD MYSQL VARIABLES TO RUNTIME"); MYSQL_QUERY(mysqladmin, "DROP TABLE IF EXISTS mysql_query_rules_948"); @@ -407,7 +409,7 @@ int main(int argc, char *argv[]) { print_commands_stats(mysqladmin); // plan(transactions * num_threads + 1); // this was too verbose - plan(1); + plan(2+2+2*num_threads*count + 1); if (debug_diag==true) { diag("Running test with debug enabled. Set debug_diag=false for less verbosity"); @@ -415,9 +417,6 @@ int main(int argc, char *argv[]) { diag("Running test with debug disabled. Set debug_diag=true for more verbosity"); } - if (strcmp(host,"localhost")==0) { - local = 1; - } pthread_t *thi=(pthread_t *)malloc(sizeof(pthread_t)*num_threads); if (thi==NULL) return exit_status(); diff --git a/test/tap/tests/set_character_set-t.cpp b/test/tap/tests/set_character_set-t.cpp index f208e532f9..e0788f1968 100644 --- a/test/tap/tests/set_character_set-t.cpp +++ b/test/tap/tests/set_character_set-t.cpp @@ -42,52 +42,46 @@ #include "command_line.h" #include "utils.h" -int main(int argc, char** argv) { - CommandLine cl; +CommandLine cl; - if(cl.getEnv()) - return exit_status(); +int main(int argc, char** argv) { - plan(11); + plan(2 + 11); diag("Testing SET CHARACTER SET"); MYSQL* mysql = mysql_init(NULL); - if (!mysql) - return exit_status(); - - if (mysql_options(mysql, MYSQL_SET_CHARSET_NAME, "utf8")) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysql)); - return exit_status(); - } - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + mysql_options(mysql, MYSQL_SET_CHARSET_NAME, "utf8"); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - fprintf(stderr, "Failed to connect to database: Error: %s\n", - mysql_error(mysql)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } if (mysql_query(mysql, "drop database if exists test")) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysql)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); return exit_status(); } if (mysql_query(mysql, "create database test charset utf8")) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysql)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); return exit_status(); } if (mysql_query(mysql, "use test")) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysql)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); return exit_status(); } if (mysql_query(mysql, "set names 'utf8'")) { - fprintf(stderr, "SET NAMES 'utf8': Error: %s\n", - mysql_error(mysql)); + fprintf(stderr, "SET NAMES 'utf8': Error: %s\n", mysql_error(mysql)); return exit_status(); } @@ -110,8 +104,7 @@ int main(int argc, char** argv) { ok(var_value.compare("utf8") == 0, "Initial database character set. Actual %s", var_value.c_str()); // ok_4 if (mysql_query(mysql, "set character set latin1")) { - fprintf(stderr, "SET CHARACTER SET : Error: %s\n", - mysql_error(mysql)); + fprintf(stderr, "SET CHARACTER SET : Error: %s\n", mysql_error(mysql)); return exit_status(); } @@ -136,8 +129,7 @@ int main(int argc, char** argv) { ok(var_value.compare("latin1") == 0, "Results character set is changed. Actual %s", var_value.c_str()); // ok_7 if (mysql_query(mysql, "set names latin1")) { - fprintf(stderr, "SET NAMES : Error: %s\n", - mysql_error(mysql)); + fprintf(stderr, "SET NAMES : Error: %s\n", mysql_error(mysql)); return exit_status(); } diff --git a/test/tap/tests/set_testing-240-t.cpp b/test/tap/tests/set_testing-240-t.cpp index cacf8c0052..1a6d4e7670 100644 --- a/test/tap/tests/set_testing-240-t.cpp +++ b/test/tap/tests/set_testing-240-t.cpp @@ -34,33 +34,33 @@ CommandLine cl; -int queries_per_connections=10; -//unsigned int num_threads=1; -//unsigned int num_threads=5; -unsigned int num_threads=20; -int count=20; +int queries_per_connections = 10; +//unsigned int num_threads = 1; +//unsigned int num_threads = 5; +unsigned int num_threads = 20; +int count = 20; int total_conn_having_client_deprecate_eof_support = (count * 0.2); // 20% of connections will have CLIENT_DEPRECATE_EOF flag enabled -char *username=NULL; -char *password=NULL; -char *host=(char *)"localhost"; -int port=3306; -int multiport=1; -char *schema=(char *)"information_schema"; +//char *username = NULL; +//char *password = NULL; +//char *host = (char *)"localhost"; +//int port = 3306; +int multiport = 1; +char *schema = (char *)"information_schema"; int silent = 0; int sysbench = 0; -int local=0; -int queries=3000; -int uniquequeries=0; -int histograms=-1; +int local = 0; +int queries = 3000; +int uniquequeries = 0; +int histograms = -1; bool is_mariadb = false; -unsigned int g_connect_OK=0; -unsigned int g_connect_ERR=0; -unsigned int g_select_OK=0; -unsigned int g_select_ERR=0; +unsigned int g_connect_OK = 0; +unsigned int g_connect_ERR = 0; +unsigned int g_select_OK = 0; +unsigned int g_select_ERR = 0; -unsigned int g_passed=0; -unsigned int g_failed=0; +unsigned int g_passed = 0; +unsigned int g_failed = 0; unsigned int status_connections = 0; unsigned int connect_phase_completed = 0; @@ -131,27 +131,30 @@ void * my_conn_thread(void *arg) { std::vector cs = {"latin1", "utf8", "utf8mb4", "latin2", "latin7"}; for (i=0; ioptions.client_flag |= CLIENT_DEPRECATE_EOF; } + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); int port = local ? 0 : ( cl.port + rand()%multiport ); - MYSQL *rc=mysql_real_connect(mysql, cl.host, cl.username, cl.password, schema, port, NULL, 0); - - if (rc==NULL) { - if (silent==0) { - fprintf(stderr,"Error while connecting on %s:%d : %s\n", cl.host , port , mysql_error(mysql)); - } - return NULL; + if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, schema, port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); + exit(EXIT_FAILURE); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } + mysqlconns[i]=mysql; set_sql_mode[i]=false; __sync_add_and_fetch(&status_connections,1); @@ -160,7 +163,7 @@ void * my_conn_thread(void *arg) { while(__sync_fetch_and_add(&connect_phase_completed,0) != num_threads) { } - MYSQL *mysql=NULL; + MYSQL *mysql = NULL; int mysql_idx = 0; json vars; std::string paddress = ""; @@ -175,7 +178,7 @@ void * my_conn_thread(void *arg) { mysql=mysqlconns[mysql_idx]; vars = varsperconn[mysql_idx]; } - if (strcmp(username,(char *)"root")) { + if (strcmp(cl.username,(char *)"root")) { if (strstr(testCases[r2].command.c_str(),"database")) { std::lock_guard lock(mtx_); skip(1, "connections mysql[%p] proxysql[%s], command [%s]", mysql, paddress.c_str(), testCases[r2].command.c_str()); @@ -467,11 +470,6 @@ void * my_conn_thread(void *arg) { int main(int argc, char *argv[]) { - if(cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return exit_status(); - } - std::string fileName2(std::string(cl.workdir) + "/set_testing-240.csv"); /* @@ -479,11 +477,11 @@ int main(int argc, char *argv[]) { queries_per_connections = 10; count = 10; */ - username = cl.username; - password = cl.password; - host = cl.host; +// username = cl.username; +// password = cl.password; +// host = cl.host; // host = "127.0.0.1"; - port = cl.port; +// port = cl.port; // port = 6033; diag("Loading test cases from file. This will take some time..."); @@ -493,10 +491,18 @@ int main(int argc, char *argv[]) { } MYSQL* proxysql_admin = mysql_init(NULL); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.admin_host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } /* admin-hash_passwords has been deprecated @@ -523,6 +529,7 @@ int main(int argc, char *argv[]) { unsigned int p = queries * num_threads; p *= 2; // number of algorithms p *= rows_res.size(); // number of host groups + p += 2 + 2*num_threads*count*2; // number of connections (2 algorithms) plan(p); for (const auto& act_row : rows_res) { @@ -541,20 +548,14 @@ int main(int argc, char *argv[]) { MYSQL_QUERY(proxysql_admin, update.c_str()); MYSQL_QUERY(proxysql_admin, "LOAD MYSQL QUERY RULES TO RUNTIME"); - if (detect_version(cl, is_mariadb) != 0) { + if (detect_version(is_mariadb) != 0) { diag("Cannot detect MySQL version"); return exit_status(); } - if (strcmp(host,"localhost")==0) { - local = 1; - } - if (uniquequeries == 0) { - if (queries) uniquequeries=queries; - } - if (uniquequeries) { - uniquequeries=(int)sqrt(uniquequeries); - } +// if (strcmp(cl.host, "localhost")==0) { +// local = 1; +// } for (int algo = 1; algo <= 2; algo++ ) { connect_phase_completed = 0; diff --git a/test/tap/tests/set_testing-240.h b/test/tap/tests/set_testing-240.h index 60254da37e..9ad3848763 100644 --- a/test/tap/tests/set_testing-240.h +++ b/test/tap/tests/set_testing-240.h @@ -479,7 +479,7 @@ bool check_session_track_gtids(const std::string& expVal, const std::string& sVa return res; } -int detect_version(CommandLine& cl, bool& is_mariadb) { +int detect_version(bool& is_mariadb) { MYSQL* mysql = mysql_init(NULL); if (!mysql) return 1; diff --git a/test/tap/tests/set_testing-multi-t.cpp b/test/tap/tests/set_testing-multi-t.cpp index 1f85d6a95b..c1905801be 100644 --- a/test/tap/tests/set_testing-multi-t.cpp +++ b/test/tap/tests/set_testing-multi-t.cpp @@ -21,33 +21,36 @@ #include "utils.h" #include "command_line.h" + +CommandLine cl; + std::string bn = ""; -int queries_per_connections=1; -unsigned int num_threads=1; +int queries_per_connections = 1; +unsigned int num_threads = 1; int count=0; -char *username=NULL; -char *password=NULL; -char *host=(char *)"localhost"; -int port=3306; -int multiport=1; -char *schema=(char *)"information_schema"; +//char *username = NULL; +//char *password = NULL; +//char *host = (char *)"localhost"; +//int port = 3306; +int multiport = 1; +char *schema = (char *)"information_schema"; int silent = 0; int sysbench = 0; -int local=0; -int queries=0; -int uniquequeries=0; -int histograms=-1; -int multi_users=0; +//int local = 0; +int queries = 0; +int uniquequeries = 0; +int histograms = -1; +int multi_users = 0; bool is_mariadb = false; bool is_cluster = false; -unsigned int g_connect_OK=0; -unsigned int g_connect_ERR=0; -unsigned int g_select_OK=0; -unsigned int g_select_ERR=0; +unsigned int g_connect_OK = 0; +unsigned int g_connect_ERR = 0; +unsigned int g_select_OK = 0; +unsigned int g_select_ERR = 0; -unsigned int g_passed=0; -unsigned int g_failed=0; +unsigned int g_passed = 0; +unsigned int g_failed = 0; unsigned int status_connections = 0; unsigned int connect_phase_completed = 0; @@ -61,8 +64,8 @@ std::vector forgotten_vars {}; void * my_conn_thread(void *arg) { g_seed = time(NULL) ^ getpid() ^ pthread_self(); - unsigned int select_OK=0; - unsigned int select_ERR=0; + unsigned int select_OK = 0; + unsigned int select_ERR = 0; int i, j; MYSQL **mysqlconns=(MYSQL **)malloc(sizeof(MYSQL *)*count); std::vector varsperconn(count); @@ -74,37 +77,43 @@ void * my_conn_thread(void *arg) { std::vector cs = {"latin1", "utf8", "utf8mb4", "latin2", "latin7"}; for (i=0; inet.compress, "Compression: (%d)", mysql->net.compress); } - mysqlconns[i]=mysql; + + mysqlconns[i] = mysql; __sync_add_and_fetch(&status_connections,1); } __sync_fetch_and_add(&connect_phase_completed,1); while(__sync_fetch_and_add(&connect_phase_completed,0) != num_threads) { } - MYSQL *mysql=NULL; + MYSQL *mysql = NULL; json vars; std::string paddress = ""; for (j=0; j lock(mtx_); skip(1, "mysql connection [%p], command [%s]", mysql, testCases[r2].command.c_str()); @@ -297,10 +306,6 @@ void * my_conn_thread(void *arg) { int main(int argc, char *argv[]) { - CommandLine cl; - - if(cl.getEnv()) - return exit_status(); { bn = basename(argv[0]); @@ -314,13 +319,18 @@ int main(int argc, char *argv[]) { std::string fileName(std::string(cl.workdir) + "/set_testing-t.csv"); MYSQL* mysqladmin = mysql_init(NULL); - if (!mysqladmin) - return exit_status(); - - if (!mysql_real_connect(mysqladmin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysqladmin)); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysqladmin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysqladmin, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(mysqladmin, cl.admin_host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysqladmin)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysqladmin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysqladmin->net.compress, "Compression: (%d)", mysqladmin->net.compress); } /* MYSQL_QUERY(mysqladmin, "update global_variables set variable_value='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' where variable_name='mysql-default_sql_mode'"); @@ -350,7 +360,7 @@ int main(int argc, char *argv[]) { MYSQL_QUERY(mysqladmin, q.c_str()); } - if (detect_version(cl, is_mariadb, is_cluster) != 0) { + if (detect_version(is_mariadb, is_cluster) != 0) { diag("Cannot detect MySQL version"); return exit_status(); } @@ -361,20 +371,24 @@ int main(int argc, char *argv[]) { queries = 1000; queries_per_connections = 10; count = 10; - username = cl.username; - password = cl.password; - host = cl.host; - port = cl.port; +// username = cl.username; +// password = cl.password; +// host = cl.host; +// port = cl.port; + + int p = 2; // admin connection + p += 2 * queries / queries_per_connections; // user connections + p += queries * num_threads; // tests + plan(p); - plan(queries * num_threads); if (!readTestCases(fileName)) { fprintf(stderr, "Cannot read %s\n", fileName.c_str()); return exit_status(); } - if (strcmp(host,"localhost")==0) { - local = 1; - } +// if (strcmp(host,"localhost")==0) { +// local = 1; +// } if (uniquequeries == 0) { if (queries) uniquequeries=queries; } diff --git a/test/tap/tests/set_testing-t.cpp b/test/tap/tests/set_testing-t.cpp index 0604669075..9a4a93c122 100644 --- a/test/tap/tests/set_testing-t.cpp +++ b/test/tap/tests/set_testing-t.cpp @@ -33,32 +33,33 @@ #include "command_line.h" - -int queries_per_connections=1; -unsigned int num_threads=1; -int count=0; -char *username=NULL; -char *password=NULL; -char *host=(char *)"localhost"; -int port=3306; -int multiport=1; -char *schema=(char *)"information_schema"; +CommandLine cl; + +int queries_per_connections = 1; +unsigned int num_threads = 1; +int count= 0 ; +//char *username = NULL; +//char *password = NULL; +//char *host = (char *)"localhost"; +//int port = 3306; +int multiport = 1; +char *schema = (char *)"information_schema"; int silent = 0; int sysbench = 0; -int local=0; -int queries=0; -int uniquequeries=0; -int histograms=-1; +//int local = 0; +int queries = 0; +int uniquequeries = 0; +int histograms = -1; bool is_mariadb = false; bool is_cluster = false; -unsigned int g_connect_OK=0; -unsigned int g_connect_ERR=0; -unsigned int g_select_OK=0; -unsigned int g_select_ERR=0; +unsigned int g_connect_OK = 0; +unsigned int g_connect_ERR = 0; +unsigned int g_select_OK = 0; +unsigned int g_select_ERR = 0; -unsigned int g_passed=0; -unsigned int g_failed=0; +unsigned int g_passed = 0; +unsigned int g_failed = 0; unsigned int status_connections = 0; unsigned int connect_phase_completed = 0; @@ -79,54 +80,59 @@ std::vector forgotten_vars {}; void * my_conn_thread(void *arg) { g_seed = time(NULL) ^ getpid() ^ pthread_self(); - unsigned int select_OK=0; - unsigned int select_ERR=0; + unsigned int select_OK = 0; + unsigned int select_ERR = 0; int i, j; MYSQL **mysqlconns=(MYSQL **)malloc(sizeof(MYSQL *)*count); std::vector varsperconn(count); - if (mysqlconns==NULL) { + if (mysqlconns == NULL) { exit(EXIT_FAILURE); } std::vector cs = {"latin1", "utf8", "utf8mb4", "latin2", "latin7"}; for (i=0; inet.compress, "Compression: (%d)", mysql->net.compress); } - mysqlconns[i]=mysql; - __sync_add_and_fetch(&status_connections,1); - } - __sync_fetch_and_add(&connect_phase_completed,1); - while(__sync_fetch_and_add(&connect_phase_completed,0) != num_threads) { + mysqlconns[i] = mysql; + __sync_add_and_fetch(&status_connections, 1); } - MYSQL *mysql=NULL; + + __sync_fetch_and_add(&connect_phase_completed, 1); + while(__sync_fetch_and_add(&connect_phase_completed, 0) != num_threads) {} + + MYSQL *mysql = NULL; json vars; std::string paddress = ""; for (j=0; j lock(mtx_); skip(1, "connections mysql[%p] proxysql[%s], command [%s]", mysql, paddress.c_str(), testCases[r2].command.c_str()); @@ -149,7 +155,7 @@ void * my_conn_thread(void *arg) { MYSQL_RES *result = mysql_store_result(mysql); mysql_free_result(result); select_OK++; - __sync_fetch_and_add(&g_select_OK,1); + __sync_fetch_and_add(&g_select_OK, 1); } } @@ -200,12 +206,12 @@ void * my_conn_thread(void *arg) { sprintf(query, "SELECT /* %p %s */ %d;", mysql, paddress.c_str(), sleepDelay); if (mysql_query(mysql,query)) { select_ERR++; - __sync_fetch_and_add(&g_select_ERR,1); + __sync_fetch_and_add(&g_select_ERR, 1); } else { MYSQL_RES *result = mysql_store_result(mysql); mysql_free_result(result); select_OK++; - __sync_fetch_and_add(&g_select_OK,1); + __sync_fetch_and_add(&g_select_OK, 1); } json mysql_vars; @@ -343,7 +349,7 @@ void * my_conn_thread(void *arg) { ok(testPassed, "connections mysql[%p] proxysql[%s], thread_id [%lu], variables_tested [%d], command [%s]", mysql, paddress.c_str(), mysql->thread_id, variables_tested, testCases[r2].command.c_str()); } } - __sync_fetch_and_add(&query_phase_completed,1); + __sync_fetch_and_add(&query_phase_completed, 1); return NULL; } @@ -351,17 +357,10 @@ void * my_conn_thread(void *arg) { int main(int argc, char *argv[]) { - CommandLine cl; - - if(cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return exit_status(); - } std::string fileName(std::string(cl.workdir) + "/set_testing-t.csv"); - - if (detect_version(cl, is_mariadb, is_cluster) != 0) { + if (detect_version(is_mariadb, is_cluster) != 0) { diag("Cannot detect MySQL version"); return exit_status(); } @@ -369,10 +368,10 @@ int main(int argc, char *argv[]) { num_threads = 10; queries_per_connections = 10; count = 10; - username = cl.username; - password = cl.password; - host = cl.host; - port = cl.port; +// username = cl.username; +// password = cl.password; +// host = cl.host; +// port = cl.port; if (!readTestCases(fileName)) { fprintf(stderr, "Cannot read %s\n", fileName.c_str()); @@ -381,11 +380,11 @@ int main(int argc, char *argv[]) { queries = 300; - plan(queries * num_threads); + plan(2*count*num_threads + queries*num_threads); - if (strcmp(host,"localhost")==0) { - local = 1; - } +// if (strcmp(host,"localhost")==0) { +// local = 1; +// } if (uniquequeries == 0) { if (queries) uniquequeries=queries; } @@ -404,5 +403,6 @@ int main(int argc, char *argv[]) { for (unsigned int i=0; i -int main(int argc, char** argv) { - CommandLine cl; +CommandLine cl; - if(cl.getEnv()) - return exit_status(); +int main(int argc, char** argv) { plan(1); std::string test_bin { std::string { cl.workdir } + "setparser_test" }; diff --git a/test/tap/tests/setparser_test.cpp b/test/tap/tests/setparser_test.cpp index 8bc210ec4a..6ee973f580 100644 --- a/test/tap/tests/setparser_test.cpp +++ b/test/tap/tests/setparser_test.cpp @@ -21,6 +21,10 @@ #include #include +#include "command_line.h" + +CommandLine cl; + // ******************************************************************************************* /** * TODO: This should be fixed once we have improved include hierarchy. All the following diff --git a/test/tap/tests/setparser_test2.cpp b/test/tap/tests/setparser_test2.cpp index 215d8b8d72..61da84be7f 100644 --- a/test/tap/tests/setparser_test2.cpp +++ b/test/tap/tests/setparser_test2.cpp @@ -3,31 +3,34 @@ * @brief Test file for unit testing 'SetParser' type, responsible of parsing * non-trivial 'SET' statements. */ +#include "command_line.h" + +CommandLine cl; #include "setparser_test_common.h" void TestParse(const Test* tests, int ntests, const std::string& title) { - for (int i = 0; i < ntests; i++) { - std::map> data; - for(auto it = std::begin(tests[i].results); it != std::end(tests[i].results); ++it) { - data[it->var] = it->values; - } - - cout << "Processing query: " << tests[i].query << endl; - SetParser parser(tests[i].query); - std::map> result = parser.parse1(); - - cout << endl; - printMap("result", result); - cout << endl; - printMap("expected", data); - cout << endl; - - CHECK_EQ(result.size(), data.size()); - ok(result.size() == data.size() , "Sizes match: %lu, %lu" , result.size() , data.size()); - CHECK(std::equal(std::begin(result), std::end(result), std::begin(data))); - ok(std::equal(std::begin(result), std::end(result), std::begin(data)) == true, "Elements match"); - } + for (int i = 0; i < ntests; i++) { + std::map> data; + for(auto it = std::begin(tests[i].results); it != std::end(tests[i].results); ++it) { + data[it->var] = it->values; + } + + cout << "Processing query: " << tests[i].query << endl; + SetParser parser(tests[i].query); + std::map> result = parser.parse1(); + + cout << endl; + printMap("result", result); + cout << endl; + printMap("expected", data); + cout << endl; + + CHECK_EQ(result.size(), data.size()); + ok(result.size() == data.size() , "Sizes match: %lu, %lu" , result.size() , data.size()); + CHECK(std::equal(std::begin(result), std::end(result), std::begin(data))); + ok(std::equal(std::begin(result), std::end(result), std::begin(data)) == true, "Elements match"); + } } diff --git a/test/tap/tests/setparser_test3.cpp b/test/tap/tests/setparser_test3.cpp index b184b6d0e6..64c96b4425 100644 --- a/test/tap/tests/setparser_test3.cpp +++ b/test/tap/tests/setparser_test3.cpp @@ -3,37 +3,40 @@ * @brief Test file for unit testing 'SetParser' type, responsible of parsing * non-trivial 'SET' statements. */ +#include "command_line.h" + +CommandLine cl; #include "setparser_test_common.h" SetParser *parser = NULL; void TestParse(const Test* tests, int ntests, const std::string& title) { - for (int i = 0; i < ntests; i++) { - std::map> data; - for(auto it = std::begin(tests[i].results); it != std::end(tests[i].results); ++it) { - data[it->var] = it->values; - } + for (int i = 0; i < ntests; i++) { + std::map> data; + for(auto it = std::begin(tests[i].results); it != std::end(tests[i].results); ++it) { + data[it->var] = it->values; + } - //SetParser parser(tests[i].query, 1); - //std::map> result = parser.parse1(); - //std::map> result = parser.parse1v2(); + //SetParser parser(tests[i].query, 1); + //std::map> result = parser.parse1(); + //std::map> result = parser.parse1v2(); - cout << "Processing query: " << tests[i].query << endl; - parser->set_query(tests[i].query); - std::map> result = parser->parse1v2(); + cout << "Processing query: " << tests[i].query << endl; + parser->set_query(tests[i].query); + std::map> result = parser->parse1v2(); - cout << endl; - printMap("result", result); - cout << endl; - printMap("expected", data); - cout << endl; + cout << endl; + printMap("result", result); + cout << endl; + printMap("expected", data); + cout << endl; - CHECK_EQ(result.size(), data.size()); - ok(result.size() == data.size() , "Sizes match: %lu, %lu" , result.size() , data.size()); - CHECK(std::equal(std::begin(result), std::end(result), std::begin(data))); - ok(std::equal(std::begin(result), std::end(result), std::begin(data)) == true, "Elements match"); - } + CHECK_EQ(result.size(), data.size()); + ok(result.size() == data.size() , "Sizes match: %lu, %lu" , result.size() , data.size()); + CHECK(std::equal(std::begin(result), std::end(result), std::begin(data))); + ok(std::equal(std::begin(result), std::end(result), std::begin(data)) == true, "Elements match"); + } } diff --git a/test/tap/tests/setparser_test_common.h b/test/tap/tests/setparser_test_common.h index b7f34ae670..6cf1c38d6e 100644 --- a/test/tap/tests/setparser_test_common.h +++ b/test/tap/tests/setparser_test_common.h @@ -31,236 +31,236 @@ MySQL_LDAP_Authentication *GloMyLdapAuth = nullptr; bool iequals(const std::string& a, const std::string& b) { - unsigned int sz = a.size(); - if (b.size() != sz) - return false; - for (unsigned int i = 0; i < sz; ++i) - if (tolower(a[i]) != tolower(b[i])) - return false; - return true; + unsigned int sz = a.size(); + if (b.size() != sz) + return false; + for (unsigned int i = 0; i < sz; ++i) + if (tolower(a[i]) != tolower(b[i])) + return false; + return true; } void printMap(const std::string query, std::map> map) { std::cout << "Query: " << query << endl; for (const auto& entry : map) { - std::cout << " - Key: " << entry.first << endl; + std::cout << " - Key: " << entry.first << endl; for (const auto& value : entry.second) { - std::cout << " + Value: " << value << endl; + std::cout << " + Value: " << value << endl; } } } struct Expected { - const char* var; - std::vector values; - Expected(const char* var, std::vector values): var(var), values(values){}; + const char* var; + std::vector values; + Expected(const char* var, std::vector values): var(var), values(values){}; }; struct Test { - const char* query; - std::vector results; + const char* query; + std::vector results; }; static Test sql_mode[] = { - { "SET @@sql_mode = 'TRADITIONAL'", { Expected("sql_mode", {"TRADITIONAL"}) } }, - { "SET SESSION sql_mode = 'TRADITIONAL'", { Expected("sql_mode", {"TRADITIONAL"}) } }, - { "SET @@session.sql_mode = 'TRADITIONAL'", { Expected("sql_mode", {"TRADITIONAL"}) } }, - { "SET @@local.sql_mode = 'TRADITIONAL'", { Expected("sql_mode", {"TRADITIONAL"}) } }, - { "SET sql_mode = 'TRADITIONAL'", { Expected("sql_mode", {"TRADITIONAL"}) } }, - { "SET SQL_MODE ='TRADITIONAL'", { Expected("sql_mode", {"TRADITIONAL"}) } }, - { "SET SQL_MODE = \"TRADITIONAL\"", { Expected("sql_mode", {"TRADITIONAL"}) } }, - { "SET SQL_MODE = TRADITIONAL", { Expected("sql_mode", {"TRADITIONAL"}) } }, - { "set sql_mode = IFNULL(NULL,\"STRICT_TRANS_TABLES\")", { Expected("sql_mode", {"IFNULL(NULL,\"STRICT_TRANS_TABLES\")"}) } }, - { "set sql_mode = IFNULL(NULL,'STRICT_TRANS_TABLES')", { Expected("sql_mode", {"IFNULL(NULL,'STRICT_TRANS_TABLES')"}) } }, - { "SET @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ', STRICT_ALL_TABLES'), ', NO_AUTO_VALUE_ON_ZERO')", { Expected("sql_mode", {"CONCAT(CONCAT(@@sql_mode, ', STRICT_ALL_TABLES'), ', NO_AUTO_VALUE_ON_ZERO')"}) } }, - { "SET @@LOCAL.sql_mode = CONCAT(CONCAT(@@sql_mode, ', STRICT_ALL_TABLES'), ', NO_AUTO_VALUE_ON_ZERO')", { Expected("sql_mode", {"CONCAT(CONCAT(@@sql_mode, ', STRICT_ALL_TABLES'), ', NO_AUTO_VALUE_ON_ZERO')"}) } }, - { "set session sql_mode = 'ONLY_FULL_GROUP_BY'" , { Expected("sql_mode", {"ONLY_FULL_GROUP_BY"}) } }, - { "SET sql_mode = 'NO_ZERO_DATE,STRICT_ALL_TABLES,ONLY_FULL_GROUP_BY'" , { Expected("sql_mode", {"NO_ZERO_DATE,STRICT_ALL_TABLES,ONLY_FULL_GROUP_BY"}) } }, - { "SET @@sql_mode = CONCAT(@@sql_mode, ',', 'ONLY_FULL_GROUP_BY')" , { Expected("sql_mode", {"CONCAT(@@sql_mode, ',', 'ONLY_FULL_GROUP_BY')"}) } }, - { "SET @@sql_mode = REPLACE(REPLACE(REPLACE(@@sql_mode, 'ONLY_FULL_GROUP_BY,', ''),',ONLY_FULL_GROUP_BY', ''),'ONLY_FULL_GROUP_BY', '')" , { Expected("sql_mode", {"REPLACE(REPLACE(REPLACE(@@sql_mode, 'ONLY_FULL_GROUP_BY,', ''),',ONLY_FULL_GROUP_BY', ''),'ONLY_FULL_GROUP_BY', '')"}) } }, - { "SET @@sql_mode = REPLACE( REPLACE( REPLACE( @@sql_mode, 'ONLY_FULL_GROUP_BY,', ''),',ONLY_FULL_GROUP_BY', ''),'ONLY_FULL_GROUP_BY', '')" , { Expected("sql_mode", {"REPLACE( REPLACE( REPLACE( @@sql_mode, 'ONLY_FULL_GROUP_BY,', ''),',ONLY_FULL_GROUP_BY', ''),'ONLY_FULL_GROUP_BY', '')"}) } }, -// { "SET @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ', STRICT_ALL_TABLES'), ', NO_AUTO_VALUE_ON_ZERO')", { Expected("sql_mode", {"CONCAT(CONCAT(@@sql_mode, ', STRICT_ALL_TABLES'), ', NO_AUTO_VALUE_ON_ZERO')"}) } }, - { "SET SQL_MODE=IFNULL(@@sql_mode,'')", { Expected("sql_mode", { "IFNULL(@@sql_mode,'')" } ) } }, - { "SET SQL_MODE=IFNULL(@old_sql_mode,'')", { Expected("sql_mode", { "IFNULL(@old_sql_mode,'')" } ) } }, - { "SET SQL_MODE=IFNULL(@OLD_SQL_MODE,'')", { Expected("sql_mode", { "IFNULL(@OLD_SQL_MODE,'')" } ) } }, - // Complex queries involving 'SELECT' and surrounding parenthesis should be parsed properly - { "SET sql_mode=(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION'))", { Expected("sql_mode", { "(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION'))" } ) } }, - { "SET sql_mode=(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION')), time_zone = '+00:00', NAMES utf8mb4 COLLATE utf8mb4_unicode_ci", - { - Expected("sql_mode", { "(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION'))" } ), - Expected("time_zone", { "+00:00" } ), - Expected("names", {"utf8mb4", "utf8mb4_unicode_ci"} ) - } - }, - // Empty set of 'sql_mode' should result into an empty value - { "SET sql_mode=''", { Expected("sql_mode", { "" } ) } }, - // Invalid 'non-matching' versions of 'sql_mode' should result into 'non-matching' - { "SET sql_mode=(SELECT CONCA(@@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION'))", {} }, - { "SET sql_mode=(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT[,NO_ENGINE_SUBSTITUTION'))", {} }, - { "SET sql_mode=(SELCT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT[,NO_ENGINE_SUBSTITUTION'))", {} } + { "SET @@sql_mode = 'TRADITIONAL'", { Expected("sql_mode", {"TRADITIONAL"}) } }, + { "SET SESSION sql_mode = 'TRADITIONAL'", { Expected("sql_mode", {"TRADITIONAL"}) } }, + { "SET @@session.sql_mode = 'TRADITIONAL'", { Expected("sql_mode", {"TRADITIONAL"}) } }, + { "SET @@local.sql_mode = 'TRADITIONAL'", { Expected("sql_mode", {"TRADITIONAL"}) } }, + { "SET sql_mode = 'TRADITIONAL'", { Expected("sql_mode", {"TRADITIONAL"}) } }, + { "SET SQL_MODE ='TRADITIONAL'", { Expected("sql_mode", {"TRADITIONAL"}) } }, + { "SET SQL_MODE = \"TRADITIONAL\"", { Expected("sql_mode", {"TRADITIONAL"}) } }, + { "SET SQL_MODE = TRADITIONAL", { Expected("sql_mode", {"TRADITIONAL"}) } }, + { "set sql_mode = IFNULL(NULL,\"STRICT_TRANS_TABLES\")", { Expected("sql_mode", {"IFNULL(NULL,\"STRICT_TRANS_TABLES\")"}) } }, + { "set sql_mode = IFNULL(NULL,'STRICT_TRANS_TABLES')", { Expected("sql_mode", {"IFNULL(NULL,'STRICT_TRANS_TABLES')"}) } }, + { "SET @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ', STRICT_ALL_TABLES'), ', NO_AUTO_VALUE_ON_ZERO')", { Expected("sql_mode", {"CONCAT(CONCAT(@@sql_mode, ', STRICT_ALL_TABLES'), ', NO_AUTO_VALUE_ON_ZERO')"}) } }, + { "SET @@LOCAL.sql_mode = CONCAT(CONCAT(@@sql_mode, ', STRICT_ALL_TABLES'), ', NO_AUTO_VALUE_ON_ZERO')", { Expected("sql_mode", {"CONCAT(CONCAT(@@sql_mode, ', STRICT_ALL_TABLES'), ', NO_AUTO_VALUE_ON_ZERO')"}) } }, + { "set session sql_mode = 'ONLY_FULL_GROUP_BY'" , { Expected("sql_mode", {"ONLY_FULL_GROUP_BY"}) } }, + { "SET sql_mode = 'NO_ZERO_DATE,STRICT_ALL_TABLES,ONLY_FULL_GROUP_BY'" , { Expected("sql_mode", {"NO_ZERO_DATE,STRICT_ALL_TABLES,ONLY_FULL_GROUP_BY"}) } }, + { "SET @@sql_mode = CONCAT(@@sql_mode, ',', 'ONLY_FULL_GROUP_BY')" , { Expected("sql_mode", {"CONCAT(@@sql_mode, ',', 'ONLY_FULL_GROUP_BY')"}) } }, + { "SET @@sql_mode = REPLACE(REPLACE(REPLACE(@@sql_mode, 'ONLY_FULL_GROUP_BY,', ''),',ONLY_FULL_GROUP_BY', ''),'ONLY_FULL_GROUP_BY', '')" , { Expected("sql_mode", {"REPLACE(REPLACE(REPLACE(@@sql_mode, 'ONLY_FULL_GROUP_BY,', ''),',ONLY_FULL_GROUP_BY', ''),'ONLY_FULL_GROUP_BY', '')"}) } }, + { "SET @@sql_mode = REPLACE( REPLACE( REPLACE( @@sql_mode, 'ONLY_FULL_GROUP_BY,', ''),',ONLY_FULL_GROUP_BY', ''),'ONLY_FULL_GROUP_BY', '')" , { Expected("sql_mode", {"REPLACE( REPLACE( REPLACE( @@sql_mode, 'ONLY_FULL_GROUP_BY,', ''),',ONLY_FULL_GROUP_BY', ''),'ONLY_FULL_GROUP_BY', '')"}) } }, +// { "SET @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ', STRICT_ALL_TABLES'), ', NO_AUTO_VALUE_ON_ZERO')", { Expected("sql_mode", {"CONCAT(CONCAT(@@sql_mode, ', STRICT_ALL_TABLES'), ', NO_AUTO_VALUE_ON_ZERO')"}) } }, + { "SET SQL_MODE=IFNULL(@@sql_mode,'')", { Expected("sql_mode", { "IFNULL(@@sql_mode,'')" } ) } }, + { "SET SQL_MODE=IFNULL(@old_sql_mode,'')", { Expected("sql_mode", { "IFNULL(@old_sql_mode,'')" } ) } }, + { "SET SQL_MODE=IFNULL(@OLD_SQL_MODE,'')", { Expected("sql_mode", { "IFNULL(@OLD_SQL_MODE,'')" } ) } }, + // Complex queries involving 'SELECT' and surrounding parenthesis should be parsed properly + { "SET sql_mode=(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION'))", { Expected("sql_mode", { "(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION'))" } ) } }, + { "SET sql_mode=(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION')), time_zone = '+00:00', NAMES utf8mb4 COLLATE utf8mb4_unicode_ci", + { + Expected("sql_mode", { "(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION'))" } ), + Expected("time_zone", { "+00:00" } ), + Expected("names", {"utf8mb4", "utf8mb4_unicode_ci"} ) + } + }, + // Empty set of 'sql_mode' should result into an empty value + { "SET sql_mode=''", { Expected("sql_mode", { "" } ) } }, + // Invalid 'non-matching' versions of 'sql_mode' should result into 'non-matching' + { "SET sql_mode=(SELECT CONCA(@@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION'))", {} }, + { "SET sql_mode=(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT[,NO_ENGINE_SUBSTITUTION'))", {} }, + { "SET sql_mode=(SELCT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT[,NO_ENGINE_SUBSTITUTION'))", {} } }; static Test Set1_v1[] = { - { "SET sql_mode=(SELECT CONCAT(@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION'))", {} }, // parse1v2 SHOULD process it - { "SET sql_mode = 'TRADITIONAL', NAMES 'utf8 COLLATE 'unicode_ci'", { Expected("sql_mode", {"TRADITIONAL"}), Expected("names", {"utf8", "unicode_ci"}) } }, // FIXME: this should return an error - { "SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(REPLACE(REPLACE(REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', ''), 'STRICT_ALL_TABLES', ''), 'TRADITIONAL', ''), ',NO_AUTO_VALUE_ON_ZERO'), ',NO_ENGINE_SUBSTITUTION'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 3600", - { + { "SET sql_mode=(SELECT CONCAT(@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION'))", {} }, // parse1v2 SHOULD process it + { "SET sql_mode = 'TRADITIONAL', NAMES 'utf8 COLLATE 'unicode_ci'", { Expected("sql_mode", {"TRADITIONAL"}), Expected("names", {"utf8", "unicode_ci"}) } }, // FIXME: this should return an error + { "SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(REPLACE(REPLACE(REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', ''), 'STRICT_ALL_TABLES', ''), 'TRADITIONAL', ''), ',NO_AUTO_VALUE_ON_ZERO'), ',NO_ENGINE_SUBSTITUTION'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 3600", + { Expected("names", {"utf8"}), - Expected("sql_mode", {"CONCAT(CONCAT(REPLACE(REPLACE(REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', ''), 'STRICT_ALL_TABLES', ''), 'TRADITIONAL', ''), ',NO_AUTO_VALUE_ON_ZERO'), ',NO_ENGINE_SUBSTITUTION')"}), + Expected("sql_mode", {"CONCAT(CONCAT(REPLACE(REPLACE(REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', ''), 'STRICT_ALL_TABLES', ''), 'TRADITIONAL', ''), ',NO_AUTO_VALUE_ON_ZERO'), ',NO_ENGINE_SUBSTITUTION')"}), Expected("sql_auto_is_null", {"0"}), - Expected("wait_timeout", {"3600"}) } }, // v2 is not able to parse this, because it can process only up to 4 functions - { "SET character_set_connection=utf8,character_set_results=utf8,character_set_client=binary", {} }, // v1 can't parse this + Expected("wait_timeout", {"3600"}) } }, // v2 is not able to parse this, because it can process only up to 4 functions + { "SET character_set_connection=utf8,character_set_results=utf8,character_set_client=binary", {} }, // v1 can't parse this }; static Test Set1_v2[] = { - //{ "SET sql_mode=(SELECT CONCAT(@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION'))", {} }, // parse1v2 SHOULD process it - //{ "SET sql_mode = 'TRADITIONAL', NAMES 'utf8 COLLATE 'unicode_ci'", { Expected("sql_mode", {"TRADITIONAL"}), Expected("names", {"utf8", "unicode_ci"}) } }, // FIXME: this should return an error - { "SET sql_mode='TRADITIONAL' , whatever = , autocommit=1", {} }, // v1 is not able to process this - { "SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(REPLACE(REPLACE(REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', ''), 'STRICT_ALL_TABLES', ''), 'TRADITIONAL', ''), ',NO_AUTO_VALUE_ON_ZERO'), ',NO_ENGINE_SUBSTITUTION'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 3600", - {} }, // v2 is not able to parse this, because it can process only up to 4 functions - { "SET character_set_connection=utf8,character_set_results=utf8,character_set_client=binary", - { + //{ "SET sql_mode=(SELECT CONCAT(@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION'))", {} }, // parse1v2 SHOULD process it + //{ "SET sql_mode = 'TRADITIONAL', NAMES 'utf8 COLLATE 'unicode_ci'", { Expected("sql_mode", {"TRADITIONAL"}), Expected("names", {"utf8", "unicode_ci"}) } }, // FIXME: this should return an error + { "SET sql_mode='TRADITIONAL' , whatever = , autocommit=1", {} }, // v1 is not able to process this + { "SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(REPLACE(REPLACE(REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', ''), 'STRICT_ALL_TABLES', ''), 'TRADITIONAL', ''), ',NO_AUTO_VALUE_ON_ZERO'), ',NO_ENGINE_SUBSTITUTION'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 3600", + {} }, // v2 is not able to parse this, because it can process only up to 4 functions + { "SET character_set_connection=utf8,character_set_results=utf8,character_set_client=binary", + { Expected("character_set_connection", {"utf8"}), Expected("character_set_results", {"utf8"}), Expected("character_set_client", {"binary"}), - }, - } + }, + } }; static Test syntax_errors[] = { - { "SET sql_mode='TRADITIONAL' , whatever", {} }, - { "SET sql_mode='TRADITIONAL' , whatever = ", {} }, + { "SET sql_mode='TRADITIONAL' , whatever", {} }, + { "SET sql_mode='TRADITIONAL' , whatever = ", {} }, }; static Test time_zone[] = { - { "SET @@time_zone = 'Europe/Paris'", { Expected("time_zone", {"Europe/Paris"}) } }, - { "SET @@time_zone = '+00:00'", { Expected("time_zone", {"+00:00"}) } }, - { "SET @@time_zone = \"Europe/Paris\"", { Expected("time_zone", {"Europe/Paris"}) } }, - { "SET @@time_zone = \"+00:00\"", { Expected("time_zone", {"+00:00"}) } }, - { "SET @@time_zone = @OLD_TIME_ZONE", { Expected("time_zone", {"@OLD_TIME_ZONE"}) } }, - { "SET @@TIME_ZONE = @OLD_TIME_ZONE", { Expected("time_zone", {"@OLD_TIME_ZONE"}) } }, - { "SET @@TIME_ZONE := 'SYSTEM'", { Expected("time_zone", {"SYSTEM"}) } }, - { "SET time_zone := 'SYSTEM'", { Expected("time_zone", {"SYSTEM"}) } }, + { "SET @@time_zone = 'Europe/Paris'", { Expected("time_zone", {"Europe/Paris"}) } }, + { "SET @@time_zone = '+00:00'", { Expected("time_zone", {"+00:00"}) } }, + { "SET @@time_zone = \"Europe/Paris\"", { Expected("time_zone", {"Europe/Paris"}) } }, + { "SET @@time_zone = \"+00:00\"", { Expected("time_zone", {"+00:00"}) } }, + { "SET @@time_zone = @OLD_TIME_ZONE", { Expected("time_zone", {"@OLD_TIME_ZONE"}) } }, + { "SET @@TIME_ZONE = @OLD_TIME_ZONE", { Expected("time_zone", {"@OLD_TIME_ZONE"}) } }, + { "SET @@TIME_ZONE := 'SYSTEM'", { Expected("time_zone", {"SYSTEM"}) } }, + { "SET time_zone := 'SYSTEM'", { Expected("time_zone", {"SYSTEM"}) } }, }; static Test session_track_gtids[] = { - { "SET @@session_track_gtids = OFF", { Expected("session_track_gtids", {"OFF"}) } }, - { "SET @@session_track_gtids = OWN_GTID", { Expected("session_track_gtids", {"OWN_GTID"}) } }, - { "SET @@SESSION.session_track_gtids = OWN_GTID", { Expected("session_track_gtids", {"OWN_GTID"}) } }, - { "SET @@LOCAL.session_track_gtids = OWN_GTID", { Expected("session_track_gtids", {"OWN_GTID"}) } }, - { "SET SESSION session_track_gtids = OWN_GTID", { Expected("session_track_gtids", {"OWN_GTID"}) } }, - { "SET @@session_track_gtids = ALL_GTIDS", { Expected("session_track_gtids", {"ALL_GTIDS"}) } }, - { "SET @@SESSION.session_track_gtids = ALL_GTIDS", { Expected("session_track_gtids", {"ALL_GTIDS"}) } }, - { "SET @@LOCAL.session_track_gtids = ALL_GTIDS", { Expected("session_track_gtids", {"ALL_GTIDS"}) } }, - { "SET SESSION session_track_gtids = ALL_GTIDS", { Expected("session_track_gtids", {"ALL_GTIDS"}) } }, + { "SET @@session_track_gtids = OFF", { Expected("session_track_gtids", {"OFF"}) } }, + { "SET @@session_track_gtids = OWN_GTID", { Expected("session_track_gtids", {"OWN_GTID"}) } }, + { "SET @@SESSION.session_track_gtids = OWN_GTID", { Expected("session_track_gtids", {"OWN_GTID"}) } }, + { "SET @@LOCAL.session_track_gtids = OWN_GTID", { Expected("session_track_gtids", {"OWN_GTID"}) } }, + { "SET SESSION session_track_gtids = OWN_GTID", { Expected("session_track_gtids", {"OWN_GTID"}) } }, + { "SET @@session_track_gtids = ALL_GTIDS", { Expected("session_track_gtids", {"ALL_GTIDS"}) } }, + { "SET @@SESSION.session_track_gtids = ALL_GTIDS", { Expected("session_track_gtids", {"ALL_GTIDS"}) } }, + { "SET @@LOCAL.session_track_gtids = ALL_GTIDS", { Expected("session_track_gtids", {"ALL_GTIDS"}) } }, + { "SET SESSION session_track_gtids = ALL_GTIDS", { Expected("session_track_gtids", {"ALL_GTIDS"}) } }, }; static Test character_set_results[] = { - { "SET @@character_set_results = utf8", { Expected("character_set_results", {"utf8"}) } }, - { "SET @@character_set_results = NULL", { Expected("character_set_results", {"NULL"}) } }, - { "SET character_set_results = NULL", { Expected("character_set_results", {"NULL"}) } }, - { "SET @@session.character_set_results = NULL", { Expected("character_set_results", {"NULL"}) } }, - { "SET @@local.character_set_results = NULL", { Expected("character_set_results", {"NULL"}) } }, - { "SET session character_set_results = NULL", { Expected("character_set_results", {"NULL"}) } }, + { "SET @@character_set_results = utf8", { Expected("character_set_results", {"utf8"}) } }, + { "SET @@character_set_results = NULL", { Expected("character_set_results", {"NULL"}) } }, + { "SET character_set_results = NULL", { Expected("character_set_results", {"NULL"}) } }, + { "SET @@session.character_set_results = NULL", { Expected("character_set_results", {"NULL"}) } }, + { "SET @@local.character_set_results = NULL", { Expected("character_set_results", {"NULL"}) } }, + { "SET session character_set_results = NULL", { Expected("character_set_results", {"NULL"}) } }, }; static Test names[] = { - { "SET NAMES utf8", { Expected("names", {"utf8"}) } }, - { "SET NAMES 'utf8'", { Expected("names", {"utf8"}) } }, - { "SET NAMES \"utf8\"", { Expected("names", {"utf8"}) } }, - { "SET NAMES utf8 COLLATE unicode_ci", { Expected("names", {"utf8", "unicode_ci"}) } }, + { "SET NAMES utf8", { Expected("names", {"utf8"}) } }, + { "SET NAMES 'utf8'", { Expected("names", {"utf8"}) } }, + { "SET NAMES \"utf8\"", { Expected("names", {"utf8"}) } }, + { "SET NAMES utf8 COLLATE unicode_ci", { Expected("names", {"utf8", "unicode_ci"}) } }, }; static Test various[] = { - { "SET @@SESSION.SQL_SELECT_LIMIT= DEFAULT", { Expected("sql_select_limit", {"DEFAULT"}) } }, - { "SET @@LOCAL.SQL_SELECT_LIMIT= DEFAULT", { Expected("sql_select_limit", {"DEFAULT"}) } }, - { "SET @@SQL_SELECT_LIMIT= DEFAULT", { Expected("sql_select_limit", {"DEFAULT"}) } }, - { "SET SESSION SQL_SELECT_LIMIT = DEFAULT", { Expected("sql_select_limit", {"DEFAULT"}) } }, - { "SET @@SESSION.SQL_SELECT_LIMIT= 1234", { Expected("sql_select_limit", {"1234"}) } }, - { "SET @@LOCAL.SQL_SELECT_LIMIT= 1234", { Expected("sql_select_limit", {"1234"}) } }, - { "SET @@SQL_SELECT_LIMIT= 1234", { Expected("sql_select_limit", {"1234"}) } }, - { "SET SESSION SQL_SELECT_LIMIT = 1234", { Expected("sql_select_limit", {"1234"}) } }, - { "SET @@SESSION.SQL_SELECT_LIMIT= 1234", { Expected("sql_select_limit", {"1234"}) } }, - { "SET @@LOCAL.SQL_SELECT_LIMIT= 1234", { Expected("sql_select_limit", {"1234"}) } }, - { "SET @@SESSION.SQL_SELECT_LIMIT= @old_sql_select_limit", { Expected("sql_select_limit", {"@old_sql_select_limit"}) } }, - { "SET @@LOCAL.SQL_SELECT_LIMIT= @old_sql_select_limit", { Expected("sql_select_limit", {"@old_sql_select_limit"}) } }, - { "SET SQL_SELECT_LIMIT= @old_sql_select_limit", { Expected("sql_select_limit", {"@old_sql_select_limit"}) } }, - { "SET @@SESSION.sql_auto_is_null = 0", { Expected("sql_auto_is_null", {"0"}) } }, - { "SET @@LOCAL.sql_auto_is_null = 0", { Expected("sql_auto_is_null", {"0"}) } }, - { "SET SESSION sql_auto_is_null = 1", { Expected("sql_auto_is_null", {"1"}) } }, - { "SET sql_auto_is_null = OFF", { Expected("sql_auto_is_null", {"OFF"}) } }, - { "SET @@sql_auto_is_null = ON", { Expected("sql_auto_is_null", {"ON"}) } }, - { "SET @@SESSION.sql_safe_updates = 0", { Expected("sql_safe_updates", {"0"}) } }, - { "SET @@LOCAL.sql_safe_updates = 0", { Expected("sql_safe_updates", {"0"}) } }, - { "SET SESSION sql_safe_updates = 1", { Expected("sql_safe_updates", {"1"}) } }, - { "SET SQL_SAFE_UPDATES = OFF", { Expected("sql_safe_updates", {"OFF"}) } }, - { "SET @@sql_safe_updates = ON", { Expected("sql_safe_updates", {"ON"}) } }, - { "SET optimizer_switch=`index_merge=OFF`" , { Expected("optimizer_switch", {"index_merge=OFF"}) } }, - { "SET optimizer_switch='index_merge=on,index_merge_union=off,index_merge_sort_union=on'" , { Expected("optimizer_switch", {"index_merge=on,index_merge_union=off,index_merge_sort_union=on"}) } }, + { "SET @@SESSION.SQL_SELECT_LIMIT= DEFAULT", { Expected("sql_select_limit", {"DEFAULT"}) } }, + { "SET @@LOCAL.SQL_SELECT_LIMIT= DEFAULT", { Expected("sql_select_limit", {"DEFAULT"}) } }, + { "SET @@SQL_SELECT_LIMIT= DEFAULT", { Expected("sql_select_limit", {"DEFAULT"}) } }, + { "SET SESSION SQL_SELECT_LIMIT = DEFAULT", { Expected("sql_select_limit", {"DEFAULT"}) } }, + { "SET @@SESSION.SQL_SELECT_LIMIT= 1234", { Expected("sql_select_limit", {"1234"}) } }, + { "SET @@LOCAL.SQL_SELECT_LIMIT= 1234", { Expected("sql_select_limit", {"1234"}) } }, + { "SET @@SQL_SELECT_LIMIT= 1234", { Expected("sql_select_limit", {"1234"}) } }, + { "SET SESSION SQL_SELECT_LIMIT = 1234", { Expected("sql_select_limit", {"1234"}) } }, + { "SET @@SESSION.SQL_SELECT_LIMIT= 1234", { Expected("sql_select_limit", {"1234"}) } }, + { "SET @@LOCAL.SQL_SELECT_LIMIT= 1234", { Expected("sql_select_limit", {"1234"}) } }, + { "SET @@SESSION.SQL_SELECT_LIMIT= @old_sql_select_limit", { Expected("sql_select_limit", {"@old_sql_select_limit"}) } }, + { "SET @@LOCAL.SQL_SELECT_LIMIT= @old_sql_select_limit", { Expected("sql_select_limit", {"@old_sql_select_limit"}) } }, + { "SET SQL_SELECT_LIMIT= @old_sql_select_limit", { Expected("sql_select_limit", {"@old_sql_select_limit"}) } }, + { "SET @@SESSION.sql_auto_is_null = 0", { Expected("sql_auto_is_null", {"0"}) } }, + { "SET @@LOCAL.sql_auto_is_null = 0", { Expected("sql_auto_is_null", {"0"}) } }, + { "SET SESSION sql_auto_is_null = 1", { Expected("sql_auto_is_null", {"1"}) } }, + { "SET sql_auto_is_null = OFF", { Expected("sql_auto_is_null", {"OFF"}) } }, + { "SET @@sql_auto_is_null = ON", { Expected("sql_auto_is_null", {"ON"}) } }, + { "SET @@SESSION.sql_safe_updates = 0", { Expected("sql_safe_updates", {"0"}) } }, + { "SET @@LOCAL.sql_safe_updates = 0", { Expected("sql_safe_updates", {"0"}) } }, + { "SET SESSION sql_safe_updates = 1", { Expected("sql_safe_updates", {"1"}) } }, + { "SET SQL_SAFE_UPDATES = OFF", { Expected("sql_safe_updates", {"OFF"}) } }, + { "SET @@sql_safe_updates = ON", { Expected("sql_safe_updates", {"ON"}) } }, + { "SET optimizer_switch=`index_merge=OFF`" , { Expected("optimizer_switch", {"index_merge=OFF"}) } }, + { "SET optimizer_switch='index_merge=on,index_merge_union=off,index_merge_sort_union=on'" , { Expected("optimizer_switch", {"index_merge=on,index_merge_union=off,index_merge_sort_union=on"}) } }, }; static Test multiple[] = { - { "SET time_zone = 'Europe/Paris', sql_mode = 'TRADITIONAL'", { Expected("time_zone", {"Europe/Paris"}), Expected("sql_mode", {"TRADITIONAL"}) } }, - { "SET time_zone = 'Europe/Paris', sql_mode = IFNULL(NULL,\"STRICT_TRANS_TABLES\")", { Expected("time_zone", {"Europe/Paris"}), Expected("sql_mode", {"IFNULL(NULL,\"STRICT_TRANS_TABLES\")"}) } }, - { "SET sql_mode = 'TRADITIONAL', NAMES 'utf8' COLLATE 'unicode_ci'", { Expected("sql_mode", {"TRADITIONAL"}), Expected("names", {"utf8", "unicode_ci"}) } }, - { "SET @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483", - { Expected("sql_mode", {"CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO')"}), Expected("sql_auto_is_null", {"0"}), - Expected("wait_timeout", {"2147483"}) } }, - { "SET @@LOCAL.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483", - { Expected("sql_mode", {"CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO')"}), Expected("sql_auto_is_null", {"0"}), - Expected("wait_timeout", {"2147483"}) } }, - { "set autocommit=1, sql_mode = concat(@@sql_mode,',STRICT_TRANS_TABLES')", { Expected("autocommit", {"1"}), Expected("sql_mode", {"concat(@@sql_mode,',STRICT_TRANS_TABLES')"}) } }, - { "SET NAMES utf8, @@SESSION.sql_mode = CONCAT(REPLACE(REPLACE(REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', ''), 'STRICT_ALL_TABLES', ''), 'TRADITIONAL', ''), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 3600", - { Expected("names", {"utf8"}), Expected("sql_mode", {"CONCAT(REPLACE(REPLACE(REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', ''), 'STRICT_ALL_TABLES', ''), 'TRADITIONAL', ''), ',NO_AUTO_VALUE_ON_ZERO')"}), Expected("sql_auto_is_null", {"0"}), - Expected("wait_timeout", {"3600"}) } }, - { "SET NAMES utf8, @@LOCAL.sql_mode = CONCAT(REPLACE(REPLACE(REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', ''), 'STRICT_ALL_TABLES', ''), 'TRADITIONAL', ''), ',NO_AUTO_VALUE_ON_ZERO'), @@LOCAL.sql_auto_is_null = 0, @@LOCAL.wait_timeout = 3600", - { Expected("names", {"utf8"}), Expected("sql_mode", {"CONCAT(REPLACE(REPLACE(REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', ''), 'STRICT_ALL_TABLES', ''), 'TRADITIONAL', ''), ',NO_AUTO_VALUE_ON_ZERO')"}), Expected("sql_auto_is_null", {"0"}), - Expected("wait_timeout", {"3600"}) } }, - { "set autocommit=1, session_track_schema=1, sql_mode = concat(@@sql_mode,',STRICT_TRANS_TABLES'), @@SESSION.net_write_timeout=7200", { Expected("autocommit", {"1"}), Expected("session_track_schema", {"1"}), Expected("sql_mode", {"concat(@@sql_mode,',STRICT_TRANS_TABLES')"}), - Expected("net_write_timeout", {"7200"}) } }, - { "set autocommit=1, session_track_schema=1, sql_mode = concat(@@sql_mode,',STRICT_TRANS_TABLES'), @@LOCAL.net_write_timeout=7200", { Expected("autocommit", {"1"}), Expected("session_track_schema", {"1"}), Expected("sql_mode", {"concat(@@sql_mode,',STRICT_TRANS_TABLES')"}), - Expected("net_write_timeout", {"7200"}) } }, - // Mutiple set queries involving 'NULL' values should be properly parsed with and without spaces - { "set character_set_results=null, names latin7, character_set_client='utf8mb4'", - { - Expected("character_set_results", { "null" } ), - Expected("names", { "latin7" } ), - Expected("character_set_client", { "utf8mb4" } ), - } - }, - { "SET character_set_results=NULL, NAMES latin7, character_set_client='utf8mb4'", - { - Expected("character_set_results", { "NULL" } ), - Expected("names", { "latin7" } ), - Expected("character_set_client", { "utf8mb4" } ), - } - }, - { "set character_set_results=null,names latin7,character_set_client='utf8mb4'", - { - Expected("character_set_results", { "null" } ), - Expected("names", { "latin7" } ), - Expected("character_set_client", { "utf8mb4" } ), - } - }, - { "SET character_set_results=NULL,NAMES latin7,character_set_client='utf8mb4'", - { - Expected("character_set_results", { "NULL" } ), - Expected("names", { "latin7" } ), - Expected("character_set_client", { "utf8mb4" } ), - } - }, - { "SET @@autocommit := 0 , NAMES \"utf8mb3\"", { Expected("autocommit", {"0"}) , Expected("names",{"utf8mb3"}) } }, - { "SET character_set_results=NULL,NAMES latin7,character_set_client='utf8mb4', autocommit := 1 , time_zone = 'Europe/Paris'", - { - Expected("character_set_results", { "NULL" } ), - Expected("names", { "latin7" } ), - Expected("character_set_client", { "utf8mb4" } ), - Expected("autocommit", { "1" } ), - Expected("time_zone", { "Europe/Paris" } ), - } - }, + { "SET time_zone = 'Europe/Paris', sql_mode = 'TRADITIONAL'", { Expected("time_zone", {"Europe/Paris"}), Expected("sql_mode", {"TRADITIONAL"}) } }, + { "SET time_zone = 'Europe/Paris', sql_mode = IFNULL(NULL,\"STRICT_TRANS_TABLES\")", { Expected("time_zone", {"Europe/Paris"}), Expected("sql_mode", {"IFNULL(NULL,\"STRICT_TRANS_TABLES\")"}) } }, + { "SET sql_mode = 'TRADITIONAL', NAMES 'utf8' COLLATE 'unicode_ci'", { Expected("sql_mode", {"TRADITIONAL"}), Expected("names", {"utf8", "unicode_ci"}) } }, + { "SET @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483", + { Expected("sql_mode", {"CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO')"}), Expected("sql_auto_is_null", {"0"}), + Expected("wait_timeout", {"2147483"}) } }, + { "SET @@LOCAL.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483", + { Expected("sql_mode", {"CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO')"}), Expected("sql_auto_is_null", {"0"}), + Expected("wait_timeout", {"2147483"}) } }, + { "set autocommit=1, sql_mode = concat(@@sql_mode,',STRICT_TRANS_TABLES')", { Expected("autocommit", {"1"}), Expected("sql_mode", {"concat(@@sql_mode,',STRICT_TRANS_TABLES')"}) } }, + { "SET NAMES utf8, @@SESSION.sql_mode = CONCAT(REPLACE(REPLACE(REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', ''), 'STRICT_ALL_TABLES', ''), 'TRADITIONAL', ''), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 3600", + { Expected("names", {"utf8"}), Expected("sql_mode", {"CONCAT(REPLACE(REPLACE(REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', ''), 'STRICT_ALL_TABLES', ''), 'TRADITIONAL', ''), ',NO_AUTO_VALUE_ON_ZERO')"}), Expected("sql_auto_is_null", {"0"}), + Expected("wait_timeout", {"3600"}) } }, + { "SET NAMES utf8, @@LOCAL.sql_mode = CONCAT(REPLACE(REPLACE(REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', ''), 'STRICT_ALL_TABLES', ''), 'TRADITIONAL', ''), ',NO_AUTO_VALUE_ON_ZERO'), @@LOCAL.sql_auto_is_null = 0, @@LOCAL.wait_timeout = 3600", + { Expected("names", {"utf8"}), Expected("sql_mode", {"CONCAT(REPLACE(REPLACE(REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', ''), 'STRICT_ALL_TABLES', ''), 'TRADITIONAL', ''), ',NO_AUTO_VALUE_ON_ZERO')"}), Expected("sql_auto_is_null", {"0"}), + Expected("wait_timeout", {"3600"}) } }, + { "set autocommit=1, session_track_schema=1, sql_mode = concat(@@sql_mode,',STRICT_TRANS_TABLES'), @@SESSION.net_write_timeout=7200", { Expected("autocommit", {"1"}), Expected("session_track_schema", {"1"}), Expected("sql_mode", {"concat(@@sql_mode,',STRICT_TRANS_TABLES')"}), + Expected("net_write_timeout", {"7200"}) } }, + { "set autocommit=1, session_track_schema=1, sql_mode = concat(@@sql_mode,',STRICT_TRANS_TABLES'), @@LOCAL.net_write_timeout=7200", { Expected("autocommit", {"1"}), Expected("session_track_schema", {"1"}), Expected("sql_mode", {"concat(@@sql_mode,',STRICT_TRANS_TABLES')"}), + Expected("net_write_timeout", {"7200"}) } }, + // Mutiple set queries involving 'NULL' values should be properly parsed with and without spaces + { "set character_set_results=null, names latin7, character_set_client='utf8mb4'", + { + Expected("character_set_results", { "null" } ), + Expected("names", { "latin7" } ), + Expected("character_set_client", { "utf8mb4" } ), + } + }, + { "SET character_set_results=NULL, NAMES latin7, character_set_client='utf8mb4'", + { + Expected("character_set_results", { "NULL" } ), + Expected("names", { "latin7" } ), + Expected("character_set_client", { "utf8mb4" } ), + } + }, + { "set character_set_results=null,names latin7,character_set_client='utf8mb4'", + { + Expected("character_set_results", { "null" } ), + Expected("names", { "latin7" } ), + Expected("character_set_client", { "utf8mb4" } ), + } + }, + { "SET character_set_results=NULL,NAMES latin7,character_set_client='utf8mb4'", + { + Expected("character_set_results", { "NULL" } ), + Expected("names", { "latin7" } ), + Expected("character_set_client", { "utf8mb4" } ), + } + }, + { "SET @@autocommit := 0 , NAMES \"utf8mb3\"", { Expected("autocommit", {"0"}) , Expected("names",{"utf8mb3"}) } }, + { "SET character_set_results=NULL,NAMES latin7,character_set_client='utf8mb4', autocommit := 1 , time_zone = 'Europe/Paris'", + { + Expected("character_set_results", { "NULL" } ), + Expected("names", { "latin7" } ), + Expected("character_set_client", { "utf8mb4" } ), + Expected("autocommit", { "1" } ), + Expected("time_zone", { "Europe/Paris" } ), + } + }, }; diff --git a/test/tap/tests/sqlite3-t.cpp b/test/tap/tests/sqlite3-t.cpp index c9c1a421c7..e549b613b1 100644 --- a/test/tap/tests/sqlite3-t.cpp +++ b/test/tap/tests/sqlite3-t.cpp @@ -1,7 +1,6 @@ #define PROXYSQL_EXTERN #define MAIN_PROXY_SQLITE3 #include -#include "tap.h" #include #include #include @@ -13,6 +12,11 @@ #include "sqlite3db.h" #include "MySQL_LDAP_Authentication.hpp" +#include "tap.h" +#include "command_line.h" + +CommandLine cl; + MySQL_LDAP_Authentication* GloMyLdapAuth = nullptr; int main() { diff --git a/test/tap/tests/sqlite_autocommit-t.cpp b/test/tap/tests/sqlite_autocommit-t.cpp index e5a15e0726..7c68083fed 100644 --- a/test/tap/tests/sqlite_autocommit-t.cpp +++ b/test/tap/tests/sqlite_autocommit-t.cpp @@ -11,6 +11,8 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + /* This test includes a lot of repetitive checks that could have been organized into functions. But they have been left in this way to easily identify the failed check @@ -18,23 +20,26 @@ But they have been left in this way to easily identify the failed check int main(int argc, char** argv) { - CommandLine cl; - - if(cl.getEnv()) - return exit_status(); - plan(48); + plan(2 + 48); diag("Testing autocommit and transaction in SQLite3 Server"); MYSQL* mysql = mysql_init(NULL); - if (!mysql) - return exit_status(); - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + mysql_options(mysql, MYSQL_SET_CHARSET_NAME, "utf8"); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, 6030, NULL, 0)) { - fprintf(stderr, "Failed to connect to database: Error: %s\n", - mysql_error(mysql)); + fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } + MYSQL_RES *res; if (create_table_test_sqlite_sbtest1(100,mysql)) { fprintf(stderr, "File %s, line %d, Error: create_table_test_sbtest1() failed\n", __FILE__, __LINE__); diff --git a/test/tap/tests/test_admin_prometheus_metrics_dump-t_disabled_gh3571.cpp b/test/tap/tests/test_admin_prometheus_metrics_dump-t_disabled_gh3571.cpp index f979b772e0..ceba25549c 100644 --- a/test/tap/tests/test_admin_prometheus_metrics_dump-t_disabled_gh3571.cpp +++ b/test/tap/tests/test_admin_prometheus_metrics_dump-t_disabled_gh3571.cpp @@ -19,30 +19,27 @@ using std::string; +CommandLine cl; + std::size_t supported_metrics = 121; int main(int argc, char** argv) { - CommandLine cl; - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - - plan(3); + plan(2 + 3); MYSQL* proxysql_admin = mysql_init(NULL); - - // Initialize connections - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return -1; - } - - // Connnect to local proxysql + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } MYSQL_QUERY(proxysql_admin, "SHOW PROMETHEUS METRICS\\G"); diff --git a/test/tap/tests/test_admin_stats-t.cpp b/test/tap/tests/test_admin_stats-t.cpp index 29ac4d0e40..cb397c6d99 100644 --- a/test/tap/tests/test_admin_stats-t.cpp +++ b/test/tap/tests/test_admin_stats-t.cpp @@ -38,6 +38,8 @@ using std::string; using std::to_string; using std::vector; +CommandLine cl; + int wait_for_history_update(MYSQL* proxysql_admin, uint32_t timeout) { uint64_t previous_timestamp = 0; uint32_t retries = 0; @@ -75,30 +77,25 @@ int wait_for_history_update(MYSQL* proxysql_admin, uint32_t timeout) { } int main(int argc, char** argv) { - CommandLine cl; - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } + /** @brief Minimum number of distinct variable_name strings in the history_mysql_status_variables_lookup table */ + const int min_distinct_variable_names = 50; - /** @brief Minimum number of distinct variable_name strings in the history_mysql_status_variables_lookup table */ - const int min_distinct_variable_names = 50; - - plan(5); + plan(2 + 5); MYSQL* proxysql_admin = mysql_init(NULL); - - // Initialize connections - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return -1; - } - - // Connnect to local proxysql + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } // Setup the interval of how often new status entries are created diff --git a/test/tap/tests/test_auth_methods-t.cpp b/test/tap/tests/test_auth_methods-t.cpp index d5b0c86023..5b21597065 100644 --- a/test/tap/tests/test_auth_methods-t.cpp +++ b/test/tap/tests/test_auth_methods-t.cpp @@ -39,6 +39,8 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + // Additional env variables uint32_t TAP_MYSQL8_BACKEND_HG = 30; uint32_t TAP_NUM_CLIENT_THREADS = 4; @@ -1659,12 +1661,6 @@ int test_all_confs_creds( } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } TAP_MYSQL8_BACKEND_HG = get_env_int("TAP_MYSQL8_BACKEND_HG", 30); TAP_NUM_CLIENT_THREADS = get_env_int("TAP_NUM_CLIENT_THREADS", 4); diff --git a/test/tap/tests/test_auto_increment_delay_multiplex-t.cpp b/test/tap/tests/test_auto_increment_delay_multiplex-t.cpp index ee50da7211..48ac9a085c 100644 --- a/test/tap/tests/test_auto_increment_delay_multiplex-t.cpp +++ b/test/tap/tests/test_auto_increment_delay_multiplex-t.cpp @@ -38,12 +38,13 @@ #include "utils.h" #include "tap.h" - using std::function; using std::string; using std::vector; using nlohmann::json; +CommandLine cl; + const char* INSERT_QUERY { "INSERT INTO test.auto_inc_multiplex (c2, c3) VALUES ('foo','bar')" }; const char* CREATE_TABLE_QUERY { "CREATE TABLE IF NOT EXISTS test.auto_inc_multiplex " @@ -898,14 +899,10 @@ const vector> conn_delay_multiplex_tests { }; int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } plan( + 2 + 2 + // connections + (2 + 2) * conn_delay_multiplex_tests.size() + // connections 1 + // Check variables are present ((VAL_RANGE / STEP) + 1) * 2 + // Tests for different 'auto_increment_delay_multiplex' values (VAL_RANGE / STEP) * 3 + // Tests for different 'auto_increment_delay_multiplex_timeout_ms' values @@ -918,16 +915,33 @@ int main(int argc, char** argv) { ); MYSQL* proxy_mysql = mysql_init(NULL); - MYSQL* proxy_admin = mysql_init(NULL); - -// if (!mysql_real_connect(proxy_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { + diag("Connecting: cl.root_username='%s' cl.use_ssl=%d cl.compression=%d", cl.root_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_mysql, cl.root_host, cl.root_username, cl.root_password, NULL, cl.root_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: \"%s\"\n", __FILE__, __LINE__, mysql_error(proxy_mysql)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_mysql->net.compress, "Compression: (%d)", proxy_mysql->net.compress); } + + MYSQL* proxy_admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: \"%s\"\n", __FILE__, __LINE__, mysql_error(proxy_admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_admin->net.compress, "Compression: (%d)", proxy_admin->net.compress); } MYSQL_QUERY(proxy_mysql, "CREATE DATABASE IF NOT EXISTS test"); @@ -943,17 +957,35 @@ int main(int argc, char** argv) { mysql_close(proxy_admin); for (const function& test : conn_delay_multiplex_tests) { - proxy_mysql = mysql_init(NULL); - proxy_admin = mysql_init(NULL); -// if (!mysql_real_connect(proxy_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { + proxy_mysql = mysql_init(NULL); + diag("Connecting: cl.root_username='%s' cl.use_ssl=%d cl.compression=%d", cl.root_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_mysql, cl.root_host, cl.root_username, cl.root_password, NULL, cl.root_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: \"%s\"\n", __FILE__, __LINE__, mysql_error(proxy_mysql)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_mysql->net.compress, "Compression: (%d)", proxy_mysql->net.compress); } + + proxy_admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: \"%s\"\n", __FILE__, __LINE__, mysql_error(proxy_admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_admin->net.compress, "Compression: (%d)", proxy_admin->net.compress); } test(proxy_mysql, proxy_admin); diff --git a/test/tap/tests/test_backend_conn_ping-t.cpp b/test/tap/tests/test_backend_conn_ping-t.cpp index 5c2be5634c..7dc0ac6a32 100644 --- a/test/tap/tests/test_backend_conn_ping-t.cpp +++ b/test/tap/tests/test_backend_conn_ping-t.cpp @@ -39,6 +39,9 @@ using std::pair; using srv_cfg = vector>; + +CommandLine cl; + int wait_timeout = 10; #ifndef SESSIONS_FOR_CONNECTIONS_HANDLER @@ -82,63 +85,62 @@ int compute_wait_timeout(MYSQL *my_conn) { } -int change_mysql_cfg( - const CommandLine& cl, const string& host, const string& port, const srv_cfg& new_srv_cfg, srv_cfg& out_old_srv_cfg -) { +int change_mysql_cfg(const string& host, const string& port, const srv_cfg& new_srv_cfg, srv_cfg& out_old_srv_cfg) { int res = EXIT_SUCCESS; MYSQL* my_conn = mysql_init(NULL); - if (!my_conn) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(my_conn)); - return EXIT_FAILURE; - } - diag("Connecting to %s:%s with user %s", host.c_str(), port.c_str(), cl.mysql_username); + if (cl.use_ssl) + mysql_ssl_set(my_conn, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(my_conn, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(my_conn, host.c_str(), cl.mysql_username, cl.mysql_password, NULL, std::stol(port.c_str()), NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(my_conn)); - res = EXIT_FAILURE; + return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(my_conn); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == my_conn->net.compress, "Compression: (%d)", my_conn->net.compress); } - if (res == EXIT_SUCCESS) { - srv_cfg old_server_config {}; + srv_cfg old_server_config {}; - for (const pair& config_var : new_srv_cfg) { - string query = "SELECT @@" + config_var.first; - diag("Line:%d : Running: %s", __LINE__, query.c_str()); - res = mysql_query(my_conn, query.c_str()); - if (res != EXIT_SUCCESS) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(my_conn)); - res = EXIT_FAILURE; - break; - } + for (const pair& config_var : new_srv_cfg) { + string query = "SELECT @@" + config_var.first; + diag("Line:%d : Running: %s", __LINE__, query.c_str()); + res = mysql_query(my_conn, query.c_str()); + if (res != EXIT_SUCCESS) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(my_conn)); + res = EXIT_FAILURE; + break; + } - MYSQL_RES* my_res = mysql_store_result(my_conn); - if (my_res == nullptr) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(my_conn)); - res = EXIT_FAILURE; - break; - } + MYSQL_RES* my_res = mysql_store_result(my_conn); + if (my_res == nullptr) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(my_conn)); + res = EXIT_FAILURE; + break; + } - MYSQL_ROW row = mysql_fetch_row(my_res); - if (row == nullptr || row[0] == nullptr) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(my_conn)); - res = EXIT_FAILURE; - break; - } else { - diag("Line:%d : Returned: %s = %s", __LINE__, config_var.first.c_str(), row[0]); - old_server_config.push_back({ config_var.first, std::stol(row[0]) }); - } + MYSQL_ROW row = mysql_fetch_row(my_res); + if (row == nullptr || row[0] == nullptr) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(my_conn)); + res = EXIT_FAILURE; + break; + } else { + diag("Line:%d : Returned: %s = %s", __LINE__, config_var.first.c_str(), row[0]); + old_server_config.push_back({ config_var.first, std::stol(row[0]) }); + } - mysql_free_result(my_res); + mysql_free_result(my_res); - query = string { "SET GLOBAL " + config_var.first + "=" + std::to_string(config_var.second) }; - diag("Line:%d : Setting on %s:%s : %s", __LINE__ , host.c_str(), port.c_str(), query.c_str()); - mysql_query(my_conn, query.c_str()); - if (res != EXIT_SUCCESS) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(my_conn)); - res = EXIT_FAILURE; - break; - } + query = string { "SET GLOBAL " + config_var.first + "=" + std::to_string(config_var.second) }; + diag("Line:%d : Setting on %s:%s : %s", __LINE__ , host.c_str(), port.c_str(), query.c_str()); + mysql_query(my_conn, query.c_str()); + if (res != EXIT_SUCCESS) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(my_conn)); + res = EXIT_FAILURE; + break; } if (res == EXIT_SUCCESS) { @@ -151,17 +153,21 @@ int change_mysql_cfg( return res; } -int create_new_backend_conn(const CommandLine& cl, int tg_hg, vector& mysql_conns) { - MYSQL* conn = mysql_init(NULL); - - if (!conn) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(conn)); - return EXIT_FAILURE; - } +int create_new_backend_conn(int tg_hg, vector& mysql_conns) { + MYSQL* conn = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(conn, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(conn, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(conn, cl.host, cl.username, cl.password, "backend_conn_ping_test", cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(conn)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(conn); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == conn->net.compress, "Compression: (%d)", conn->net.compress); } const string query { "DO /* ;hostgroup=" + std::to_string(tg_hg) + ";create_new_connection=1 */ 1" }; @@ -206,15 +212,14 @@ struct test_params_t { using svr_addr = pair; -int check_backend_conns( - const CommandLine& cl, const test_params_t& test_params, uint32_t hg, const vector& svrs_addrs -) { +int check_backend_conns(const test_params_t& test_params, uint32_t hg, const vector& svrs_addrs) { + vector mysql_conns {}; int res = EXIT_SUCCESS; diag("Line:%d : Creating %f connections on hg %d", __LINE__ , test_params.init_batch_size, hg); for (uint32_t i = 0; i < test_params.init_batch_size; i++) { - int c_res = create_new_backend_conn(cl, hg, mysql_conns); + int c_res = create_new_backend_conn(hg, mysql_conns); if (c_res != EXIT_SUCCESS) { return EXIT_FAILURE; } } @@ -224,7 +229,7 @@ int check_backend_conns( for (uint32_t i = 0; i < test_params.its; i++) { diag("Line:%d : Creating %f connections on hg %d , iteration %d", __LINE__ , test_params.batch_size, hg, i); for (uint32_t j = 0; j < test_params.batch_size; j++) { - int c_res = create_new_backend_conn(cl, hg, mysql_conns); + int c_res = create_new_backend_conn(hg, mysql_conns); if (c_res != EXIT_SUCCESS) { return EXIT_FAILURE; } } @@ -236,19 +241,36 @@ int check_backend_conns( vector svrs_conns {}; { + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == admin->net.compress, "Compression: (%d)", admin->net.compress); } for (const auto& svr_addr : svrs_addrs) { - MYSQL* mysql = mysql_init(NULL); -// if (!mysql_real_connect(mysql, svr_addr.first.c_str(), cl.username, cl.password, NULL, svr_addr.second, NULL, 0)) { + MYSQL* mysql = mysql_init(NULL); + diag("Connecting: cl.mysql_username='%s' cl.use_ssl=%d cl.compression=%d", cl.mysql_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, svr_addr.first.c_str(), cl.mysql_username, cl.mysql_password, NULL, svr_addr.second, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); res = EXIT_FAILURE; goto cleanup; + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } svrs_conns.push_back(mysql); @@ -426,14 +448,8 @@ int wait_target_backend_conns(MYSQL* admin, uint32_t tg_backend_conns, uint32_t } int main(int, char**) { - CommandLine cl; - plan(4); - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } +// plan(2+2 + 4); struct rlimit limits { 0, 0 }; getrlimit(RLIMIT_NOFILE, &limits); @@ -441,15 +457,18 @@ int main(int, char**) { setrlimit(RLIMIT_NOFILE, &limits); MYSQL* proxy_mysql = mysql_init(NULL); - - // Initialize connections - if (!proxy_mysql) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_mysql)); - return exit_status(); - } + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_mysql)); - return exit_status(); + return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_mysql->net.compress, "Compression: (%d)", proxy_mysql->net.compress); } // Create a new 'db' for connection filtering @@ -458,16 +477,21 @@ int main(int, char**) { mysql_close(proxy_mysql); MYSQL* proxy_admin = mysql_init(NULL); - if (!proxy_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_admin)); - return exit_status(); - } - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_admin)); - return exit_status(); + return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_admin->net.compress, "Compression: (%d)", proxy_admin->net.compress); } + if (compute_wait_timeout(proxy_admin) != EXIT_SUCCESS) { return exit_status(); } @@ -482,6 +506,13 @@ int main(int, char**) { double its = (conn_creation_intv - b_0/rate) / ( b / rate ); double delay_s = conn_creation_intv / its; +// plan( +// 2+2 + // connections +// b_0*2 + // +// its*(b*2)*2 + // * num of hg? +// 4 // tests +// ); + // Cleanup previous backend connections diag("Cleaning up previous backend connections..."); MYSQL_QUERY(proxy_admin, "UPDATE mysql_servers SET max_connections=0"); @@ -546,7 +577,7 @@ int main(int, char**) { for (const mysql_res_row& srv_row : servers_rows) { srv_cfg old_srv_cfg {}; diag("Line:%d : %s:%s", __LINE__ , srv_row[0].c_str(), srv_row[1].c_str()); - int cfg_res = change_mysql_cfg(cl, srv_row[0], srv_row[1], new_srv_cfg, old_srv_cfg); + int cfg_res = change_mysql_cfg(srv_row[0], srv_row[1], new_srv_cfg, old_srv_cfg); if (cfg_res != EXIT_SUCCESS) { return exit_status(); @@ -562,7 +593,8 @@ int main(int, char**) { vector s_server_test; vector m_server_test; - const string docker_mode = getenv("DOCKER_MODE"); + const char * env_str = getenv("DOCKER_MODE"); + const string docker_mode { env_str ? env_str : "" }; if (docker_mode.find("dns") == docker_mode.size() - 3) { s_server_test.assign({ { "mysql1.infra-mysql57", 3306 } }); m_server_test.assign({ { "mysql1.infra-mysql57", 3306 }, { "mysql2.infra-mysql57", 3306 }, { "mysql3.infra-mysql57", 3306 } }); @@ -579,7 +611,7 @@ int main(int, char**) { } diag("Performing 'check_backend_conns()' for servers: '%s'", nlohmann::json(s_server_test).dump().c_str()); - int s_server_rc = check_backend_conns(cl, test_params, 0, s_server_test); + int s_server_rc = check_backend_conns(test_params, 0, s_server_test); if (s_server_rc == EXIT_SUCCESS) { diag("Cleaning up previous backend connections..."); string query = "UPDATE mysql_servers SET max_connections=0"; @@ -610,7 +642,7 @@ int main(int, char**) { if (w_res == EXIT_SUCCESS) { diag("Performing 'check_backend_conns()' for servers: '%s'", nlohmann::json(m_server_test).dump().c_str()); - int m_server_rc = check_backend_conns(cl, test_params, 1, m_server_test); + int m_server_rc = check_backend_conns(test_params, 1, m_server_test); if (m_server_rc == EXIT_FAILURE) { diag("'check_backend_conns()' failed for servers: '%s'", nlohmann::json(s_server_test).dump().c_str()); } @@ -627,7 +659,7 @@ int main(int, char**) { const srv_cfg& old_srv_config = server_old_config.second; srv_cfg _tmp_conf {}; - int cfg_res = change_mysql_cfg(cl, res_row[0], res_row[1], old_srv_config, _tmp_conf); + int cfg_res = change_mysql_cfg(res_row[0], res_row[1], old_srv_config, _tmp_conf); if (cfg_res != EXIT_SUCCESS) { return EXIT_FAILURE; } diff --git a/test/tap/tests/test_binlog_fast_forward-t.cpp b/test/tap/tests/test_binlog_fast_forward-t.cpp index 6f9c98befb..689944ba4f 100644 --- a/test/tap/tests/test_binlog_fast_forward-t.cpp +++ b/test/tap/tests/test_binlog_fast_forward-t.cpp @@ -106,27 +106,33 @@ std::vector repl_queries_set1 = { // only 1 set, maybe more later int setup_replication(int server_id, bool frontend_ssl, bool backend_ssl, std::vector& mysql_queries) { diag("Running %s using server_id %d , frontend_ssl = %s , backend_ssl = %s", __func__ , server_id, (frontend_ssl ? "TRUE" : "FALSE") , (backend_ssl ? "TRUE" : "FALSE")); - MYSQL * mysql = mysql_init(NULL); std::vector admin_queries = {}; admin_queries.push_back(std::string("SET mysql-have_ssl='") + std::string(frontend_ssl ? "true" : "false") + "'"); admin_queries.push_back("LOAD MYSQL VARIABLES TO RUNTIME"); + admin_queries.push_back(std::string("UPDATE mysql_users SET use_ssl=") + std::string(frontend_ssl ? "1" : "0") + " WHERE username = 'root'"); + admin_queries.push_back("LOAD MYSQL USERS TO RUNTIME"); admin_queries.push_back(std::string("UPDATE mysql_servers SET use_ssl=") + std::string(backend_ssl ? "1" : "0")); admin_queries.push_back("LOAD MYSQL SERVERS TO RUNTIME"); - if (!mysql) + if (run_queries_sets(admin_queries, mysqladmin, "Running on Admin")) return exit_status(); - if (frontend_ssl) { + + MYSQL * mysql = mysql_init(NULL); + diag("Connecting: cl.root_username='%s' frontend_ssl=%d", cl.root_username,frontend_ssl); + if (frontend_ssl) mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); - } -// if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - if (!mysql_real_connect(mysql, cl.root_host, cl.root_username, cl.root_password, NULL, cl.root_port, NULL, 0)) { - //if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, 3306, NULL, 0)) { + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(mysql, cl.host, cl.root_username, cl.root_password, NULL, cl.root_port, NULL, 0)) { fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(frontend_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } - if (run_queries_sets(admin_queries, mysqladmin, "Running on Admin")) - return exit_status(); + if (run_queries_sets(mysql_queries, mysql, "Running on MySQL")) return exit_status(); int rc = pull_replication(mysql, server_id); @@ -139,19 +145,21 @@ int setup_replication(int server_id, bool frontend_ssl, bool backend_ssl, std::v int main(int argc, char** argv) { - if(cl.getEnv()) - return exit_status(); - - plan(8); // each test has 2 OK + plan(2+4*2 + 8); // each test has 2 OK mysqladmin = mysql_init(NULL); - if (!mysqladmin) - return exit_status(); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysqladmin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysqladmin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysqladmin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysqladmin)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysqladmin)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysqladmin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysqladmin->net.compress, "Compression: (%d)", mysqladmin->net.compress); } const std::vector query_rules = { "INSERT OR IGNORE INTO mysql_query_rules (rule_id,active,match_digest,destination_hostgroup,multiplex,apply) VALUES\ diff --git a/test/tap/tests/test_binlog_reader-t.cpp b/test/tap/tests/test_binlog_reader-t.cpp index 82eaf7f619..4732d51aef 100644 --- a/test/tap/tests/test_binlog_reader-t.cpp +++ b/test/tap/tests/test_binlog_reader-t.cpp @@ -44,6 +44,8 @@ using std::map; using nlohmann::json; +CommandLine cl; + int create_testing_tables(MYSQL* mysql_server) { // Create the testing database MYSQL_QUERY(mysql_server, "CREATE DATABASE IF NOT EXISTS test"); @@ -124,13 +126,22 @@ map> extract_hosgtroups_stats(const vectornet.compress, "Compression: (%d)", select_conn->net.compress); } for (uint32_t i = 0; i < NUM; i++) { @@ -154,7 +165,7 @@ int perform_rnd_selects(const CommandLine& cl, uint32_t NUM) { return EXIT_SUCCESS; } -int check_gitd_tracking(const CommandLine& cl, MYSQL* proxysql_mysql, MYSQL* proxysql_admin) { +int check_gitd_tracking(MYSQL* proxysql_mysql, MYSQL* proxysql_admin) { // Check that all queries were routed to the correct hostgroup MYSQL_QUERY(proxysql_admin, "SELECT hostgroup, queries, Queries_GTID_sync FROM stats.stats_mysql_connection_pool"); MYSQL_RES* conn_pool_stats_myres = mysql_store_result(proxysql_admin); @@ -198,7 +209,7 @@ int check_gitd_tracking(const CommandLine& cl, MYSQL* proxysql_mysql, MYSQL* pro mysql_free_result(mysql_store_result(proxysql_admin)); // Perform random selects, no prior updates in the connection, no GTID tracking should take place - rc = perform_rnd_selects(cl, NUM_CHECKS / 5); + rc = perform_rnd_selects(NUM_CHECKS / 5); if (rc != EXIT_SUCCESS) { return EXIT_FAILURE; } // Update stats @@ -228,12 +239,6 @@ int check_gitd_tracking(const CommandLine& cl, MYSQL* proxysql_mysql, MYSQL* pro } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } bool stop_on_failure = false; @@ -244,19 +249,37 @@ int main(int argc, char** argv) { if (stop_on_failure) { plan(0); } else { - plan(3); + plan(2+2+2 + 3); } MYSQL* proxysql_mysql = mysql_init(NULL); - MYSQL* proxysql_admin = mysql_init(NULL); - + diag("Connecting: username='%s' cl.use_ssl=%d cl.compression=%d", "sbtest8", cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_mysql, cl.host, "sbtest8", "sbtest8", NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_mysql->net.compress, "Compression: (%d)", proxysql_mysql->net.compress); } + + MYSQL* proxysql_admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } vector> failed_rows {}; @@ -313,7 +336,7 @@ int main(int argc, char** argv) { { if (stop_on_failure == 0) { - check_gitd_tracking(cl, proxysql_mysql, proxysql_admin); + check_gitd_tracking(proxysql_mysql, proxysql_admin); const double pct_fail_rate = failed_rows.size() * 100 / static_cast(NUM_CHECKS); ok( diff --git a/test/tap/tests/test_binlog_reader_uses_previous_hostgroup-t.cpp b/test/tap/tests/test_binlog_reader_uses_previous_hostgroup-t.cpp index 2015e47163..8f15dec4d2 100644 --- a/test/tap/tests/test_binlog_reader_uses_previous_hostgroup-t.cpp +++ b/test/tap/tests/test_binlog_reader_uses_previous_hostgroup-t.cpp @@ -22,10 +22,30 @@ using std::vector; using std::string; +CommandLine cl; + const char* QUERY_CONN_CLOSED { "SELECT ConnOk - ConnFree FROM stats.stats_mysql_connection_pool WHERE hostgroup=%d" }; + +void * work(void *arg) { + sleep(30); + diag("Timeout! - exiting..."); + exit(EXIT_FAILURE); + return NULL; +} + +int run_funct_timeout(void *(*start_routine)(void *), int timeout) { + // we run the test on a separate thread because we have a built-in timeout + pthread_t thread_id; + if (pthread_create(&thread_id, NULL, start_routine, NULL)) { + fprintf(stderr, "Error calling pthread_create()"); + return EXIT_FAILURE; + } + return 0; +} + int conn_pool_hg_stat_conn_closed(MYSQL* proxy_admin, int hg_id, vector& out_stats) { MYSQL_RES* my_stats_res = NULL; @@ -61,19 +81,25 @@ int conn_pool_hg_stat_conn_closed(MYSQL* proxy_admin, int hg_id, vector& } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } MYSQL* proxy_admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_admin->net.compress, "Compression: (%d)", proxy_admin->net.compress); } + plan(2 + 1); + run_funct_timeout(work, 30); + const int destination_hostgroup = 2; string query; query = "DELETE FROM mysql_servers WHERE hostgroup_id=" + std::to_string(destination_hostgroup); diff --git a/test/tap/tests/test_change_user-t.cpp b/test/tap/tests/test_change_user-t.cpp index 0f876234bc..1fb8ee991d 100644 --- a/test/tap/tests/test_change_user-t.cpp +++ b/test/tap/tests/test_change_user-t.cpp @@ -35,6 +35,8 @@ using nlohmann::json; #define NCONNS 16 +CommandLine cl; + int run_queries_sets(std::vector& queries, MYSQL *my, const std::string& message_prefix) { for (std::vector::iterator it = queries.begin(); it != queries.end(); it++) { std::string q = *it; @@ -193,7 +195,6 @@ int TestSet1(const CommandLine& cl, const char *plugin, bool test_ssl , bool tes } int main(int argc, char** argv) { - CommandLine cl; int p = 1; // admin connection // with mysql-default_authentication_plugin = mysql_native_password @@ -229,11 +230,6 @@ int main(int argc, char** argv) { plan(p); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - int rc = 0; admin = mysql_init(NULL); { diff --git a/test/tap/tests/test_clickhouse_server-t.cpp b/test/tap/tests/test_clickhouse_server-t.cpp index d943442e97..78b1b2ef42 100644 --- a/test/tap/tests/test_clickhouse_server-t.cpp +++ b/test/tap/tests/test_clickhouse_server-t.cpp @@ -35,6 +35,8 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + using query_spec = std::tuple; const int proxysql_clickhouse_port = 6090; @@ -70,18 +72,24 @@ int set_clickhouse_port(MYSQL *pa, int p) { int test_crash(const char *host, int port) { // try to connect and run queries while there is no backend for (int i=0; inet.compress, "Compression: (%d)", proxysql_clickhouse->net.compress); } + char * q = (char *)"SELECT 1"; int query_err = mysql_query(proxysql_clickhouse, q); MYSQL_RES * result = mysql_store_result(proxysql_clickhouse); @@ -96,6 +104,7 @@ int test_crash(const char *host, int port) { } return 0; } + int create_users(MYSQL *pa) { diag("Emptying clickhouse_users table"); MYSQL_QUERY(pa, "DELETE FROM clickhouse_users"); @@ -362,11 +371,11 @@ std::vector ch_intf_queries { }; int main(int argc, char** argv) { - CommandLine cl; // plan as many tests as queries plan( - crash_loops + 7*2 // connections + + crash_loops + 2 /* Fail to connect with wrong username and password */ + 4 // during LOAD USERS TO RUNTIME + 4 // during LOAD USERS TO RUNTIME , second time @@ -377,28 +386,22 @@ int main(int argc, char** argv) { + 1 /* Connect to new setup interface */ ); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - - MYSQL* proxysql_admin = mysql_init(NULL); - // Connect to ProxySQL Admin and check current clickhouse configuration - if ( - !mysql_real_connect( - proxysql_admin, cl.host, cl.admin_username, cl.admin_password, - NULL, cl.admin_port, NULL, 0 - ) - ) { - fprintf( - stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, - mysql_error(proxysql_admin) - ); + MYSQL* proxysql_admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } - create_users(proxysql_admin); create_users(proxysql_admin); // to trigger more code coverage @@ -428,12 +431,12 @@ int main(int argc, char** argv) { // Connect with invalid username std::string inv_user_err {}; bool failed_to_connect = false; - if ( - !mysql_real_connect( - proxysql_clickhouse, host_port.first.c_str(), "foobar_user", cl.password, - NULL, host_port.second, NULL, 0 - ) - ) { + diag("Connecting: username='%s' cl.use_ssl=%d cl.compression=%d", "foobar_user", cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_clickhouse, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_clickhouse, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(proxysql_clickhouse, host_port.first.c_str(), "foobar_user", cl.password, NULL, host_port.second, NULL, 0)) { inv_user_err = mysql_error(proxysql_clickhouse); failed_to_connect = true; } @@ -451,12 +454,12 @@ int main(int argc, char** argv) { // Connect with invalid password std::string inv_pass_err {}; failed_to_connect = false; - if ( - !mysql_real_connect( - proxysql_clickhouse, host_port.first.c_str(), credentials[0].first.c_str(), "foobar_pass", - NULL, host_port.second, NULL, 0 - ) - ) { + diag("Connecting: username='%s' cl.use_ssl=%d cl.compression=%d", credentials[0].first.c_str(), cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_clickhouse, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_clickhouse, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(proxysql_clickhouse, host_port.first.c_str(), credentials[0].first.c_str(), "foobar_pass", NULL, host_port.second, NULL, 0)) { inv_pass_err = mysql_error(proxysql_clickhouse); failed_to_connect = true; } @@ -472,17 +475,18 @@ int main(int argc, char** argv) { proxysql_clickhouse = mysql_init(NULL); // Correctly connect to Clickhouse server - if ( - !mysql_real_connect( - proxysql_clickhouse, host_port.first.c_str(), credentials[0].first.c_str(), credentials[0].second.c_str(), - NULL, host_port.second, NULL, 0 - ) - ) { - fprintf( - stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, - mysql_error(proxysql_clickhouse) - ); + diag("Connecting: username='%s' cl.use_ssl=%d cl.compression=%d", credentials[0].first.c_str(), cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_clickhouse, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_clickhouse, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(proxysql_clickhouse, host_port.first.c_str(), credentials[0].first.c_str(), credentials[0].second.c_str(), NULL, host_port.second, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_clickhouse)); goto cleanup; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_clickhouse); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_clickhouse->net.compress, "Compression: (%d)", proxysql_clickhouse->net.compress); } diag("Started performing queries set 1"); @@ -528,14 +532,18 @@ int main(int argc, char** argv) { // Connect with invalid username bool success_to_connect = true; std::string new_intf_conn_err {}; - if ( - !mysql_real_connect( - proxysql_clickhouse, new_host_port.first.c_str(), credentials[1].first.c_str(), credentials[1].second.c_str(), - NULL, new_host_port.second, NULL, 0 - ) - ) { + diag("Connecting: username='%s' cl.use_ssl=%d cl.compression=%d", credentials[1].first.c_str(), cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_clickhouse, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_clickhouse, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(proxysql_clickhouse, new_host_port.first.c_str(), credentials[1].first.c_str(), credentials[1].second.c_str(), NULL, new_host_port.second, NULL, 0)) { new_intf_conn_err = mysql_error(proxysql_clickhouse); success_to_connect = false; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_clickhouse); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_clickhouse->net.compress, "Compression: (%d)", proxysql_clickhouse->net.compress); } ok( diff --git a/test/tap/tests/test_client_limit_error-t.cpp b/test/tap/tests/test_client_limit_error-t.cpp index 6d84f245a7..f41caf415b 100644 --- a/test/tap/tests/test_client_limit_error-t.cpp +++ b/test/tap/tests/test_client_limit_error-t.cpp @@ -60,6 +60,8 @@ const uint32_t NUM_LOOPBACK_ADDRS = 5; using host_cache_entry = std::tuple; +CommandLine cl; + inline unsigned long long realtime_time_s() { time_t __now = time(NULL); return __now; @@ -88,7 +90,7 @@ std::vector get_client_host_cache_entries(MYSQL* proxysql_admi return host_cache_entries; } -int invalid_proxysql_conn(const std::string& addr, const CommandLine& cl) { +int invalid_proxysql_conn(const std::string& addr) { MYSQL* proxysql = mysql_init(NULL); int my_err = EXIT_SUCCESS; @@ -101,7 +103,7 @@ int invalid_proxysql_conn(const std::string& addr, const CommandLine& cl) { return my_err; } -int invalid_proxysql_conn(const std::string& addr, const CommandLine& cl, std::string& err_msg) { +int invalid_proxysql_conn(const std::string& addr, std::string& err_msg) { MYSQL* proxysql = mysql_init(NULL); int my_err = EXIT_SUCCESS; @@ -115,13 +117,22 @@ int invalid_proxysql_conn(const std::string& addr, const CommandLine& cl, std::s return my_err; } -int valid_proxysql_conn(const std::string& addr, const CommandLine& cl, std::string& err_msg) { - MYSQL* proxysql = mysql_init(NULL); +int valid_proxysql_conn(const std::string& addr, std::string& err_msg) { int my_err = EXIT_SUCCESS; + MYSQL* proxysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql, addr.c_str(), cl.username, cl.password, NULL, 6033, NULL, 0)) { my_err = mysql_errno(proxysql); err_msg = mysql_error(proxysql); + } else { + const char * c = mysql_get_ssl_cipher(proxysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql->net.compress, "Compression: (%d)", proxysql->net.compress); } mysql_close(proxysql); @@ -139,7 +150,7 @@ int valid_proxysql_conn(const std::string& addr, const CommandLine& cl, std::str * * @return 'EXIT_SUCCESS' in case of success, 'EXIT_FAILURE' otherwise. */ -int test_cache_filled_by_invalid_conn(const CommandLine& cl, MYSQL* proxysql_admin) { +int test_cache_filled_by_invalid_conn(MYSQL* proxysql_admin) { diag(" START TEST NUMBER 1 "); diag("-------------------------------------------------------------"); @@ -154,7 +165,7 @@ int test_cache_filled_by_invalid_conn(const CommandLine& cl, MYSQL* proxysql_adm const std::string exp_client_addr { "127.0.0.2" }; diag("Performing connection to fill 'client_host_cache'"); - int inv_user_errno = invalid_proxysql_conn(exp_client_addr, cl); + int inv_user_errno = invalid_proxysql_conn(exp_client_addr); if (inv_user_errno == EXIT_SUCCESS) { diag("Expected failure but client connection succeed"); return EXIT_FAILURE; @@ -197,7 +208,7 @@ int test_cache_filled_by_invalid_conn(const CommandLine& cl, MYSQL* proxysql_adm * * @return 'EXIT_SUCCESS' in case of success, 'EXIT_FAILURE' otherwise. */ -int test_cache_entry_count_by_invalid_conn(const CommandLine& cl, MYSQL* proxysql_admin) { +int test_cache_entry_count_by_invalid_conn(MYSQL* proxysql_admin) { printf("\n"); diag(" START TEST NUMBER 2 "); diag("-------------------------------------------------------------"); @@ -210,7 +221,7 @@ int test_cache_entry_count_by_invalid_conn(const CommandLine& cl, MYSQL* proxysq diag("Performing connection to fill 'client_host_cache'"); for (errors = 0; errors < 5; errors++) { - int inv_user_errno = invalid_proxysql_conn(exp_client_addr, cl); + int inv_user_errno = invalid_proxysql_conn(exp_client_addr); if (inv_user_errno == EXIT_SUCCESS) { diag("Expected failure but client connection succeed"); return EXIT_FAILURE; @@ -254,7 +265,7 @@ int test_cache_entry_count_by_invalid_conn(const CommandLine& cl, MYSQL* proxysq * * @return 'EXIT_SUCCESS' in case of success, 'EXIT_FAILURE' otherwise. */ -int test_cache_entry_count_by_mult_invalid_conns(const CommandLine& cl, MYSQL* proxysql_admin) { +int test_cache_entry_count_by_mult_invalid_conns(MYSQL* proxysql_admin) { printf("\n"); diag(" START TEST NUMBER 3 "); diag("-------------------------------------------------------------"); @@ -275,7 +286,7 @@ int test_cache_entry_count_by_mult_invalid_conns(const CommandLine& cl, MYSQL* p for (int i = 2; i < NUM_LOOPBACK_ADDRS; i++) { std::string loopback_addr { "127.0.0." + std::to_string(i) }; for (errors = 0; errors < 2; errors++) { - int inv_user_errno = invalid_proxysql_conn(loopback_addr, cl); + int inv_user_errno = invalid_proxysql_conn(loopback_addr); diag("Client connection failed with error: %d", inv_user_errno); } } @@ -329,7 +340,7 @@ int test_cache_entry_count_by_mult_invalid_conns(const CommandLine& cl, MYSQL* p * * @return 'EXIT_SUCCESS' in case of success, 'EXIT_FAILURE' otherwise. */ -int test_client_exceeding_cache_error_limit(const CommandLine& cl, MYSQL* proxysql_admin) { +int test_client_exceeding_cache_error_limit(MYSQL* proxysql_admin) { printf("\n"); diag(" START TEST NUMBER 4 "); diag("-------------------------------------------------------------"); @@ -354,7 +365,7 @@ int test_client_exceeding_cache_error_limit(const CommandLine& cl, MYSQL* proxys diag("Performing connections to fill 'client_host_cache'"); for (const auto loopback_addr : loopback_addrs) { for (errors = 0; errors < 3; errors++) { - int inv_user_errno = invalid_proxysql_conn(loopback_addr, cl); + int inv_user_errno = invalid_proxysql_conn(loopback_addr); diag("Client connection failed with error: %d", inv_user_errno); } } @@ -408,7 +419,7 @@ int test_client_exceeding_cache_error_limit(const CommandLine& cl, MYSQL* proxys int limit_conn_err = EXIT_SUCCESS; for (int limits = errors; limits < 5 + 1; limits++) { - limit_conn_err = invalid_proxysql_conn(loopback_addr, cl, command_res); + limit_conn_err = invalid_proxysql_conn(loopback_addr, command_res); diag("Client connection failed with error: (%d, %s)", limit_conn_err, command_res.c_str()); } printf("\n"); @@ -463,7 +474,7 @@ int test_client_exceeding_cache_error_limit(const CommandLine& cl, MYSQL* proxys // Client has exceeded maximum connections failure is expected if (i == 4) { std::string conn_err_msg {}; - int limit_conn_err = valid_proxysql_conn(loopback_addr, cl, conn_err_msg); + int limit_conn_err = valid_proxysql_conn(loopback_addr, conn_err_msg); ok( limit_conn_err == 2013, @@ -471,7 +482,7 @@ int test_client_exceeding_cache_error_limit(const CommandLine& cl, MYSQL* proxys ); } else { std::string command_res {}; - int command_err = valid_proxysql_conn(loopback_addr, cl, command_res); + int command_err = valid_proxysql_conn(loopback_addr, command_res); ok( command_err == 0, "Connection should succeed for clients which limit haven't been exceeded." @@ -501,7 +512,7 @@ int test_client_exceeding_cache_error_limit(const CommandLine& cl, MYSQL* proxys * * @return 'EXIT_SUCCESS' in case of success, 'EXIT_FAILURE' otherwise. */ -int test_client_exceeding_changed_error_limit(const CommandLine& cl, MYSQL* proxysql_admin) { +int test_client_exceeding_changed_error_limit(MYSQL* proxysql_admin) { printf("\n"); diag(" START TEST NUMBER 5 "); diag("-------------------------------------------------------------"); @@ -525,7 +536,7 @@ int test_client_exceeding_changed_error_limit(const CommandLine& cl, MYSQL* prox diag("Performing connections to fill 'client_host_cache'"); for (int i = 0; i < 4; i++) { - int inv_user_errno = invalid_proxysql_conn(loopback_addr, cl); + int inv_user_errno = invalid_proxysql_conn(loopback_addr); diag("Client connection failed with error: %d", inv_user_errno); } @@ -537,7 +548,7 @@ int test_client_exceeding_changed_error_limit(const CommandLine& cl, MYSQL* prox printf("\n"); std::string conn_err_msg {}; - int valid_user_err = valid_proxysql_conn(loopback_addr, cl, conn_err_msg); + int valid_user_err = valid_proxysql_conn(loopback_addr, conn_err_msg); diag("Client connection failed with error: (%d, %s)", valid_user_err, conn_err_msg.c_str()); ok( @@ -559,7 +570,7 @@ int test_client_exceeding_changed_error_limit(const CommandLine& cl, MYSQL* prox * * @return 'EXIT_SUCCESS' in case of success, 'EXIT_FAILURE' otherwise. */ -int test_cache_size_decrease_by_new_connections(const CommandLine& cl, MYSQL* proxysql_admin) { +int test_cache_size_decrease_by_new_connections(MYSQL* proxysql_admin) { printf("\n"); diag(" START TEST NUMBER 6 "); diag("-------------------------------------------------------------"); @@ -587,7 +598,7 @@ int test_cache_size_decrease_by_new_connections(const CommandLine& cl, MYSQL* pr diag("Performing connections to fill 'client_host_cache'"); for (const auto loopback_addr : loopback_addrs) { for (errors = 0; errors < 3; errors++) { - int inv_user_errno = invalid_proxysql_conn(loopback_addr, cl); + int inv_user_errno = invalid_proxysql_conn(loopback_addr); diag("Client connection failed with error: %d", inv_user_errno); } } @@ -605,7 +616,7 @@ int test_cache_size_decrease_by_new_connections(const CommandLine& cl, MYSQL* pr std::string loopback_addr { "127.0.0.4" }; printf("\n"); - int inv_user_err = invalid_proxysql_conn(loopback_addr, cl); + int inv_user_err = invalid_proxysql_conn(loopback_addr); diag("Client connection failed with error: %d", inv_user_err); std::vector updated_entries { @@ -659,7 +670,7 @@ int test_cache_size_decrease_by_new_connections(const CommandLine& cl, MYSQL* pr const std::string new_member { "127.0.0.5" }; - inv_user_err = invalid_proxysql_conn(new_member, cl); + inv_user_err = invalid_proxysql_conn(new_member); diag("Client connection failed with error: %d", inv_user_err); diag("2.1 Checking that the address hasn't been added"); @@ -697,7 +708,7 @@ int test_cache_size_decrease_by_new_connections(const CommandLine& cl, MYSQL* pr const std::string forgotten_address { "127.0.0.4" }; std::string err_msg {}; - int valid_conn_err = valid_proxysql_conn(forgotten_address, cl, err_msg); + int valid_conn_err = valid_proxysql_conn(forgotten_address, err_msg); if (valid_conn_err) { diag("Failed to execute 'valid_proxysql_conn' at ('%s':'%d')", __FILE__, __LINE__); } @@ -720,7 +731,7 @@ int test_cache_size_decrease_by_new_connections(const CommandLine& cl, MYSQL* pr return EXIT_SUCCESS; } -int create_tcp_conn(const CommandLine& cl, const std::string& addr) { +int create_tcp_conn(const std::string& addr) { int sock = 0; struct sockaddr_in serv_addr; @@ -753,7 +764,7 @@ int create_tcp_conn(const CommandLine& cl, const std::string& addr) { * * @return 'EXIT_SUCCESS' in case of success, 'EXIT_FAILURE' otherwise. */ -int test_cache_populated_timeout_conns(const CommandLine& cl, MYSQL* proxysql_admin) { +int test_cache_populated_timeout_conns(MYSQL* proxysql_admin) { printf("\n"); diag(" START TEST NUMBER 7 "); diag("-------------------------------------------------------------"); @@ -784,7 +795,7 @@ int test_cache_populated_timeout_conns(const CommandLine& cl, MYSQL* proxysql_ad std::vector sockets {}; for (int i = 2; i < NUM_LOOPBACK_ADDRS; i++) { std::string loopback_addr { "127.0.0." + std::to_string(i) }; - int inv_user_errno = create_tcp_conn(cl, loopback_addr); + int inv_user_errno = create_tcp_conn(loopback_addr); diag("Client connection failed with error: %d", inv_user_errno); } sleep((client_timeout / 1000) * 2 + 1); @@ -804,7 +815,7 @@ int test_cache_populated_timeout_conns(const CommandLine& cl, MYSQL* proxysql_ad for (int i = 2; i < NUM_LOOPBACK_ADDRS; i++) { std::string loopback_addr { "127.0.0." + std::to_string(i) }; for (errors = 0; errors < 2; errors++) { - int inv_user_errno = create_tcp_conn(cl, loopback_addr); + int inv_user_errno = create_tcp_conn(loopback_addr); diag("Client connection timeout out with error: %d", inv_user_errno); } } @@ -839,39 +850,24 @@ int test_cache_populated_timeout_conns(const CommandLine& cl, MYSQL* proxysql_ad } int main(int, char**) { - int res = 0; - CommandLine cl; - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } + int res = 0; - plan(30); + plan(5*2 + 30); MYSQL* proxysql_admin = mysql_init(NULL); - - // Initialize connections - if (!proxysql_admin) { - fprintf( - stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, - mysql_error(proxysql_admin) - ); - return -1; - } - - // Connect to ProxySQL Admin - if ( - !mysql_real_connect( - proxysql_admin, cl.host, cl.admin_username, cl.admin_password, - NULL, cl.admin_port, NULL, 0 - ) - ) { - fprintf( - stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, - mysql_error(proxysql_admin) - ); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } // Setup the virtual namespaces to be used by the test @@ -921,13 +917,13 @@ int main(int, char**) { printf("\n"); - test_cache_filled_by_invalid_conn(cl, proxysql_admin); - test_cache_entry_count_by_invalid_conn(cl, proxysql_admin); - test_cache_entry_count_by_mult_invalid_conns(cl, proxysql_admin); - test_client_exceeding_cache_error_limit(cl, proxysql_admin); - test_client_exceeding_changed_error_limit(cl, proxysql_admin); - test_cache_size_decrease_by_new_connections(cl, proxysql_admin); - test_cache_populated_timeout_conns(cl, proxysql_admin); + test_cache_filled_by_invalid_conn(proxysql_admin); + test_cache_entry_count_by_invalid_conn(proxysql_admin); + test_cache_entry_count_by_mult_invalid_conns(proxysql_admin); + test_client_exceeding_cache_error_limit(proxysql_admin); + test_client_exceeding_changed_error_limit(proxysql_admin); + test_cache_size_decrease_by_new_connections(proxysql_admin); + test_cache_populated_timeout_conns(proxysql_admin); cleanup: // Cleanup the virtual namespaces to be used by the test diff --git a/test/tap/tests/test_cluster1-t.cpp b/test/tap/tests/test_cluster1-t.cpp index 089c4bd82a..7ea23c3394 100644 --- a/test/tap/tests/test_cluster1-t.cpp +++ b/test/tap/tests/test_cluster1-t.cpp @@ -10,6 +10,7 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; /* * this test assumes that this proxysql instance is part of a 10 nodes cluster @@ -139,19 +140,24 @@ int module_in_sync( return 1; } -int create_connections(CommandLine& cl) { +int create_connections() { for (int i = 0; i < cluster_ports.size() ; i++) { + MYSQL * mysql = mysql_init(NULL); - if (!mysql) { + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(mysql, cl.host, cl.admin_username, cl.admin_password, NULL, cluster_ports[i], NULL, CLIENT_COMPRESS)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(mysql->net.compress == 1, "Compression: (%d)", mysql->net.compress); } - mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); - if (!mysql_real_connect(mysql, cl.host, cl.admin_username, cl.admin_password, NULL, cluster_ports[i], NULL, CLIENT_SSL|CLIENT_COMPRESS)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); - return exit_status(); - } conns.push_back(mysql); } return 0; @@ -179,28 +185,25 @@ int trigger_sync_and_check(MYSQL *mysql, std::string modname, const char *update } int main(int argc, char** argv) { - CommandLine cl; int np = 8; np += 4*5*(4+(cluster_ports.size()-4)); plan(np); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - MYSQL* proxysql_admin = mysql_init(NULL); - // Initialize connections - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return -1; - } - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } std::vector modules = { @@ -239,7 +242,7 @@ int main(int argc, char** argv) { MYSQL_RES* proxy_res; int rc = 0; - rc = create_connections(cl); + rc = create_connections(); if (rc != 0) { return exit_status(); } diff --git a/test/tap/tests/test_cluster_sync-t.cpp b/test/tap/tests/test_cluster_sync-t.cpp index 32a449fc30..69ea13c14a 100644 --- a/test/tap/tests/test_cluster_sync-t.cpp +++ b/test/tap/tests/test_cluster_sync-t.cpp @@ -100,6 +100,8 @@ using std::tuple; using std::fstream; using std::function; +CommandLine cl; + /** * @brief Helper function to verify that the sync of a table (or variable) have been performed. * @@ -157,7 +159,7 @@ const uint32_t SYNC_TIMEOUT = 10; const uint32_t CONNECT_TIMEOUT = 10; const uint32_t R_PORT = 16062; -int setup_config_file(const CommandLine& cl) { +int setup_config_file() { const std::string t_fmt_config_file = std::string(cl.workdir) + "test_cluster_sync_config/test_cluster_sync-t.cnf"; const std::string fmt_config_file = std::string(cl.workdir) + "test_cluster_sync_config/test_cluster_sync.cnf"; const std::string datadir_path = std::string(cl.workdir) + "test_cluster_sync_config"; @@ -244,17 +246,24 @@ int setup_config_file(const CommandLine& cl) { return 0; } -int check_nodes_sync( - const CommandLine& cl, const vector& core_nodes, const string& check_query, uint32_t sync_timeout -) { +int check_nodes_sync(const vector& core_nodes, const string& check_query, uint32_t sync_timeout) { for (const auto& node : core_nodes) { const string host { node[0] }; const int port = std::stol(node[1]); MYSQL* c_node_admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(c_node_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(c_node_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(c_node_admin, host.c_str(), cl.admin_username, cl.admin_password, NULL, port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(c_node_admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(c_node_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == c_node_admin->net.compress, "Compression: (%d)", c_node_admin->net.compress); } int not_synced = sync_checker(c_node_admin, { check_query }, sync_timeout); @@ -273,10 +282,7 @@ const std::string t_debug_query = "mysql -u%s -p%s -h %s -P%d -C -e \"%s\""; using mysql_server_tuple = tuple; -int check_mysql_servers_sync( - const CommandLine& cl, MYSQL* proxy_admin, MYSQL* r_proxy_admin, - const vector& insert_mysql_servers_values -) { +int check_mysql_servers_sync(MYSQL* proxy_admin, MYSQL* r_proxy_admin, const vector& insert_mysql_servers_values) { MYSQL_QUERY(proxy_admin, "SET mysql-monitor_enabled='false'"); MYSQL_QUERY(proxy_admin, "LOAD MYSQL VARIABLES TO RUNTIME"); @@ -1058,14 +1064,8 @@ int check_modules_checksums_sync( int main(int, char**) { int res = 0; - CommandLine cl; std::atomic save_proxy_stderr(false); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - const size_t num_pls = module_sync_payloads.size(); const size_t all_mod_sync_checks = ((5+(3*(num_pls-1)))*(num_pls-1))*2 + (5+(3*(num_pls-1))); @@ -1082,17 +1082,18 @@ int main(int, char**) { const std::string fmt_config_file = std::string(cl.workdir) + "test_cluster_sync_config/test_cluster_sync.cnf"; MYSQL* proxy_admin = mysql_init(NULL); - - // Initialize connections - if (!proxy_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_admin)); - return EXIT_FAILURE; - } - - // Connnect to local proxysql + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_admin->net.compress, "Compression: (%d)", proxy_admin->net.compress); } const std::string t_update_proxysql_servers { @@ -1103,7 +1104,7 @@ int main(int, char**) { string_format(t_update_proxysql_servers, update_proxysql_servers, cl.host, cl.admin_port); // Setup the config file using the env variables in 'CommandLine' - if (setup_config_file(cl)) { + if (setup_config_file()) { return EXIT_FAILURE; } @@ -1127,7 +1128,7 @@ int main(int, char**) { check_no_primary_query, cl.host, cl.admin_port ); - int check_res = check_nodes_sync(cl, core_nodes, check_no_primary_query, SYNC_TIMEOUT); + int check_res = check_nodes_sync(core_nodes, check_no_primary_query, SYNC_TIMEOUT); if (check_res != EXIT_SUCCESS) { return EXIT_FAILURE; } // 4. Remove all current servers from primary instance (only secondary sync matters) @@ -1136,7 +1137,7 @@ int main(int, char**) { MYSQL_QUERY(proxy_admin, "LOAD PROXYSQL SERVERS TO RUNTIME"); // Launch proxysql with cluster config - std::thread proxy_replica_th([&save_proxy_stderr, &cl] () { + std::thread proxy_replica_th([&save_proxy_stderr] () { const string replica_stderr { string(cl.workdir) + "test_cluster_sync_config/cluster_sync_node_stderr.txt" }; const std::string proxysql_db = std::string(cl.workdir) + "test_cluster_sync_config/proxysql.db"; const std::string stats_db = std::string(cl.workdir) + "test_cluster_sync_config/proxysql_stats.db"; @@ -1196,7 +1197,7 @@ int main(int, char**) { std::make_tuple(1001, "127.0.0.1", 13307, 13, "OFFLINE_SOFT", 2, 1, 500, 300, 1, 200, "") }; - check_mysql_servers_sync(cl, proxy_admin, r_proxy_admin, insert_mysql_servers_values); + check_mysql_servers_sync(proxy_admin, r_proxy_admin, insert_mysql_servers_values); vector insert_mysql_servers_values_2 { std::make_tuple(1000, "127.0.0.1", 13306, 12, "ONLINE", 1, 1, 1000, 300, 1, 200, "mysql_1"), @@ -1205,7 +1206,7 @@ int main(int, char**) { std::make_tuple(1003, "127.0.0.1", 13309, 15, "OFFLINE_SOFT", 1, 0, 500, 300, 1, 200, "mysql_4_offline") }; - check_mysql_servers_sync(cl, proxy_admin, r_proxy_admin, insert_mysql_servers_values_2); + check_mysql_servers_sync(proxy_admin, r_proxy_admin, insert_mysql_servers_values_2); vector insert_mysql_servers_values_3 { std::make_tuple(1000, "127.0.0.1", 13306, 12, "ONLINE", 1, 1, 1000, 300, 1, 200, "mysql_1"), @@ -1214,7 +1215,7 @@ int main(int, char**) { std::make_tuple(1003, "127.0.0.1", 13309, 15, "OFFLINE_HARD", 1, 0, 500, 300, 1, 200, "mysql_4_offline") }; - check_mysql_servers_sync(cl, proxy_admin, r_proxy_admin, insert_mysql_servers_values_3); + check_mysql_servers_sync(proxy_admin, r_proxy_admin, insert_mysql_servers_values_3); } { @@ -2645,10 +2646,14 @@ int main(int, char**) { for (const auto& row : core_nodes) { const string host { row[0] }; const int port = std::stol(row[1]); - MYSQL* c_node_admin = mysql_init(NULL); + MYSQL* c_node_admin = mysql_init(NULL); diag("RESTORING: Inserting into node '%s:%d'", host.c_str(), port); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(c_node_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(c_node_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(c_node_admin, host.c_str(), cl.admin_username, cl.admin_password, NULL, port, NULL, 0)) { const string err_msg { "Connection to core node failed with '" + string { mysql_error(c_node_admin) } + "'. Retrying..." @@ -2656,6 +2661,10 @@ int main(int, char**) { fprintf(stderr, "File %s, line %d, Error: `%s`\n", __FILE__, __LINE__, err_msg.c_str()); mysql_close(c_node_admin); continue; + } else { + const char * c = mysql_get_ssl_cipher(c_node_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == c_node_admin->net.compress, "Compression: (%d)", c_node_admin->net.compress); } int my_rc = mysql_query(c_node_admin, insert_query.c_str()); @@ -2678,7 +2687,7 @@ int main(int, char**) { ); // Wait for the other nodes to sync ProxySQL servers to include Primary - int check_res = check_nodes_sync(cl, core_nodes, check_no_primary_query, SYNC_TIMEOUT); + int check_res = check_nodes_sync(core_nodes, check_no_primary_query, SYNC_TIMEOUT); if (check_res != EXIT_SUCCESS) { return EXIT_FAILURE; } // Recover the old ProxySQL servers from backup in primary diff --git a/test/tap/tests/test_cluster_sync_mysql_servers-t.cpp b/test/tap/tests/test_cluster_sync_mysql_servers-t.cpp index a1338a4a8d..179c0f1ccc 100644 --- a/test/tap/tests/test_cluster_sync_mysql_servers-t.cpp +++ b/test/tap/tests/test_cluster_sync_mysql_servers-t.cpp @@ -75,6 +75,8 @@ const std::string t_debug_query = "mysql -u%s -p%s -h %s -P%d -C -e \"%s\""; using mysql_server_tuple = std::tuple; using replication_hostgroups_tuple = std::tuple; +CommandLine cl; + /** * @brief Computes the checksum for the resultset, excluding records labeled as 'OFFLINE_HARD', instead of checking each row individually. * @@ -817,14 +819,8 @@ std::vector> queries = { int main(int, char**) { - CommandLine cl; std::atomic save_proxy_stderr(false); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - plan( 1 + 1 // replica instances + 1 // confirming mysql server 127.0.0.1:13306 is a writer + (6 * 5) // calling check_mysql_servers_sync 7 times, 5 differnt checks in each call diff --git a/test/tap/tests/test_com_binlog_dump_enables_fast_forward-t.cpp b/test/tap/tests/test_com_binlog_dump_enables_fast_forward-t.cpp index 581cf39bfd..495d66557b 100644 --- a/test/tap/tests/test_com_binlog_dump_enables_fast_forward-t.cpp +++ b/test/tap/tests/test_com_binlog_dump_enables_fast_forward-t.cpp @@ -9,16 +9,12 @@ #include "tap.h" #include "command_line.h" +CommandLine cl; + int main(int argc, char** argv) { - CommandLine cl; plan(1); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - const std::string user = "root"; const std::string test_deps_path = getenv("TEST_DEPS"); diff --git a/test/tap/tests/test_com_register_slave_enables_fast_forward-t.cpp b/test/tap/tests/test_com_register_slave_enables_fast_forward-t.cpp index 33f3055547..9b47167d28 100644 --- a/test/tap/tests/test_com_register_slave_enables_fast_forward-t.cpp +++ b/test/tap/tests/test_com_register_slave_enables_fast_forward-t.cpp @@ -16,6 +16,9 @@ #include "tap.h" +#include "command_line.h" + +CommandLine cl; int main(int argc, char** argv) { plan(1); diff --git a/test/tap/tests/test_com_reset_connection_com_change_user-t.cpp b/test/tap/tests/test_com_reset_connection_com_change_user-t.cpp index ed81bd5abb..ac8cd31d8c 100644 --- a/test/tap/tests/test_com_reset_connection_com_change_user-t.cpp +++ b/test/tap/tests/test_com_reset_connection_com_change_user-t.cpp @@ -31,6 +31,8 @@ using nlohmann::json; using var_val = std::pair; +CommandLine cl; + const std::vector tracked_variables { "sql_log_bin", "sql_mode", "time_zone", "sql_auto_is_null", "sql_safe_updates", "session_track_gtids", //"max_join_size", "net_write_timeout", "sql_select_limit", "sql_select_limit", "character_set_results", @@ -399,7 +401,7 @@ int get_default_trx_isolation_attr(const std::string& user_attributes, std::stri return EXIT_SUCCESS; } -int test_simple_select_after_reset(MYSQL* proxysql, const CommandLine&, const std::vector& user_configs, bool com_reset=true) { +int test_simple_select_after_reset(MYSQL* proxysql, const std::vector& user_configs, bool com_reset=true) { // Do an initial reset if (com_reset) { int err_code = mysql_reset_connection(proxysql); @@ -444,17 +446,22 @@ int test_simple_select_after_reset(MYSQL* proxysql, const CommandLine&, const st return EXIT_SUCCESS; } -int test_simple_reset_admin(MYSQL*, const CommandLine& cl, const std::vector&, bool) { - MYSQL* admin = mysql_init(NULL); +int test_simple_reset_admin(MYSQL*, const std::vector&, bool) { int res = EXIT_FAILURE; - if ( - !mysql_real_connect( - admin, "127.0.0.1", cl.admin_username, cl.admin_password, "information_schema", cl.admin_port, NULL, 0 - ) - ) { + MYSQL* admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(admin, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(admin, cl.admin_host, cl.admin_username, cl.admin_password, "information_schema", cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == admin->net.compress, "Compression: (%d)", admin->net.compress); } // FIXME: 'COM_CHANGE_USER' doesn't return proper error right now for unsupported sessions types. @@ -473,7 +480,7 @@ int test_simple_reset_admin(MYSQL*, const CommandLine& cl, const std::vector& user_configs, bool com_reset=true) { +int test_transaction_rollback(MYSQL* proxysql, const std::vector& user_configs, bool com_reset=true) { MYSQL_QUERY(proxysql, "DROP TABLE IF EXISTS test.com_reset_connection_trx"); MYSQL_QUERY( proxysql, @@ -528,7 +535,7 @@ int test_transaction_rollback(MYSQL* proxysql, const CommandLine&, const std::ve return EXIT_SUCCESS; } -int test_tracked_variables_cleanup(MYSQL* proxysql, const CommandLine&, const std::vector& user_configs, bool com_reset=true) { +int test_tracked_variables_cleanup(MYSQL* proxysql, const std::vector& user_configs, bool com_reset=true) { // Get the initial values for the tracked variables std::vector var_names {}; std::transform( @@ -710,7 +717,7 @@ int test_tracked_variables_cleanup(MYSQL* proxysql, const CommandLine&, const st return reset_values_match ? 0 : 1; } -int test_user_defined_variables_cleanup(MYSQL* proxysql, const CommandLine&, const std::vector& user_configs, bool com_reset=true) { +int test_user_defined_variables_cleanup(MYSQL* proxysql, const std::vector& user_configs, bool com_reset=true) { // Do an initial reset if (com_reset) { int err_code = mysql_reset_connection(proxysql); @@ -838,7 +845,7 @@ int test_user_defined_variables_cleanup(MYSQL* proxysql, const CommandLine&, con return EXIT_SUCCESS; } -int test_recover_session_values(MYSQL* proxysql, const CommandLine& cl, const std::vector& user_configs, bool com_reset=true) { +int test_recover_session_values(MYSQL* proxysql, const std::vector& user_configs, bool com_reset=true) { std::string username = std::get<0>(user_configs[0]); std::string password = std::get<1>(user_configs[0]); @@ -971,18 +978,25 @@ int test_recover_session_values(MYSQL* proxysql, const CommandLine& cl, const st } } -int test_mysql_server_variables(MYSQL*, const CommandLine& cl, const std::vector& user_configs, bool com_reset=true) { +int test_mysql_server_variables(MYSQL*, const std::vector& user_configs, bool com_reset=true) { // Do an initial reset - MYSQL* mysql = mysql_init(NULL); + MYSQL* mysql = mysql_init(NULL); // Use a known default charset for the connection MARIADB_CHARSET_INFO* latin2_charset = proxysqlTap_find_charset_collate("latin2_general_ci"); mysql->charset = latin2_charset; - -// if (!mysql_real_connect(mysql, cl.host, "root", "root", NULL, 13306, NULL, 0)) { + diag("Connecting: cl.mysql_username='%s' cl.use_ssl=%d cl.compression=%d", cl.mysql_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.mysql_host, cl.mysql_username, cl.mysql_password, NULL, cl.mysql_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } std::vector bef_vars_vals {}; @@ -1111,7 +1125,7 @@ int test_mysql_server_variables(MYSQL*, const CommandLine& cl, const std::vector return reset_values_match ? 0 : 1; } -using test_function = std::function&,bool)>; +using test_function = std::function&, bool)>; std::vector> tests_fns { { "test_simple_select_after_reset", test_simple_select_after_reset }, @@ -1126,39 +1140,41 @@ std::vector> tests_fns { }; int main(int argc, char** argv) { - CommandLine cl; // One 'reset_connection' and 'change_user_test' - plan(tests_fns.size() * 2); - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } + plan(2+2+2+2+2 + tests_fns.size() * 2); MYSQL* proxysql = mysql_init(NULL); - // Use a known default charset for the connection MARIADB_CHARSET_INFO* latin2_charset = proxysqlTap_find_charset_collate("latin2_general_ci"); proxysql->charset = latin2_charset; - - if ( - !mysql_real_connect( - proxysql, "127.0.0.1", cl.username, cl.password, "information_schema", cl.port, NULL, 0 - ) - ) { + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(proxysql, cl.host, cl.username, cl.password, "information_schema", cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql->net.compress, "Compression: (%d)", proxysql->net.compress); } MYSQL* admin = mysql_init(NULL); - if ( - !mysql_real_connect( - admin, "127.0.0.1", cl.admin_username, cl.admin_password, "information_schema", cl.admin_port, NULL, 0 - ) - ) { + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(admin, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(admin, cl.admin_host, cl.admin_username, cl.admin_password, "information_schema", cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == admin->net.compress, "Compression: (%d)", admin->net.compress); } // Set the number of backend connections to '1' for making sure all the operations are performed in the same @@ -1188,10 +1204,18 @@ int main(int argc, char** argv) { }; MYSQL* mysql_server = mysql_init(NULL); -// if (!mysql_real_connect(mysql_server, cl.host, "root", "root", NULL, 13306, NULL, 0)) { + diag("Connecting: cl.mysql_username='%s' cl.use_ssl=%d cl.compression=%d", cl.mysql_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql_server, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql_server, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql_server, cl.mysql_host, cl.mysql_username, cl.mysql_password, NULL, cl.mysql_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql_server)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(mysql_server); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql_server->net.compress, "Compression: (%d)", mysql_server->net.compress); } int err_code = create_extra_users(admin, mysql_server, extra_users); @@ -1207,7 +1231,7 @@ int main(int argc, char** argv) { // Test the 'reset_connection' first try { - test_res = test_fn.second(proxysql, cl, extra_users, true); + test_res = test_fn.second(proxysql, extra_users, true); } catch (const std::exception& ex) { diag("Exception while executing test '%s', exception msg: '%s'", test_fn.first.c_str(), ex.what()); } @@ -1218,7 +1242,7 @@ int main(int argc, char** argv) { // Test the 'change_user' later try { - test_res = test_fn.second(proxysql, cl, extra_users, false); + test_res = test_fn.second(proxysql, extra_users, false); } catch (const std::exception& ex) { diag("Exception while executing test '%s', exception msg: '%s'", test_fn.first.c_str(), ex.what()); } diff --git a/test/tap/tests/test_connection_annotation-t.cpp b/test/tap/tests/test_connection_annotation-t.cpp index 915e20c122..bdc179c19a 100644 --- a/test/tap/tests/test_connection_annotation-t.cpp +++ b/test/tap/tests/test_connection_annotation-t.cpp @@ -17,25 +17,40 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + int main(int argc, char** argv) { - CommandLine cl; - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } + plan(2+2 + 1); - plan(1); MYSQL* proxysql_mysql = mysql_init(NULL); - MYSQL* proxysql_admin = mysql_init(NULL); - + diag("Connecting: cl.root_username='%s' cl.use_ssl=%d cl.compression=%d", cl.root_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_mysql, cl.root_host, cl.root_username, cl.root_password, NULL, cl.root_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_mysql->net.compress, "Compression: (%d)", proxysql_mysql->net.compress); } + + MYSQL* proxysql_admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } const char* stats_mysql_connection_pool = "SELECT COUNT(*) FROM (SELECT ConnFree FROM stats.stats_mysql_connection_pool WHERE hostgroup=1) WHERE ConnFree >= 1"; diff --git a/test/tap/tests/test_csharp_connector_support-t.cpp b/test/tap/tests/test_csharp_connector_support-t.cpp index a6a1168fe7..16cc17df31 100644 --- a/test/tap/tests/test_csharp_connector_support-t.cpp +++ b/test/tap/tests/test_csharp_connector_support-t.cpp @@ -12,24 +12,25 @@ #include "command_line.h" #include "utils.h" -int main(int argc, char** argv) { - CommandLine cl; +CommandLine cl; - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } +int main(int argc, char** argv) { - plan(4); + plan(2 + 4); MYSQL* proxysql_admin = mysql_init(NULL); - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return -1; - } + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } // Test the new introduced query "SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP())" diff --git a/test/tap/tests/test_debug_filters-t.cpp b/test/tap/tests/test_debug_filters-t.cpp index 559f73b653..7ca6d90924 100644 --- a/test/tap/tests/test_debug_filters-t.cpp +++ b/test/tap/tests/test_debug_filters-t.cpp @@ -31,22 +31,45 @@ using std::pair; using std::vector; using std::tuple; -int create_and_close_proxy_conn(const CommandLine& cl) { +CommandLine cl; + +int create_and_close_proxy_conn() { + MYSQL* proxysql_mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_mysql->net.compress, "Compression: (%d)", proxysql_mysql->net.compress); } + mysql_close(proxysql_mysql); return EXIT_SUCCESS; } -int set_statement_query(const CommandLine& cl) { +int set_statement_query() { + MYSQL* proxysql_mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_mysql->net.compress, "Compression: (%d)", proxysql_mysql->net.compress); } MYSQL_QUERY(proxysql_mysql, "SET character_set_results='utf8'"); @@ -131,20 +154,14 @@ int check_log_line(const function& proxy_action, const string& err_id, c } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } diag("This test is now disabled because the plan is to have debugging always enabled"); plan(1); ok(1,"This test is now disabled because the plan is to have debugging always enabled"); return exit_status(); - const auto create_conn_action = [&cl]() -> int { return create_and_close_proxy_conn(cl); }; - const auto set_statement_action = [&cl]() -> int { return set_statement_query(cl); }; + const auto create_conn_action = []() -> int { return create_and_close_proxy_conn(); }; + const auto set_statement_action = []() -> int { return set_statement_query(); }; vector>> regexes_and_actions { { "mysql_connection", "~MySQL_Connection", create_conn_action }, @@ -158,13 +175,21 @@ int main(int argc, char** argv) { { "UPDATE debug_filters SET line=0,funct=''", "Filter should work using just 'filename'" }, }; - plan(regexes_and_actions.size() + regexes_and_actions.size()*filter_combinations.size()); + plan(2 + 3*regexes_and_actions.size() + 3*regexes_and_actions.size()*filter_combinations.size()); MYSQL* proxysql_admin = mysql_init(NULL); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } // Enable debugging levels for the modules to be queried @@ -239,7 +264,7 @@ int main(int argc, char** argv) { MYSQL_QUERY(proxysql_admin, "LOAD DEBUG TO RUNTIME"); - const auto proxy_action = [&cl]() -> int { return create_and_close_proxy_conn(cl); }; + const auto proxy_action = []() -> int { return create_and_close_proxy_conn(); }; int c_res = check_log_line(proxy_action, err_id, f_path, filter_comb.second); if (c_res != EXIT_SUCCESS) { goto cleanup; } diff --git a/test/tap/tests/test_default_conn_collation-t.cpp b/test/tap/tests/test_default_conn_collation-t.cpp index a130ac1307..00c7f402a4 100644 --- a/test/tap/tests/test_default_conn_collation-t.cpp +++ b/test/tap/tests/test_default_conn_collation-t.cpp @@ -18,6 +18,9 @@ using std::string; +CommandLine cl; + + const MARIADB_CHARSET_INFO * proxysql_find_charset_nr(unsigned int nr) { const MARIADB_CHARSET_INFO * c = mariadb_compiled_charsets; do { @@ -29,21 +32,8 @@ const MARIADB_CHARSET_INFO * proxysql_find_charset_nr(unsigned int nr) { return NULL; } -int check_all_collations(const CommandLine& cl, MYSQL* admin) { +int check_all_collations(MYSQL* admin) { const MARIADB_CHARSET_INFO* c = mariadb_compiled_charsets; - uint32_t num_tests = 0; - - { - mysql_query(admin, "SELECT COUNT(*) FROM mysql_collations WHERE id < 256"); - MYSQL_RES* myres = mysql_store_result(admin); - MYSQL_ROW myrow = mysql_fetch_row(myres); - - if (myrow && myrow[0]) { - num_tests = atoi(myrow[0]); - } - } - - plan(num_tests); do { if (c[0].nr > 255) { @@ -61,10 +51,18 @@ int check_all_collations(const CommandLine& cl, MYSQL* admin) { MYSQL_QUERY_T(admin, "LOAD MYSQL VARIABLES TO RUNTIME"); MYSQL* proxy = mysql_init(NULL); - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy->net.compress, "Compression: (%d)", proxy->net.compress); } const MARIADB_CHARSET_INFO* charset_info = proxysql_find_charset_nr(proxy->server_language); @@ -85,22 +83,35 @@ int check_all_collations(const CommandLine& cl, MYSQL* admin) { } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - MYSQL* admin = mysql_init(NULL); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == admin->net.compress, "Compression: (%d)", admin->net.compress); + } + + uint32_t num_tests = 0; + { + mysql_query(admin, "SELECT COUNT(*) FROM mysql_collations WHERE id < 256"); + MYSQL_RES* myres = mysql_store_result(admin); + MYSQL_ROW myrow = mysql_fetch_row(myres); + + if (myrow && myrow[0]) { + num_tests = atoi(myrow[0]); + } } + plan(2 + 3*num_tests); - check_all_collations(cl, admin); + check_all_collations(admin); cleanup: diff --git a/test/tap/tests/test_default_value_transaction_isolation-t.cpp b/test/tap/tests/test_default_value_transaction_isolation-t.cpp index 972b9a3ac0..d723c992b7 100644 --- a/test/tap/tests/test_default_value_transaction_isolation-t.cpp +++ b/test/tap/tests/test_default_value_transaction_isolation-t.cpp @@ -11,23 +11,26 @@ #include "command_line.h" #include "utils.h" -int main(int argc, char** argv) { - CommandLine cl; +CommandLine cl; - if(cl.getEnv()) - return exit_status(); +int main(int argc, char** argv) { - plan(3); + plan(2+2+2+2 + 3); diag("Testing default value for session varable transaction isolation"); MYSQL* mysqladmin = mysql_init(NULL); - if (!mysqladmin) - return exit_status(); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysqladmin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysqladmin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysqladmin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysqladmin)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysqladmin)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysqladmin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysqladmin->net.compress, "Compression: (%d)", mysqladmin->net.compress); } // Set default non-existing value for transaction isolation level @@ -35,28 +38,40 @@ int main(int argc, char** argv) { MYSQL_QUERY(mysqladmin, "load mysql variables to runtime"); MYSQL* mysql_1 = mysql_init(NULL); - if (!mysql_1) - return exit_status(); - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql_1, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql_1, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql_1, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - fprintf(stderr, "Failed to connect to database: Error: %s\n", - mysql_error(mysql_1)); + fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql_1)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql_1); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql_1->net.compress, "Compression: (%d)", mysql_1->net.compress); } + MYSQL_QUERY(mysql_1, "select 1"); MYSQL_RES* result = mysql_store_result(mysql_1); ok(mysql_num_rows(result) == 1, "Select statement should be executed on connection 1"); mysql_free_result(result); MYSQL* mysql_2 = mysql_init(NULL); - if (!mysql_2) - return exit_status(); - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql_2, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql_2, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql_2, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - fprintf(stderr, "Failed to connect to database: Error: %s\n", - mysql_error(mysql_2)); + fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql_2)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql_2); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql_2->net.compress, "Compression: (%d)", mysql_2->net.compress); } + MYSQL_QUERY(mysql_2, "select 1"); result = mysql_store_result(mysql_2); ok(mysql_num_rows(result) == 1, "Select statement should be executed on connection 1"); @@ -68,14 +83,20 @@ int main(int argc, char** argv) { // Try third connection with different default value of the session variable MYSQL* mysql_3 = mysql_init(NULL); - if (!mysql_3) - return exit_status(); - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql_3, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql_3, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql_3, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - fprintf(stderr, "Failed to connect to database: Error: %s\n", - mysql_error(mysql_3)); + fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql_3)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql_3); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql_3->net.compress, "Compression: (%d)", mysql_3->net.compress); } + MYSQL_QUERY(mysql_3, "select 1"); result = mysql_store_result(mysql_3); ok(mysql_num_rows(result) == 1, "Select statement should be executed on connection 1"); diff --git a/test/tap/tests/test_default_value_transaction_isolation_attr-t.cpp b/test/tap/tests/test_default_value_transaction_isolation_attr-t.cpp index c90541e200..2cbf5ece11 100644 --- a/test/tap/tests/test_default_value_transaction_isolation_attr-t.cpp +++ b/test/tap/tests/test_default_value_transaction_isolation_attr-t.cpp @@ -33,11 +33,14 @@ using std::string; using namespace nlohmann; +CommandLine cl; + using user_attributes = std::tuple; /** * @brief User names and attributes to be check and verified. */ + const std::vector c_user_attributes { std::make_tuple( "sbtest1", @@ -191,27 +194,37 @@ int extract_exp_iso_level( } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - plan(c_user_attributes.size() * 4); + plan(2+2+2*c_user_attributes.size() + c_user_attributes.size()*4); MYSQL* proxysql_admin = mysql_init(NULL); - MYSQL* mysql_server = mysql_init(NULL); - - // Creating the new connections + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } -// if (!mysql_real_connect(mysql_server, cl.host, "root", "root", NULL, 13306, NULL, 0)) { + + MYSQL* mysql_server = mysql_init(NULL); + diag("Connecting: cl.mysql_username='%s' cl.use_ssl=%d cl.compression=%d", cl.mysql_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql_server, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql_server, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql_server, cl.mysql_host, cl.mysql_username, cl.mysql_password, NULL, cl.mysql_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql_server)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(mysql_server); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql_server->net.compress, "Compression: (%d)", mysql_server->net.compress); } // Creating the new required users @@ -236,19 +249,18 @@ int main(int argc, char** argv) { for (const auto& user_attribute : user_attributes) { // Create the new connection to verify MYSQL* proxysql_mysql = mysql_init(NULL); - if ( - !mysql_real_connect( - proxysql_mysql, - cl.host, - std::get<0>(user_attribute).c_str(), - std::get<1>(user_attribute).c_str(), - NULL, cl.port, NULL, 0) - ) { - fprintf( - stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, - mysql_error(proxysql_mysql) - ); + diag("Connecting: username='%s' cl.use_ssl=%d cl.compression=%d", std::get<0>(user_attribute).c_str(), cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_mysql, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect( proxysql_mysql, cl.host, std::get<0>(user_attribute).c_str(), std::get<1>(user_attribute).c_str(), NULL, cl.port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_mysql->net.compress, "Compression: (%d)", proxysql_mysql->net.compress); } std::string exp_iso_level {}; diff --git a/test/tap/tests/test_digest_umap_aux-t.cpp b/test/tap/tests/test_digest_umap_aux-t.cpp index 227f5af08d..f74f01476c 100644 --- a/test/tap/tests/test_digest_umap_aux-t.cpp +++ b/test/tap/tests/test_digest_umap_aux-t.cpp @@ -29,6 +29,7 @@ using std::vector; using std::string; CommandLine cl; + double slowest_query = 0.0; double fastest_query = 0.0; std::atomic_bool stop(false); @@ -111,12 +112,19 @@ vector get_digest_stats(MYSQL* proxy_admin) { void run_dummy_queries() { MYSQL* proxy_mysql = mysql_init(NULL); - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { -// if (!mysql_real_connect(proxy_mysql, cl.root_host, cl.root_username, cl.root_password, NULL, cl.root_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_mysql)); slowest_query = -1.0; return; + } else { + const char * c = mysql_get_ssl_cipher(proxy_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_mysql->net.compress, "Compression: (%d)", proxy_mysql->net.compress); } vector execution_times = {}; @@ -173,17 +181,21 @@ void run_stats_digest_query(MYSQL* proxy_admin) { int main(int argc, char** argv) { - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - - plan(1 + DUMMY_QUERIES.size() * 5); // always specify the number of tests that are going to be performed + plan(2+2+2 + 1 + DUMMY_QUERIES.size() * 5); // always specify the number of tests that are going to be performed MYSQL *proxy_admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_admin->net.compress, "Compression: (%d)", proxy_admin->net.compress); } MYSQL_QUERY(proxy_admin, "TRUNCATE TABLE stats.stats_mysql_query_digest"); @@ -199,11 +211,19 @@ int main(int argc, char** argv) { } MYSQL *proxy_mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { -// if (!mysql_real_connect(proxy_mysql, cl.root_host, cl.root_username, cl.root_password, NULL, cl.root_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_mysql)); mysql_close(proxy_admin); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_mysql->net.compress, "Compression: (%d)", proxy_mysql->net.compress); } time_t init_time = time(NULL); diff --git a/test/tap/tests/test_dns_cache-t.cpp b/test/tap/tests/test_dns_cache-t.cpp index 652efa2425..8c9a297f84 100644 --- a/test/tap/tests/test_dns_cache-t.cpp +++ b/test/tap/tests/test_dns_cache-t.cpp @@ -21,6 +21,8 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + std::vector split(const std::string& s, char delimiter) { std::vector tokens {}; std::string token {}; @@ -128,23 +130,21 @@ bool check_result(const std::string& key, const std::map& p } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } // Initialize Admin connection MYSQL* proxysql_admin = mysql_init(NULL); - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return -1; - } - // Connnect to ProxySQL Admin + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } // MYSQL_QUERY(proxysql_admin, "DELETE FROM mysql_servers WHERE hostgroup_id=999"); // just in case @@ -159,15 +159,18 @@ int main(int argc, char** argv) { // Initialize ProxySQL connection MYSQL* proxysql = mysql_init(NULL); - if (!proxysql) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql)); - return -1; - } - // Connect to ProxySQL -// if (!mysql_real_connect(proxysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { + diag("Connecting: cl.root_username='%s' cl.use_ssl=%d cl.compression=%d", cl.root_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql, cl.root_host, cl.root_username, cl.root_password, NULL, cl.root_port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(proxysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql->net.compress, "Compression: (%d)", proxysql->net.compress); } DECLARE_PREV_AFTER_METRICS(); @@ -270,7 +273,7 @@ int main(int argc, char** argv) { STEP_END }; - plan((dns_cache_check_steps.size() -1) * 3 * 2); + plan(2+2 + (dns_cache_check_steps.size() -1) * 3 * 2); for (size_t i = 0; i < dns_cache_check_steps.size(); i++) { diag("Starting Step:'%ld'", i); diff --git a/test/tap/tests/test_empty_query-t.cpp b/test/tap/tests/test_empty_query-t.cpp index 558b08e546..72b098e444 100644 --- a/test/tap/tests/test_empty_query-t.cpp +++ b/test/tap/tests/test_empty_query-t.cpp @@ -8,23 +8,27 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + uint32_t EXECUTIONS = 100; int main(int argc, char** argv) { - plan(1); - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } + plan(2 + 1); MYSQL* proxy = mysql_init(NULL); - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy->net.compress, "Compression: (%d)", proxy->net.compress); } int exp_myerr = 1065; diff --git a/test/tap/tests/test_enforce_autocommit_on_reads-t.cpp b/test/tap/tests/test_enforce_autocommit_on_reads-t.cpp index 0d7550c4a9..9bff73ee3e 100644 --- a/test/tap/tests/test_enforce_autocommit_on_reads-t.cpp +++ b/test/tap/tests/test_enforce_autocommit_on_reads-t.cpp @@ -11,6 +11,8 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + /* This test includes a lot of repetitive checks that could have been organized into functions. But they have been left in this way to easily identify the failed check @@ -18,36 +20,43 @@ But they have been left in this way to easily identify the failed check int main(int argc, char** argv) { - CommandLine cl; - - if(cl.getEnv()) - return exit_status(); - plan(96); + plan(2+2 + 96); diag("Testing mysql-enforce_autocommit_on_reads"); MYSQL* mysqladmin = mysql_init(NULL); - if (!mysqladmin) - return exit_status(); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysqladmin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysqladmin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysqladmin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysqladmin)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysqladmin)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysqladmin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysqladmin->net.compress, "Compression: (%d)", mysqladmin->net.compress); } MYSQL_QUERY(mysqladmin, "SET mysql-enforce_autocommit_on_reads=0"); MYSQL_QUERY(mysqladmin, "load mysql variables to runtime"); MYSQL* mysql = mysql_init(NULL); - if (!mysql) - return exit_status(); - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - fprintf(stderr, "Failed to connect to database: Error: %s\n", - mysql_error(mysql)); + fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } + MYSQL_RES *res; if (create_table_test_sbtest1(100,mysql)) { fprintf(stderr, "File %s, line %d, Error: create_table_test_sbtest1() failed\n", __FILE__, __LINE__); diff --git a/test/tap/tests/test_filtered_set_statements-t.cpp b/test/tap/tests/test_filtered_set_statements-t.cpp index 5e27cb55fc..f4981d27c8 100644 --- a/test/tap/tests/test_filtered_set_statements-t.cpp +++ b/test/tap/tests/test_filtered_set_statements-t.cpp @@ -22,11 +22,14 @@ #include "utils.h" #include +CommandLine cl; + /** * @brief Queries to be tested that are known to be filtered by ProxySQL. * * TODO: Fill with all the statements that should be properly handled by ProxySQL. */ + std::vector> filtered_set_queries { { "sql_mode", "'ONLY_FULL_GROUP_BY,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO'" }, { "wait_timeout", "28801" }, @@ -70,28 +73,40 @@ std::vector get_valid_set_query_set(const std::string& set_query, c } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } // plan one test per statement attempt + one check 'SUM(sum_time) == 0' for each 'filtered_set_queries' - plan(filtered_set_queries.size() + filtered_set_queries.size()*get_valid_set_query_set("", "").size()); + plan(2+2 + filtered_set_queries.size() + filtered_set_queries.size()*get_valid_set_query_set("", "").size()); // create a regular connection to 'proxysql' MYSQL* proxysql_mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_mysql->net.compress, "Compression: (%d)", proxysql_mysql->net.compress); } // create a connection to 'proxysql_admin' MYSQL* proxysql_admin = mysql_init(NULL); - if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_password, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } // first clean the 'stats_mysql_query_digest' table diff --git a/test/tap/tests/test_firewall-t.cpp b/test/tap/tests/test_firewall-t.cpp index a9b8cc6bab..c9a2681475 100644 --- a/test/tap/tests/test_firewall-t.cpp +++ b/test/tap/tests/test_firewall-t.cpp @@ -11,33 +11,41 @@ #include "command_line.h" #include "utils.h" -int main(int argc, char** argv) { - CommandLine cl; +CommandLine cl; - if(cl.getEnv()) - return exit_status(); +int main(int argc, char** argv) { - plan(7); + plan(2+2 + 7); diag("Testing firewall whitelist functionality"); MYSQL* mysqladmin = mysql_init(NULL); - if (!mysqladmin) - return exit_status(); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysqladmin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysqladmin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysqladmin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysqladmin)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysqladmin)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysqladmin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysqladmin->net.compress, "Compression: (%d)", mysqladmin->net.compress); } MYSQL* mysql = mysql_init(NULL); - if (!mysql) - return exit_status(); - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - fprintf(stderr, "Failed to connect to database: Error: %s\n", - mysql_error(mysql)); + fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } MYSQL_QUERY(mysqladmin, "delete from mysql_firewall_whitelist_users"); diff --git a/test/tap/tests/test_flagOUT_weight-t.cpp b/test/tap/tests/test_flagOUT_weight-t.cpp index f07da9f2cc..089f5bcaf4 100644 --- a/test/tap/tests/test_flagOUT_weight-t.cpp +++ b/test/tap/tests/test_flagOUT_weight-t.cpp @@ -12,6 +12,7 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; char * username = (char *)"user1459"; char * password = (char *)"pass1459"; @@ -54,40 +55,45 @@ int run_queries_sets(std::vector& queries, MYSQL *my, const std::st int main(int argc, char** argv) { - CommandLine cl; - if(cl.getEnv()) - return exit_status(); - - plan(4); + plan(2+2 + 4); MYSQL* mysqladmin = mysql_init(NULL); - if (!mysqladmin) - return exit_status(); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysqladmin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysqladmin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysqladmin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysqladmin)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysqladmin)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysqladmin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysqladmin->net.compress, "Compression: (%d)", mysqladmin->net.compress); } - MYSQL * mysql = NULL; - diag("We will reconfigure ProxySQL to use SQLite3 Server on hostgroup 1458 and 1459, IP 127.0.0.1 and port 6030"); diag("We will reconfigure query rules to load balance between these 2 hostgroups"); if (run_queries_sets(queries_set1, mysqladmin, "Running on Admin")) return exit_status(); - mysql = mysql_init(NULL); - if (!mysql) - return exit_status(); - + MYSQL* mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, username, password, NULL, cl.port, NULL, 0)) { - fprintf(stderr, "Failed to connect to database: Error: %s\n", - mysql_error(mysql)); + fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } + // We now create a table named tbl1459 if (run_queries_sets(queries_SQL1, mysql, "Running on SQLite3")) return exit_status(); diff --git a/test/tap/tests/test_format_utils-t.cpp b/test/tap/tests/test_format_utils-t.cpp index 252bac5f29..51b6929bf8 100644 --- a/test/tap/tests/test_format_utils-t.cpp +++ b/test/tap/tests/test_format_utils-t.cpp @@ -14,6 +14,9 @@ #include "proxysql_utils.h" #include "tap.h" #include "utils.h" +#include "command_line.h" + +CommandLine cl; using std::vector; using std::tuple; diff --git a/test/tap/tests/test_greeting_capabilities-t.cpp b/test/tap/tests/test_greeting_capabilities-t.cpp index 51fe727146..e63d3b347e 100644 --- a/test/tap/tests/test_greeting_capabilities-t.cpp +++ b/test/tap/tests/test_greeting_capabilities-t.cpp @@ -17,6 +17,8 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + using std::pair; using std::string; using std::vector; @@ -63,15 +65,23 @@ pair check_server_capabilities( return { caps_match, exp_caps }; } -int test_proxy_capabilites(const CommandLine& cl, MYSQL* admin) { +int test_proxy_capabilites(MYSQL* admin) { MYSQL_QUERY(admin, "SET mysql-enable_client_deprecate_eof=0"); MYSQL_QUERY(admin, "LOAD MYSQL VARIABLES TO RUNTIME"); MYSQL* proxy = mysql_init(NULL); - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy->net.compress, "Compression: (%d)", proxy->net.compress); } pair caps_res { check_server_capabilities(proxy, { CLIENT_DEPRECATE_EOF }, false) }; @@ -89,10 +99,18 @@ int test_proxy_capabilites(const CommandLine& cl, MYSQL* admin) { proxy = mysql_init(NULL); proxy->options.client_flag |= CLIENT_DEPRECATE_EOF; - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy->net.compress, "Compression: (%d)", proxy->net.compress); } caps_res = check_server_capabilities(proxy, { CLIENT_DEPRECATE_EOF }, true); @@ -109,24 +127,26 @@ int test_proxy_capabilites(const CommandLine& cl, MYSQL* admin) { } int main(int argc, char** argv) { - CommandLine cl; // TODO: Harcoded for now, this is an initial version of the test. - plan(2); - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } + plan(2+2+2 + 2); MYSQL* admin = mysql_init(NULL); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == admin->net.compress, "Compression: (%d)", admin->net.compress); } - test_proxy_capabilites(cl, admin); + test_proxy_capabilites(admin); mysql_close(admin); diff --git a/test/tap/tests/test_gtid_forwarding-t.cpp b/test/tap/tests/test_gtid_forwarding-t.cpp index dddc65206a..5150627d26 100644 --- a/test/tap/tests/test_gtid_forwarding-t.cpp +++ b/test/tap/tests/test_gtid_forwarding-t.cpp @@ -23,25 +23,27 @@ #include "proxysql_utils.h" #include "re2/re2.h" -int main(int, char**) { - CommandLine cl; +CommandLine cl; - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } +int LOOPS = 1000; - MYSQL* proxysql_mysql = mysql_init(NULL); +int main(int, char**) { - // Initialize connections - if (!proxysql_mysql) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); - return -1; - } + plan(2 + 3*LOOPS); + MYSQL* proxysql_mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_mysql->net.compress, "Compression: (%d)", proxysql_mysql->net.compress); } MYSQL_QUERY(proxysql_mysql, "CREATE DATABASE IF NOT EXISTS test"); @@ -50,7 +52,7 @@ int main(int, char**) { uint last_id { 0 }; - for (uint32_t i = 0; i < 1000; i++) { + for (uint32_t i = 0; i < LOOPS; i++) { // Simple select to verify resultset is being returned properly MYSQL_QUERY(proxysql_mysql, "SELECT 1"); MYSQL_RES* select_res = mysql_store_result(proxysql_mysql); diff --git a/test/tap/tests/test_keep_multiplexing_variables-t.cpp b/test/tap/tests/test_keep_multiplexing_variables-t.cpp index 56e283c93b..38c276cdba 100644 --- a/test/tap/tests/test_keep_multiplexing_variables-t.cpp +++ b/test/tap/tests/test_keep_multiplexing_variables-t.cpp @@ -18,6 +18,8 @@ using std::string; using namespace nlohmann; +CommandLine cl; + std::vector select_queries { "select @@session.autocommit, @@session.big_tables, @@autocommit,@@bulk_insert_buffer_size, @@character_set_database,@@transaction_isolation, @@version,@@session.transaction_isolation", "select @@autocommit, @@sql_mode, @@big_tables, @@autocommit,@@bulk_insert_buffer_size, @@character_set_database,@@session.transaction_isolation, @@version,@@transaction_isolation", @@ -32,12 +34,21 @@ std::vector select_queries { "select @@session.autocommit, @@big_tables, @@autocommit,@@bulk_insert_buffer_size, @@character_set_database,@@transaction_isolation, @@version,@@session.transaction_isolation", }; -int check_multiplexing_disabled(const CommandLine& cl, const std::string query, bool& multiplex_disabled) { - MYSQL* proxysql_mysql = mysql_init(NULL); +int check_multiplexing_disabled(const std::string query, bool& multiplex_disabled) { + MYSQL* proxysql_mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_mysql->net.compress, "Compression: (%d)", proxysql_mysql->net.compress); } MYSQL_QUERY(proxysql_mysql, query.c_str()); @@ -60,20 +71,22 @@ int check_multiplexing_disabled(const CommandLine& cl, const std::string query, } int main(int argc, char** argv) { - CommandLine cl; - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - - plan(26); + plan(2+2*4+2*2*select_queries.size() + 26); MYSQL* proxysql_admin = mysql_init(NULL); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } // Clean the 'keep_multiplexing_variables' @@ -84,13 +97,13 @@ int main(int argc, char** argv) { // Check that any query will disable multiplexing { bool disabled_multiplexing = false; - int check_multiplexing_err = check_multiplexing_disabled(cl, "SELECT @@sql_mode", disabled_multiplexing); + int check_multiplexing_err = check_multiplexing_disabled("SELECT @@sql_mode", disabled_multiplexing); ok (disabled_multiplexing == true, "Simple 'SELECT @@*' should disable multiplexing."); } { bool disabled_multiplexing = false; - int check_multiplexing_err = check_multiplexing_disabled(cl, "SELECT @@SESSION.sql_mode", disabled_multiplexing); + int check_multiplexing_err = check_multiplexing_disabled("SELECT @@SESSION.sql_mode", disabled_multiplexing); ok (disabled_multiplexing == true, "Simple 'SELECT @@SESSION.*' should disable multiplexing."); } @@ -102,13 +115,13 @@ int main(int argc, char** argv) { // Check that any query will disable multiplexing { bool disabled_multiplexing = false; - int check_multiplexing_err = check_multiplexing_disabled(cl, "SELECT @@sql_mode", disabled_multiplexing); + int check_multiplexing_err = check_multiplexing_disabled("SELECT @@sql_mode", disabled_multiplexing); ok (disabled_multiplexing == false, "Simple 'SELECT @@*' should keep multiplexing enabled."); } { bool disabled_multiplexing = false; - int check_multiplexing_err = check_multiplexing_disabled(cl, "SELECT @@SESSION.sql_mode", disabled_multiplexing); + int check_multiplexing_err = check_multiplexing_disabled("SELECT @@SESSION.sql_mode", disabled_multiplexing); ok (disabled_multiplexing == false, "Simple 'SELECT @@SESSION.*' should keep multiplexing enabled."); } @@ -120,7 +133,7 @@ int main(int argc, char** argv) { { for (const std::string& query : select_queries) { bool disabled_multiplexing = true; - int check_multiplexing_err = check_multiplexing_disabled(cl, query, disabled_multiplexing); + int check_multiplexing_err = check_multiplexing_disabled(query, disabled_multiplexing); ok (disabled_multiplexing == true, "Complex 'SELECT @@SESSION.*, @@*' should disable multiplexing."); } } @@ -133,7 +146,7 @@ int main(int argc, char** argv) { { for (const std::string& query : select_queries) { bool disabled_multiplexing = false; - int check_multiplexing_err = check_multiplexing_disabled(cl, query, disabled_multiplexing); + int check_multiplexing_err = check_multiplexing_disabled(query, disabled_multiplexing); ok (disabled_multiplexing == false, "Complex 'SELECT @@SESSION.*, @@*' queries should keep multiplexing enabled."); } } diff --git a/test/tap/tests/test_ldap_stats_mysql_users.cpp b/test/tap/tests/test_ldap_stats_mysql_users.cpp index 677b67a185..478cb0ea37 100644 --- a/test/tap/tests/test_ldap_stats_mysql_users.cpp +++ b/test/tap/tests/test_ldap_stats_mysql_users.cpp @@ -25,6 +25,8 @@ using std::string; using std::vector; using std::map; +CommandLine cl; + using user_stats_t = std::tuple; const string LDAP_USER_T { "clientuser" }; @@ -86,7 +88,10 @@ const uint32_t LDAP_MAX_CONNS = 20; const uint32_t USER_NUM = 30; int main(int argc, char** argv) { + plan( + 2+2 + // connections + 2*USER_NUM + // connections *tg_conns ??? 1 + // Check that 'ldap-max_db_connections' is properly updated 1 + // Check that row count from 'stats_mysql_users' match expected USER_NUM + // Check that actual user conns match expected @@ -95,13 +100,6 @@ int main(int argc, char** argv) { 5 // Check that conns fails to be created over 'LDAP_MAX_CONNS' ); - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - struct rlimit limits { 0, 0 }; getrlimit(RLIMIT_NOFILE, &limits); diag("Old process limits: { %ld, %ld }", limits.rlim_cur, limits.rlim_max); @@ -110,16 +108,33 @@ int main(int argc, char** argv) { diag("New process limits: { %ld, %ld }", limits.rlim_cur, limits.rlim_max); MYSQL* proxy = mysql_init(NULL); - MYSQL* admin = mysql_init(NULL); - - if (!mysql_real_connect(proxy, cl.host, cl.username, cl.password, NULL, 13306, NULL, 0)) { + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(proxy, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy->net.compress, "Compression: (%d)", proxy->net.compress); } + MYSQL* admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == admin->net.compress, "Compression: (%d)", admin->net.compress); } // Get the maximum number of connections per LDAP user right now, '' @@ -202,9 +217,18 @@ int main(int argc, char** argv) { diag("Creating connection for user '%s'", LDAP_USER.c_str()); MYSQL* conn = mysql_init(NULL); + diag("Connecting: username='%s' cl.use_ssl=%d cl.compression=%d", LDAP_USER.c_str(), cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(conn, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(conn, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(conn, cl.host, LDAP_USER.c_str(), LDAP_PASS.c_str(), NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(conn)); goto cleanup; + } else { + const char * c = mysql_get_ssl_cipher(conn); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == conn->net.compress, "Compression: (%d)", conn->net.compress); } user_conns.push_back(conn); diff --git a/test/tap/tests/test_log_last_insert_id-t.cpp b/test/tap/tests/test_log_last_insert_id-t.cpp index 2443a85d1d..04e8c3de66 100644 --- a/test/tap/tests/test_log_last_insert_id-t.cpp +++ b/test/tap/tests/test_log_last_insert_id-t.cpp @@ -20,8 +20,9 @@ using std::string; using nlohmann::json; using std::fstream; +CommandLine cl; + int main(int argc, char** argv) { - CommandLine cl; MYSQL * proxysql_mysql = mysql_init(NULL); MYSQL* proxysql_admin = mysql_init(NULL); @@ -29,9 +30,6 @@ int main(int argc, char** argv) { char * datadir = NULL; plan(4); // 3 INSERTs + a count on entries - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - } datadir = getenv("REGULAR_INFRA_DATADIR"); if (datadir == NULL) { @@ -40,16 +38,8 @@ int main(int argc, char** argv) { } // Connect to ProxySQL Admin and check current SQLite3 configuration - if ( - !mysql_real_connect( - proxysql_admin, cl.host, cl.admin_username, cl.admin_password, - NULL, cl.admin_port, NULL, 0 - ) - ) { - fprintf( - stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, - mysql_error(proxysql_admin) - ); + if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); goto cleanup; } @@ -59,10 +49,7 @@ int main(int argc, char** argv) { MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME"); if (!mysql_real_connect(proxysql_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - fprintf( - stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, - mysql_error(proxysql_mysql) - ); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__,mysql_error(proxysql_mysql)); return EXIT_FAILURE; } diff --git a/test/tap/tests/test_max_transaction_time-t.cpp b/test/tap/tests/test_max_transaction_time-t.cpp index 3d0e00bf6d..78bdb30381 100644 --- a/test/tap/tests/test_max_transaction_time-t.cpp +++ b/test/tap/tests/test_max_transaction_time-t.cpp @@ -26,6 +26,8 @@ using nlohmann::json; using namespace std; +CommandLine cl; + void parse_result_json_column(MYSQL_RES *result, json& j) { if(!result) return; MYSQL_ROW row; @@ -37,19 +39,22 @@ void parse_result_json_column(MYSQL_RES *result, json& j) { // This test was previously failing due to replication not catching up quickly enough when doing int main(int, char**) { - CommandLine cl; - - plan(NUMQUERIES*2+1); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } + plan(2+2 + NUMQUERIES*2+1); MYSQL* admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == admin->net.compress, "Compression: (%d)", admin->net.compress); } diag("Configure ProxySQL to test mysql-max_transaction_time"); @@ -63,9 +68,18 @@ int main(int, char**) { mysql_close(admin); MYSQL* proxy = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy->net.compress, "Compression: (%d)", proxy->net.compress); } diag("Run %d 1-second transactions:", NUMQUERIES); diff --git a/test/tap/tests/test_mysql_connect_retries-t.cpp b/test/tap/tests/test_mysql_connect_retries-t.cpp index 54dbcc8656..0d624b32b4 100644 --- a/test/tap/tests/test_mysql_connect_retries-t.cpp +++ b/test/tap/tests/test_mysql_connect_retries-t.cpp @@ -38,6 +38,8 @@ using std::string; typedef std::chrono::high_resolution_clock hrc; +CommandLine cl; + /** * @brief Return the 'errno' when trying to connect to a particular port. * @param port The port in which to attempt to 'connect'. @@ -146,14 +148,12 @@ int configure_target_user(MYSQL* admin, const string& ff_user, uint32_t def_hg, return EXIT_SUCCESS; } -int check_connect_retries( - const CommandLine& cl, MYSQL* admin, uint32_t retries, uint32_t hg, uint32_t port, bool ff -) { - const string USER { "sbtest10" }; +int check_connect_retries(MYSQL* admin, uint32_t retries, uint32_t hg, uint32_t port, bool ff) { + const string user { "sbtest10" }; int cnf_user_err = configure_target_user(admin, "sbtest10", hg, ff); if (cnf_user_err) { - diag("Failed to configure target user '%s'", USER.c_str()); + diag("Failed to configure target user '%s'", user.c_str()); return EXIT_FAILURE; } @@ -168,9 +168,18 @@ int check_connect_retries( diag("Starting a '%s' connection with user 'sbtest10' and issuing query", conn_type.c_str()); MYSQL* proxy = mysql_init(NULL); - if (!mysql_real_connect(proxy, cl.host, USER.c_str(), USER.c_str(), NULL, cl.port, NULL, 0)) { + diag("Connecting: username='%s' cl.use_ssl=%d cl.compression=%d", user.c_str(), cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(proxy, cl.host, user.c_str(), user.c_str(), NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy->net.compress, "Compression: (%d)", proxy->net.compress); } diag("START: Checking behavior first 'ConnectionError' in the connection"); @@ -286,9 +295,7 @@ int check_connect_retries( return tests_failed(); } -int check_connect_error_consistency( - const CommandLine& cl, MYSQL* admin, uint32_t hg, bool ff, uint32_t queries -) { +int check_connect_error_consistency(MYSQL* admin, uint32_t hg, bool ff, uint32_t queries) { const string user { "sbtest10" }; const uint32_t retries = 1; const uint32_t timeout = 3000; @@ -316,9 +323,18 @@ int check_connect_error_consistency( usleep(1500 * 1000); MYSQL* proxy = mysql_init(NULL); + diag("Connecting: username='%s' cl.use_ssl=%d cl.compression=%d", user.c_str(), cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy, cl.host, user.c_str(), user.c_str(), NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy->net.compress, "Compression: (%d)", proxy->net.compress); } diag("START: checking behavior first 'ConnectionError' in the connection"); @@ -351,7 +367,7 @@ int check_connect_error_consistency( return EXIT_SUCCESS; } -int check_connect_timeout_precedence(const CommandLine& cl, MYSQL* admin, uint32_t hg, bool ff) { +int check_connect_timeout_precedence(MYSQL* admin, uint32_t hg, bool ff) { const string user { "sbtest10" }; const uint32_t retries = 2; const uint32_t timeout = 1000; @@ -374,9 +390,18 @@ int check_connect_timeout_precedence(const CommandLine& cl, MYSQL* admin, uint32 MYSQL_QUERY_T(admin, "LOAD MYSQL VARIABLES TO RUNTIME"); MYSQL* proxy = mysql_init(NULL); + diag("Connecting: username='%s' cl.use_ssl=%d cl.compression=%d", user.c_str(), cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy, cl.host, user.c_str(), user.c_str(), NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy->net.compress, "Compression: (%d)", proxy->net.compress); } diag("START: Checking that timeout should have precedence over retries"); @@ -395,9 +420,10 @@ const uint32_t MAX_RETRIES = 4; const uint32_t ERR_QUERIES = 3; int main(int, char**) { - CommandLine cl; plan( + 2 + // connections + 4*MAX_RETRIES + 2*4 + // connections // Number of retries per number of checks 'check_connect_retries' MAX_RETRIES * 3 * 2 + // Number of errors to check + 2 extra checks on 'check_connect_error_consistency' @@ -406,15 +432,19 @@ int main(int, char**) { 1 * 2 ); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - MYSQL* admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == admin->net.compress, "Compression: (%d)", admin->net.compress); } uint32_t unused_port = get_unused_port(); @@ -450,21 +480,21 @@ int main(int, char**) { MYSQL_QUERY_T(admin, "LOAD MYSQL VARIABLES TO RUNTIME"); // Test for a connection without fast-forward - int rc = check_connect_retries(cl, admin, retries, hg, unused_port, 0); + int rc = check_connect_retries(admin, retries, hg, unused_port, 0); if (rc) { break; } // Test for a connection with fast-forward - rc = check_connect_retries(cl, admin, retries, hg, unused_port, 1); + rc = check_connect_retries(admin, retries, hg, unused_port, 1); if (rc) { break; } } // Check several connect errors in the same connection behave in a consistent way - check_connect_error_consistency(cl, admin, hg, 0, ERR_QUERIES); - check_connect_error_consistency(cl, admin, hg, 1, ERR_QUERIES); + check_connect_error_consistency(admin, hg, 0, ERR_QUERIES); + check_connect_error_consistency(admin, hg, 1, ERR_QUERIES); // Check that retries never takes precedence over the 'connect_timeout' - check_connect_timeout_precedence(cl, admin, hg, 0); - check_connect_timeout_precedence(cl, admin, hg, 1); + check_connect_timeout_precedence(admin, hg, 0); + check_connect_timeout_precedence(admin, hg, 1); mysql_close(admin); diff --git a/test/tap/tests/test_mysql_connect_retries_delay-t.cpp b/test/tap/tests/test_mysql_connect_retries_delay-t.cpp index 014c2eff6b..01eae958e3 100644 --- a/test/tap/tests/test_mysql_connect_retries_delay-t.cpp +++ b/test/tap/tests/test_mysql_connect_retries_delay-t.cpp @@ -29,41 +29,45 @@ using std::string; using std::vector; +CommandLine cl; + typedef std::chrono::high_resolution_clock hrc; const vector test_retry_delays { 1000, 2000, 3000 }; const double DUR_EPSILON = 1; int main() { - CommandLine cl; - - plan(test_retry_delays.size()); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } + plan(2+2 + test_retry_delays.size()); MYSQL* proxysql_admin = mysql_init(NULL); - MYSQL* proxysql = mysql_init(NULL); - - // Initialize connections - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return EXIT_FAILURE; - } - if (!proxysql) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql)); - return EXIT_FAILURE; - } - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } + + MYSQL* proxysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql->net.compress, "Compression: (%d)", proxysql->net.compress); } // Global config diff --git a/test/tap/tests/test_mysql_hostgroup_attributes-1-t.cpp b/test/tap/tests/test_mysql_hostgroup_attributes-1-t.cpp index 8825126eb8..0a022737d4 100644 --- a/test/tap/tests/test_mysql_hostgroup_attributes-1-t.cpp +++ b/test/tap/tests/test_mysql_hostgroup_attributes-1-t.cpp @@ -13,6 +13,7 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; int run_queries_sets(std::vector& queries, MYSQL *my, const std::string& message_prefix) { for (std::vector::iterator it = queries.begin(); it != queries.end(); it++) { @@ -52,11 +53,6 @@ int run_one_test(MYSQL *mysqladmin, const char *expected_checksum, const char *q } int main(int argc, char** argv) { - CommandLine cl; - - if(cl.getEnv()) - return exit_status(); - std::unordered_map queries_and_checksums = { { @@ -88,17 +84,22 @@ int main(int argc, char** argv) { } }; - plan(queries_and_checksums.size()*4); + plan(2 + queries_and_checksums.size()*4); diag("Testing the loading of mysql_hostgroup_attributes"); MYSQL* mysqladmin = mysql_init(NULL); - if (!mysqladmin) - return exit_status(); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysqladmin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysqladmin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysqladmin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysqladmin)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysqladmin)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysqladmin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysqladmin->net.compress, "Compression: (%d)", mysqladmin->net.compress); } for (std::unordered_map::iterator it = queries_and_checksums.begin(); it != queries_and_checksums.end(); it++) { diff --git a/test/tap/tests/test_mysql_query_digests_stages-t.cpp b/test/tap/tests/test_mysql_query_digests_stages-t.cpp index c4c79ddf0d..bfe9eca647 100644 --- a/test/tap/tests/test_mysql_query_digests_stages-t.cpp +++ b/test/tap/tests/test_mysql_query_digests_stages-t.cpp @@ -53,6 +53,8 @@ __thread int mysql_thread___query_digests_groups_grouping_limit = 1; using std::vector; using std::string; +CommandLine cl; + std::string replace_str(const std::string& str, const std::string& match, const std::string& repl) { if(match.empty()) { return str; @@ -418,7 +420,7 @@ int count_crashing_test_defs(const nlohmann::json& j_test_defs, uint32_t& test_n return EXIT_SUCCESS; } -void process_crashing_tests(CommandLine& cl, const nlohmann::json& test_defs) { +void process_crashing_tests(const nlohmann::json& test_defs) { int res = EXIT_SUCCESS; for (const auto& test_def : test_defs) { @@ -757,12 +759,6 @@ void process_grouping_tests(uint32_t max_groups) { int MAX_GEN_QUERY_LENGTH = 1800; int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } bool exec_crashing_tests = true; bool exec_grouping_tests = true; @@ -829,7 +825,7 @@ int main(int argc, char** argv) { process_digest_tests(regular_tests_defs); } if (exec_crashing_tests) { - process_crashing_tests(cl, crashing_tests_defs); + process_crashing_tests(crashing_tests_defs); } if (exec_grouping_tests) { for (uint32_t i = 300; i < MAX_GEN_QUERY_LENGTH; i += 50) { diff --git a/test/tap/tests/test_mysql_query_rules_fast_routing-t.cpp b/test/tap/tests/test_mysql_query_rules_fast_routing-t.cpp index cecfd8dfcc..068821f5b3 100644 --- a/test/tap/tests/test_mysql_query_rules_fast_routing-t.cpp +++ b/test/tap/tests/test_mysql_query_rules_fast_routing-t.cpp @@ -11,40 +11,31 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + std::vector params = { 100, 1234, 2356, 129645, 345123, 412317 }; int main(int argc, char** argv) { - /* - * 1. Read and command line parameters - */ - - // Define comman line parser - CommandLine cl; - - // Initialize tests parameters from environment variables - // Test parameters are similar to the mysql command line parameters but - // additionally they include admin interface username/password, host and port, - // working directory for test files. - if(cl.getEnv()) - return exit_status(); - - /* - * Prepare TAP framework to run tests - */ // Initialize TAP with planned number of checks and print the name of the test - plan(params.size()); + plan(2 + params.size()); diag("Testing query rules fast routing"); - /* - * Initialize connections to the servers and prepare data for test. - * Also initialize additional libraries. - */ - // Initialize connection to the proxysql admin interface - MYSQL* mysqlAdmin = mysql_init(NULL); - if (!mysqlAdmin) return exit_status(); - if (!mysql_real_connect(mysqlAdmin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) return exit_status(); + MYSQL* proxysql_admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); + return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); + } /* * Execute test performing required checks during execution @@ -54,19 +45,19 @@ int main(int argc, char** argv) { std::string queryS = ""; for (auto i=0; inet.compress, "Compression: (%d)", mysql_server->net.compress); } int query_res = mysql_query(mysql_server, "select concat(@@version, ' ', @@version_comment)"); diff --git a/test/tap/tests/test_prepare_statement_memory_usage-t.cpp b/test/tap/tests/test_prepare_statement_memory_usage-t.cpp index 9b2d48dbee..49c77940e9 100644 --- a/test/tap/tests/test_prepare_statement_memory_usage-t.cpp +++ b/test/tap/tests/test_prepare_statement_memory_usage-t.cpp @@ -11,6 +11,8 @@ #include "proxysql_utils.h" #include "utils.h" +CommandLine cl; + enum ComparisonOperator { kEqual = 0x00000001, kGreaterThan = 0x00000002, @@ -95,13 +97,6 @@ int check_prepare_statement_mem_usage(MYSQL* proxysql_admin, MYSQL* proxysql, co int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - plan(4 * // query 3 // checks ); diff --git a/test/tap/tests/test_prometheus_metrics-t.cpp b/test/tap/tests/test_prometheus_metrics-t.cpp index a9bc27df6a..25dd082bfb 100644 --- a/test/tap/tests/test_prometheus_metrics-t.cpp +++ b/test/tap/tests/test_prometheus_metrics-t.cpp @@ -92,7 +92,7 @@ int get_cur_metrics(MYSQL* admin, map& metrics_vals) { * @param proxy MYSQL Oppened MYSQL handler to ProxySQL Admin. * @return True if the action was able to be performed correctly, false otherwise. */ -bool trigger_auto_increment_delay_multiplex_metric(MYSQL* proxy, MYSQL*, const CommandLine&) { +bool trigger_auto_increment_delay_multiplex_metric(MYSQL* proxy, MYSQL*) { int inc_query_res = mysql_query( proxy, @@ -144,25 +144,24 @@ void check_auto_increment_delay_multiplex_metric( } } -bool trigger_access_denied_wrong_password_total(MYSQL*, MYSQL*, const CommandLine& cl) { - // Initialize ProxySQL connection - MYSQL* proxysql = mysql_init(NULL); - if (!proxysql) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql)); - return -1; - } - - // Connect to ProxySQL +bool trigger_access_denied_wrong_password_total(MYSQL*, MYSQL*) { bool access_denied_error = false; - void* connect_res = mysql_real_connect(proxysql, cl.host, "invalid_username", "invalid_password", NULL, cl.port, NULL, 0); - int access_errno = mysql_errno(proxysql); - - if (!connect_res && access_errno == ER_ACCESS_DENIED_ERROR) { - access_denied_error = true; - } else { - diag("Connections should have failed due to access denied. ErrCode: %d", access_errno); - access_denied_error = false; + // Connect to ProxySQL + MYSQL* proxysql = mysql_init(NULL); + diag("Connecting: username='%s' cl.use_ssl=%d cl.compression=%d", "invalid_username", cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql, MYSQL_OPT_COMPRESS, NULL); + if(!mysql_real_connect(proxysql, cl.host, "invalid_username", "invalid_password", NULL, cl.port, NULL, 0)) { + if (mysql_errno(proxysql) == ER_ACCESS_DENIED_ERROR) { + access_denied_error = true; + } else { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql)); + } } + if(!access_denied_error) + diag("Connections should have failed due to access denied. ErrCode: %d", 0); return access_denied_error; } @@ -191,7 +190,7 @@ void check_access_denied_wrong_password_total( } } -bool trigger_transaction_rollback_total(MYSQL* proxysql, MYSQL*, const CommandLine&) { +bool trigger_transaction_rollback_total(MYSQL* proxysql, MYSQL*) { int st_err = mysql_query(proxysql, "BEGIN"); bool res = false; @@ -232,7 +231,7 @@ void check_transaction_rollback_total( string PROXYSQL_VERSION {}; -bool get_proxysql_version_info(MYSQL*, MYSQL* admin, const CommandLine&) { +bool get_proxysql_version_info(MYSQL*, MYSQL* admin) { int v_err = mysql_query(admin, "SELECT @@version"); if (v_err) { diag( @@ -324,17 +323,21 @@ map extract_metric_tags(const string metric_id) { return result; } -bool trigger_message_count_parse_failure(MYSQL*, MYSQL*, const CommandLine& cl) { +bool trigger_message_count_parse_failure(MYSQL*, MYSQL*) { // Initialize ProxySQL connection MYSQL* proxysql = mysql_init(NULL); - if (!proxysql) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql)); - return false; - } - // Connect to ProxySQL + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql)); return false; + } else { + const char * c = mysql_get_ssl_cipher(proxysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql->net.compress, "Compression: (%d)", proxysql->net.compress); } int res = false; @@ -451,7 +454,7 @@ int get_target_metrics( return EXIT_SUCCESS; } -bool rm_add_server_connpool_setup(MYSQL* proxy, MYSQL* admin, const CommandLine& cl) { +bool rm_add_server_connpool_setup(MYSQL* proxy, MYSQL* admin) { // Exercise some load on the hostgroup 0 for (size_t i = 0; i < 10; i++) { int rc = mysql_query_d(proxy, "/* hostgroup=0 */ SELECT 1"); @@ -463,7 +466,7 @@ bool rm_add_server_connpool_setup(MYSQL* proxy, MYSQL* admin, const CommandLine& return EXIT_SUCCESS; } -bool rm_add_server_connpool_counters(MYSQL* proxy, MYSQL* admin, const CommandLine& cl) { +bool rm_add_server_connpool_counters(MYSQL* proxy, MYSQL* admin) { // Delete server and add it again to hostgroup diag("Removing current 'mysql_servers' for target hostgroup '0'"); mysql_query_d(admin, "DELETE FROM mysql_servers WHERE hostgroup_id=0"); @@ -541,15 +544,15 @@ void check_server_data_recv(const map& prev_metrics, const map; -using metric_trigger = function; +using setup = function; +using metric_trigger = function; using metric_check = function&, const map&)>; struct CHECK { enum funcs { SETUP, TRIGGER, CHECKER, _END }; }; -bool placeholder_setup(MYSQL*, MYSQL*, const CommandLine&) { return true; } +bool placeholder_setup(MYSQL*, MYSQL*) { return true; } /** * @brief Map of test identifier and pair functions holding the metrics tests: @@ -594,35 +597,43 @@ using std::map; int main(int argc, char** argv) { - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - - plan(metric_tests.size() * 4); + plan( + 4*metric_tests.size() + // connections + 2*2 + // connections + metric_tests.size() * 4 // tests + ); for (const auto& metric_test : metric_tests) { // Initialize Admin connection MYSQL* proxysql_admin = mysql_init(NULL); - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return EXIT_FAILURE; - } - // Connnect to ProxySQL Admin + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } + // Initialize ProxySQL connection MYSQL* proxysql = mysql_init(NULL); - if (!proxysql) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql)); - return EXIT_FAILURE; - } - // Connect to ProxySQL + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql->net.compress, "Compression: (%d)", proxysql->net.compress); } // Log test start for metric @@ -630,7 +641,7 @@ int main(int argc, char** argv) { // Execute the action triggering the metric update const auto& metric_setup = std::get(metric_test.second); - bool action_res = metric_setup(proxysql, proxysql_admin, cl); + bool action_res = metric_setup(proxysql, proxysql_admin); ok(action_res, "Setup action to prepare the env was successful."); // Get the current metrics values @@ -640,7 +651,7 @@ int main(int argc, char** argv) { // Execute the action triggering the metric update const auto& metric_trigger = std::get(metric_test.second); - bool trigger_res = metric_trigger(proxysql, proxysql_admin, cl); + bool trigger_res = metric_trigger(proxysql, proxysql_admin); ok(trigger_res, "Action to update the metric was executed properly."); // Get the new updated metrics values diff --git a/test/tap/tests/test_ps_async-t.cpp b/test/tap/tests/test_ps_async-t.cpp index 707d880eaf..eb7ec1856a 100644 --- a/test/tap/tests/test_ps_async-t.cpp +++ b/test/tap/tests/test_ps_async-t.cpp @@ -14,11 +14,13 @@ #include #include -typedef int myf; // Type of MyFlags in my_funcs -#define MYF(v) (myf) (v) -#define MY_KEEP_PREALLOC 1 -#define MY_ALIGN(A,L) (((A) + (L) - 1) & ~((L) - 1)) -#define ALIGN_SIZE(A) MY_ALIGN((A),sizeof(double)) +CommandLine cl; + +typedef int myf; // Type of MyFlags in my_funcs +#define MYF(v) (myf) (v) +#define MY_KEEP_PREALLOC 1 +#define MY_ALIGN(A,L) (((A) + (L) - 1) & ~((L) - 1)) +#define ALIGN_SIZE(A) MY_ALIGN((A),sizeof(double)) void ma_free_root(MA_MEM_ROOT *root, myf MyFLAGS); void *ma_alloc_root(MA_MEM_ROOT *mem_root, size_t Size); //void ma_free_root(MA_MEM_ROOT *, int); @@ -30,99 +32,99 @@ void *ma_alloc_root(MA_MEM_ROOT *mem_root, size_t Size); void * ma_alloc_root(MA_MEM_ROOT *mem_root, size_t Size) { #if defined(HAVE_purify) && defined(EXTRA_DEBUG) - MA_USED_MEM *next; - Size+=ALIGN_SIZE(sizeof(MA_USED_MEM)); - - if (!(next = (MA_USED_MEM*) malloc(Size))) - { - if (mem_root->error_handler) - (*mem_root->error_handler)(); - return((void *) 0); /* purecov: inspected */ - } - next->next=mem_root->used; - mem_root->used=next; - return (void *) (((char*) next)+ALIGN_SIZE(sizeof(MA_USED_MEM))); + MA_USED_MEM *next; + Size+=ALIGN_SIZE(sizeof(MA_USED_MEM)); + + if (!(next = (MA_USED_MEM*) malloc(Size))) + { + if (mem_root->error_handler) + (*mem_root->error_handler)(); + return((void *) 0); /* purecov: inspected */ + } + next->next=mem_root->used; + mem_root->used=next; + return (void *) (((char*) next)+ALIGN_SIZE(sizeof(MA_USED_MEM))); #else - size_t get_size; - void * point; - MA_USED_MEM *next= 0; - MA_USED_MEM **prev; - - Size= ALIGN_SIZE(Size); - - if ((*(prev= &mem_root->free))) - { - if ((*prev)->left < Size && - mem_root->first_block_usage++ >= 16 && - (*prev)->left < 4096) - { - next= *prev; - *prev= next->next; - next->next= mem_root->used; - mem_root->used= next; - mem_root->first_block_usage= 0; - } - for (next= *prev; next && next->left < Size; next= next->next) - prev= &next->next; - } - if (! next) - { /* Time to alloc new block */ - get_size= MAX(Size+ALIGN_SIZE(sizeof(MA_USED_MEM)), - (mem_root->block_size & ~1) * ( (mem_root->block_num >> 2) < 4 ? 4 : (mem_root->block_num >> 2) ) ); - - if (!(next = (MA_USED_MEM*) malloc(get_size))) - { - if (mem_root->error_handler) - (*mem_root->error_handler)(); - return((void *) 0); /* purecov: inspected */ - } - mem_root->block_num++; - next->next= *prev; - next->size= get_size; - next->left= get_size-ALIGN_SIZE(sizeof(MA_USED_MEM)); - *prev=next; - } - point= (void *) ((char*) next+ (next->size-next->left)); - if ((next->left-= Size) < mem_root->min_malloc) - { /* Full block */ - *prev=next->next; /* Remove block from list */ - next->next=mem_root->used; - mem_root->used=next; - mem_root->first_block_usage= 0; - } - return(point); + size_t get_size; + void * point; + MA_USED_MEM *next= 0; + MA_USED_MEM **prev; + + Size= ALIGN_SIZE(Size); + + if ((*(prev= &mem_root->free))) + { + if ((*prev)->left < Size && + mem_root->first_block_usage++ >= 16 && + (*prev)->left < 4096) + { + next= *prev; + *prev= next->next; + next->next= mem_root->used; + mem_root->used= next; + mem_root->first_block_usage= 0; + } + for (next= *prev; next && next->left < Size; next= next->next) + prev= &next->next; + } + if (! next) + { /* Time to alloc new block */ + get_size= MAX(Size+ALIGN_SIZE(sizeof(MA_USED_MEM)), + (mem_root->block_size & ~1) * ( (mem_root->block_num >> 2) < 4 ? 4 : (mem_root->block_num >> 2) ) ); + + if (!(next = (MA_USED_MEM*) malloc(get_size))) + { + if (mem_root->error_handler) + (*mem_root->error_handler)(); + return((void *) 0); /* purecov: inspected */ + } + mem_root->block_num++; + next->next= *prev; + next->size= get_size; + next->left= get_size-ALIGN_SIZE(sizeof(MA_USED_MEM)); + *prev=next; + } + point= (void *) ((char*) next+ (next->size-next->left)); + if ((next->left-= Size) < mem_root->min_malloc) + { /* Full block */ + *prev=next->next; /* Remove block from list */ + next->next=mem_root->used; + mem_root->used=next; + mem_root->first_block_usage= 0; + } + return(point); #endif } void ma_free_root(MA_MEM_ROOT *root, myf MyFlags) { - MA_USED_MEM *next,*old; - - if (!root) - return; /* purecov: inspected */ - if (!(MyFlags & MY_KEEP_PREALLOC)) - root->pre_alloc=0; - - for ( next=root->used; next ;) - { - old=next; next= next->next ; - if (old != root->pre_alloc) - free(old); - } - for (next= root->free ; next ; ) - { - old=next; next= next->next ; - if (old != root->pre_alloc) - free(old); - } - root->used=root->free=0; - if (root->pre_alloc) - { - root->free=root->pre_alloc; - root->free->left=root->pre_alloc->size-ALIGN_SIZE(sizeof(MA_USED_MEM)); - root->free->next=0; - } + MA_USED_MEM *next,*old; + + if (!root) + return; /* purecov: inspected */ + if (!(MyFlags & MY_KEEP_PREALLOC)) + root->pre_alloc=0; + + for ( next=root->used; next ;) + { + old=next; next= next->next ; + if (old != root->pre_alloc) + free(old); + } + for (next= root->free ; next ; ) + { + old=next; next= next->next ; + if (old != root->pre_alloc) + free(old); + } + root->used=root->free=0; + if (root->pre_alloc) + { + root->free=root->pre_alloc; + root->free->left=root->pre_alloc->size-ALIGN_SIZE(sizeof(MA_USED_MEM)); + root->free->next=0; + } } @@ -453,64 +455,74 @@ int test_ps_async(MYSQL* proxy, MYSQL* admin) { } int main(int argc, char** argv) { - CommandLine cl; - if(cl.getEnv()) - return exit_status(); - - plan(4); + plan(2+2+2 + 4); diag("Testing PS async store result"); MYSQL* admin = mysql_init(NULL); - if (!admin) - return EXIT_FAILURE; - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(admin)); return EXIT_FAILURE; - } - - MYSQL* proxy = mysql_init(NULL); - if (!proxy) { - return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == admin->net.compress, "Compression: (%d)", admin->net.compress); } // First test without 'CLIENT_DEPRECATE_EOF' support { // configure the connection as not blocking diag("Setting mysql connection non blocking"); + MYSQL* proxy = mysql_init(NULL); mysql_options(proxy, MYSQL_OPT_NONBLOCK, 0); - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy->net.compress, "Compression: (%d)", proxy->net.compress); } test_ps_async(proxy, admin); - } - - mysql_close(proxy); - proxy = mysql_init(NULL); - if (!proxy) { - return EXIT_FAILURE; + mysql_close(proxy); } // Enable 'CLIENT_DEPRECATE_EOF' support and retest { // configure the connection as not blocking diag("Setting mysql connection non blocking"); + MYSQL* proxy = mysql_init(NULL); mysql_options(proxy, MYSQL_OPT_NONBLOCK, 0); proxy->options.client_flag |= CLIENT_DEPRECATE_EOF; - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy->net.compress, "Compression: (%d)", proxy->net.compress); } test_ps_async(proxy, admin); + mysql_close(proxy); } - mysql_close(proxy); mysql_library_end(); return exit_status(); diff --git a/test/tap/tests/test_ps_hg_routing-t.cpp b/test/tap/tests/test_ps_hg_routing-t.cpp index 02a514f111..ddd799ad61 100644 --- a/test/tap/tests/test_ps_hg_routing-t.cpp +++ b/test/tap/tests/test_ps_hg_routing-t.cpp @@ -13,36 +13,44 @@ #include +CommandLine cl; + int main(int argc, char** argv) { - CommandLine cl; - char buf[1024]; + char buf[1024]; const int STRING_SIZE=32; - if(cl.getEnv()) - return exit_status(); - - plan(1); + plan(2+2 + 1); diag("Testing PS host groups routing"); MYSQL* mysqladmin = mysql_init(NULL); - if (!mysqladmin) - return exit_status(); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysqladmin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysqladmin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysqladmin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysqladmin)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysqladmin)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysqladmin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysqladmin->net.compress, "Compression: (%d)", mysqladmin->net.compress); } MYSQL* mysql = mysql_init(NULL); - if (!mysql) - return exit_status(); - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - fprintf(stderr, "Failed to connect to database: Error: %s\n", - mysql_error(mysql)); + fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } MYSQL_QUERY(mysql, "create database if not exists test"); diff --git a/test/tap/tests/test_ps_large_result-t.cpp b/test/tap/tests/test_ps_large_result-t.cpp index 52e6caaba9..8866fb6217 100644 --- a/test/tap/tests/test_ps_large_result-t.cpp +++ b/test/tap/tests/test_ps_large_result-t.cpp @@ -14,6 +14,8 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + const int NUM_ROWS=10000; int restore_admin(MYSQL* mysqladmin) { @@ -26,32 +28,38 @@ int restore_admin(MYSQL* mysqladmin) { } int main(int argc, char** argv) { - CommandLine cl; - - if(cl.getEnv()) - return exit_status(); - plan(9); + plan(2+2 + 9); diag("Testing PS large resultset"); MYSQL* mysqladmin = mysql_init(NULL); - if (!mysqladmin) - return exit_status(); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysqladmin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysqladmin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysqladmin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysqladmin)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysqladmin)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysqladmin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysqladmin->net.compress, "Compression: (%d)", mysqladmin->net.compress); } MYSQL* mysql = mysql_init(NULL); - if (!mysql) - return exit_status(); - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysql)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } MYSQL_QUERY(mysqladmin, "delete from mysql_query_rules"); diff --git a/test/tap/tests/test_ps_no_store-t.cpp b/test/tap/tests/test_ps_no_store-t.cpp index a64b507bf9..b3f94a5b1d 100644 --- a/test/tap/tests/test_ps_no_store-t.cpp +++ b/test/tap/tests/test_ps_no_store-t.cpp @@ -10,6 +10,9 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + + const int NUM_ROWS=5; int restore_admin(MYSQL* mysqladmin) { @@ -22,32 +25,38 @@ int restore_admin(MYSQL* mysqladmin) { } int main(int argc, char** argv) { - CommandLine cl; - - if(cl.getEnv()) - return exit_status(); - plan(3); + plan(2+2 + 3); diag("Testing PS large resultset"); MYSQL* mysqladmin = mysql_init(NULL); - if (!mysqladmin) - return exit_status(); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysqladmin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysqladmin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysqladmin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysqladmin)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysqladmin)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysqladmin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysqladmin->net.compress, "Compression: (%d)", mysqladmin->net.compress); } MYSQL* mysql = mysql_init(NULL); - if (!mysql) - return exit_status(); - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysql)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } MYSQL_QUERY(mysqladmin, "delete from mysql_query_rules"); diff --git a/test/tap/tests/test_query_cache_soft_ttl_pct-t.cpp b/test/tap/tests/test_query_cache_soft_ttl_pct-t.cpp index 2eff27d901..1e0f55c8a3 100644 --- a/test/tap/tests/test_query_cache_soft_ttl_pct-t.cpp +++ b/test/tap/tests/test_query_cache_soft_ttl_pct-t.cpp @@ -48,12 +48,21 @@ class timer { }; void run_dummy_query(double* timer_result) { - MYSQL* proxy_mysql = mysql_init(NULL); + MYSQL* proxy_mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_mysql)); *timer_result = -1.0; return; + } else { + const char * c = mysql_get_ssl_cipher(proxy_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_mysql->net.compress, "Compression: (%d)", proxy_mysql->net.compress); } for (int i = 0; i < NUM_QUERIES; i++) { @@ -110,17 +119,21 @@ std::map get_digest_stats_dummy_query(MYSQL* proxy_admin) { int main(int argc, char** argv) { - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - - plan(3); // always specify the number of tests that are going to be performed + plan(2+2+2*NUM_THREADS + 3); // always specify the number of tests that are going to be performed MYSQL* proxy_admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_admin->net.compress, "Compression: (%d)", proxy_admin->net.compress); } vector admin_queries = { @@ -139,10 +152,19 @@ int main(int argc, char** argv) { std::map stats_before = get_digest_stats_dummy_query(proxy_admin); MYSQL* proxy_mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_mysql)); mysql_close(proxy_admin); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_mysql->net.compress, "Compression: (%d)", proxy_mysql->net.compress); } diag("Running: %s", DUMMY_QUERY); diff --git a/test/tap/tests/test_query_rules_fast_routing_algorithm-t.cpp b/test/tap/tests/test_query_rules_fast_routing_algorithm-t.cpp index 81b8c39ee4..8826ee4b02 100644 --- a/test/tap/tests/test_query_rules_fast_routing_algorithm-t.cpp +++ b/test/tap/tests/test_query_rules_fast_routing_algorithm-t.cpp @@ -31,6 +31,8 @@ using std::vector; // Used for 'extract_module_host_port' #include "modules_server_test.h" +CommandLine cl; + void parse_result_json_column(MYSQL_RES *result, json& j) { if(!result) return; MYSQL_ROW row; @@ -160,9 +162,7 @@ int create_mysql_servers_range( return EXIT_SUCCESS; }; -int create_fast_routing_rules_range( - const CommandLine& cl, MYSQL* admin, const pair& host_port, uint32_t rng_init, uint32_t rng_end -) { +int create_fast_routing_rules_range(MYSQL* admin, const pair& host_port, uint32_t rng_init, uint32_t rng_end) { const string init { std::to_string(rng_init) }; const string end { std::to_string(rng_end) }; @@ -242,7 +242,7 @@ int test_fast_routing_algorithm( diag("Initial 'mysql_query_rules_memory' of '%d'", init_rules_mem_stats); // Check that fast_routing rules are being properly triggered - c_err = create_fast_routing_rules_range(cl, admin, host_port, rng_init, rng_end); + c_err = create_fast_routing_rules_range(admin, host_port, rng_init, rng_end); if (c_err) { return EXIT_FAILURE; } MYSQL_QUERY_T(admin, "LOAD MYSQL QUERY RULES TO RUNTIME"); @@ -388,26 +388,38 @@ int test_fast_routing_algorithm( int main(int argc, char** argv) { // `5` logic checks + 20*3 checks per query rule, per test - plan((8 + 20*3) * 2); + plan(2+2 + (8 + 20*3) * 2); CommandLine cl; - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - MYSQL* proxy = mysql_init(NULL); - MYSQL* admin = mysql_init(NULL); - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy->net.compress, "Compression: (%d)", proxy->net.compress); } + MYSQL* admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == admin->net.compress, "Compression: (%d)", admin->net.compress); } pair host_port {}; diff --git a/test/tap/tests/test_query_rules_routing-t.cpp b/test/tap/tests/test_query_rules_routing-t.cpp index 792ef90ae9..f0a352ac1b 100644 --- a/test/tap/tests/test_query_rules_routing-t.cpp +++ b/test/tap/tests/test_query_rules_routing-t.cpp @@ -27,6 +27,8 @@ #include "tap.h" #include "utils.h" +CommandLine cl; + int g_seed = 0; inline int fastrand() { @@ -313,30 +315,52 @@ int create_testing_tables(MYSQL* proxysql, uint32_t num_tables) { } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - plan(dst_hostgroup_tests.size()); + plan(2+2+2 + dst_hostgroup_tests.size()); - MYSQL* proxysql_admin = mysql_init(NULL); MYSQL* proxysql_text = mysql_init(NULL); - MYSQL* proxysql_stmt = mysql_init(NULL); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_text, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_text, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_text, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_text)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_text); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_text->net.compress, "Compression: (%d)", proxysql_text->net.compress); } + + MYSQL* proxysql_stmt = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_stmt, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_stmt, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_stmt, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_stmt)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_stmt); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_stmt->net.compress, "Compression: (%d)", proxysql_stmt->net.compress); } + + MYSQL* proxysql_admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } // Disable 'auto_increment_delay_multiplex' for avoiding unintentionally diff --git a/test/tap/tests/test_query_timeout-t.cpp b/test/tap/tests/test_query_timeout-t.cpp index 9f4af5f6b5..a8bd85aad3 100644 --- a/test/tap/tests/test_query_timeout-t.cpp +++ b/test/tap/tests/test_query_timeout-t.cpp @@ -11,40 +11,48 @@ #include "command_line.h" #include "utils.h" +using std::string; + +CommandLine cl; + inline unsigned long long monotonic_time() { - struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000); + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000); } -using std::string; - int main(int argc, char** argv) { - CommandLine cl; - - if(cl.getEnv()) - return exit_status(); - plan(1); + plan(2+2 + 1); MYSQL* mysql = mysql_init(NULL); - if (!mysql) - return exit_status(); - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); + fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } MYSQL* admin = mysql_init(NULL); - if (!admin) { - fprintf(stderr, "Failed 'mysql_init'\n"); - return exit_status(); - } - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - fprintf(stderr, "Failed to connect to Admin: Error: %s\n", mysql_error(admin)); + fprintf(stderr, "Failed to connect to Admin: Error: %s\n", mysql_error(admin)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == admin->net.compress, "Compression: (%d)", admin->net.compress); } const string poll_query { "SELECT variable_value FROM global_variables WHERE variable_name='mysql-poll_timeout'" }; diff --git a/test/tap/tests/test_read_only_actions_offline_hard_servers-t.cpp b/test/tap/tests/test_read_only_actions_offline_hard_servers-t.cpp index 90380e20f9..651f2bf07e 100644 --- a/test/tap/tests/test_read_only_actions_offline_hard_servers-t.cpp +++ b/test/tap/tests/test_read_only_actions_offline_hard_servers-t.cpp @@ -24,6 +24,8 @@ } \ } while(0) +CommandLine cl; + const uint32_t SYNC_TIMEOUT = 10; using mysql_server_tuple = std::tuple; @@ -32,17 +34,20 @@ using replication_hostgroups_tuple = std::tuple; MYSQL* create_new_connection(const char* host, const char* username, const char* password, int port) { MYSQL* mysql = mysql_init(NULL); - - if (!mysql) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); - goto __exit; - } - + diag("Connecting: username='%s' cl.use_ssl=%d cl.compression=%d", username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, host, username, password, NULL, port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); mysql_close(mysql); mysql = NULL; goto __exit; + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } __exit: @@ -101,9 +106,7 @@ int sync_checker(MYSQL* r_proxy_admin, const std::vector& queries, } } -int check_nodes_sync( - const CommandLine& cl, const std::vector& core_nodes, const std::string& check_query, uint32_t sync_timeout -) { +int check_nodes_sync(const std::vector& core_nodes, const std::string& check_query, uint32_t sync_timeout) { int ret_status = EXIT_FAILURE; for (const auto& node : core_nodes) { @@ -111,9 +114,18 @@ int check_nodes_sync( const int port = std::stol(node[1]); MYSQL* c_node_admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(c_node_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(c_node_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(c_node_admin, host.c_str(), cl.admin_username, cl.admin_password, NULL, port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(c_node_admin)); goto __exit; + } else { + const char * c = mysql_get_ssl_cipher(c_node_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == c_node_admin->net.compress, "Compression: (%d)", c_node_admin->net.compress); } int not_synced = sync_checker(c_node_admin, { check_query }, sync_timeout); @@ -192,7 +204,7 @@ int insert_mysql_servers_records(MYSQL* proxy_admin, const std::vector core_nodes; std::string check_no_primary_query; @@ -564,7 +576,7 @@ int test_read_only_offline_hard_servers(MYSQL* proxy_admin, const CommandLine& c check_no_primary_query, cl.host, cl.admin_port ); - int check_res = check_nodes_sync(cl, core_nodes, check_no_primary_query, SYNC_TIMEOUT); + int check_res = check_nodes_sync(core_nodes, check_no_primary_query, SYNC_TIMEOUT); if (check_res != EXIT_SUCCESS) { goto cleanup; } @@ -575,11 +587,11 @@ int test_read_only_offline_hard_servers(MYSQL* proxy_admin, const CommandLine& c MYSQL_QUERY__(proxy_admin, "LOAD PROXYSQL SERVERS TO RUNTIME"); } - if (test_scenario_1(proxy_admin, cl) != EXIT_SUCCESS) { + if (test_scenario_1(proxy_admin) != EXIT_SUCCESS) { goto cleanup; } - if (test_scenario_2(proxy_admin, cl) != EXIT_SUCCESS) { + if (test_scenario_2(proxy_admin) != EXIT_SUCCESS) { goto cleanup; } @@ -604,10 +616,15 @@ int test_read_only_offline_hard_servers(MYSQL* proxy_admin, const CommandLine& c for (const auto& row : core_nodes) { const std::string host{ row[0] }; const int port = std::stol(row[1]); - MYSQL* c_node_admin = mysql_init(NULL); diag("RESTORING: Inserting into node '%s:%d'", host.c_str(), port); + MYSQL* c_node_admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(c_node_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(c_node_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(c_node_admin, host.c_str(), cl.admin_username, cl.admin_password, NULL, port, NULL, 0)) { const std::string err_msg{ "Connection to core node failed with '" + std::string { mysql_error(c_node_admin) } + "'. Retrying..." @@ -615,6 +632,10 @@ int test_read_only_offline_hard_servers(MYSQL* proxy_admin, const CommandLine& c fprintf(stderr, "File %s, line %d, Error: `%s`\n", __FILE__, __LINE__, err_msg.c_str()); mysql_close(c_node_admin); continue; + } else { + const char * c = mysql_get_ssl_cipher(c_node_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == c_node_admin->net.compress, "Compression: (%d)", c_node_admin->net.compress); } int my_rc = mysql_query(c_node_admin, insert_query.c_str()); @@ -637,7 +658,7 @@ int test_read_only_offline_hard_servers(MYSQL* proxy_admin, const CommandLine& c ); // Wait for the other nodes to sync ProxySQL servers to include Primary - int check_res = check_nodes_sync(cl, core_nodes, check_no_primary_query, SYNC_TIMEOUT); + int check_res = check_nodes_sync(core_nodes, check_no_primary_query, SYNC_TIMEOUT); if (check_res != EXIT_SUCCESS) { return EXIT_FAILURE; } // Recover the old ProxySQL servers from backup in primary @@ -653,36 +674,30 @@ int test_read_only_offline_hard_servers(MYSQL* proxy_admin, const CommandLine& c int main(int, char**) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - - plan(9+9); + plan(2+2*20 + 9+9); MYSQL* proxy_admin = mysql_init(NULL); - - // Initialize connections - if (!proxy_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_admin)); - return EXIT_FAILURE; - } - - // Connnect to local proxysql + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_admin->net.compress, "Compression: (%d)", proxy_admin->net.compress); } diag(">> test_read_only_offline_hard_servers() >> Primary node included in cluster\n"); - if (test_read_only_offline_hard_servers(proxy_admin, cl, false) != EXIT_SUCCESS) { + if (test_read_only_offline_hard_servers(proxy_admin, false) != EXIT_SUCCESS) { goto cleanup; } diag(">> test_read_only_offline_hard_servers() >> Primary node isolated from cluster\n"); - if (test_read_only_offline_hard_servers(proxy_admin, cl, true) != EXIT_SUCCESS) { + if (test_read_only_offline_hard_servers(proxy_admin, true) != EXIT_SUCCESS) { goto cleanup; } diff --git a/test/tap/tests/test_rw_binary_data-t.cpp b/test/tap/tests/test_rw_binary_data-t.cpp index 748d62aedd..2d872f7c69 100644 --- a/test/tap/tests/test_rw_binary_data-t.cpp +++ b/test/tap/tests/test_rw_binary_data-t.cpp @@ -35,8 +35,11 @@ using std::vector; using std::string; +CommandLine cl; + const std::string fdev_random { "/dev/random" }; const size_t NUM_TESTS = 100; +const size_t MAX_COLUMNS = 5; // starting at 1 /** * @brief Create a random binary string of the supplied size. The string isn't allowed to contain single @@ -48,6 +51,7 @@ const size_t NUM_TESTS = 100; * * @return The randomly generated binary string. */ + int get_random_bin_str(std::size_t str_size, string& str_bin_data, bool rm_final_5c = true) { std::ifstream ifs_random(fdev_random, std::ios::binary); if (!ifs_random.is_open()) { @@ -385,24 +389,37 @@ void stmt_protocol_check(MYSQL* proxy, MYSQL* admin, const size_t idx, const vec } int main(int argc, char** argv) { - CommandLine cl; - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } + plan(2+2 + (MAX_COLUMNS-1)*(2*NUM_TESTS+1)); - MYSQL* proxy = mysql_init(NULL); MYSQL* admin = mysql_init(NULL); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == admin->net.compress, "Compression: (%d)", admin->net.compress); } + + MYSQL* proxy = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - // if (!mysql_real_connect(proxy, cl.host, cl.username, cl.password, NULL, 13306, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy->net.compress, "Compression: (%d)", proxy->net.compress); } // Reset 'stats_mysql_query_digest' to verify that test doesn't pollute the content @@ -418,8 +435,6 @@ int main(int argc, char** argv) { // We just care about the data, so we intentionally ignore '\' MYSQL_QUERY(proxy, "SET sql_mode='NO_BACKSLASH_ESCAPES'"); - size_t MAX_COLUMNS = 5; - for (size_t num_columns = 1; num_columns < MAX_COLUMNS; num_columns++) { string create_table_query { gen_create_table(num_columns, "DEFAULT CHARSET=latin2") }; diff --git a/test/tap/tests/test_server_sess_status-t.cpp b/test/tap/tests/test_server_sess_status-t.cpp index cf743b2759..471245b5df 100644 --- a/test/tap/tests/test_server_sess_status-t.cpp +++ b/test/tap/tests/test_server_sess_status-t.cpp @@ -20,6 +20,8 @@ using std::pair; using std::string; +CommandLine cl; + int get_user_def_hg(MYSQL* admin, const string& user) { const string sel_q { "SELECT default_hostgroup FROM mysql_users WHERE username='" + user + "'" }; if (mysql_query(admin, sel_q.c_str())) { @@ -78,28 +80,38 @@ pair get_def_srv_host(MYSQL* admin, const string user) { } int main(int argc, char** argv) { - CommandLine cl; // TODO: Harcoded for now, this is an initial version of the test. - plan(6); - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } + plan(2+2+2 + 6); MYSQL* proxy = mysql_init(NULL); - MYSQL* mysql = mysql_init(NULL); - MYSQL* admin = mysql_init(NULL); - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy->net.compress, "Compression: (%d)", proxy->net.compress); } + MYSQL* admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == admin->net.compress, "Compression: (%d)", admin->net.compress); } const pair srv_host { get_def_srv_host(admin, cl.username) }; @@ -109,9 +121,19 @@ int main(int argc, char** argv) { } { + MYSQL* mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, srv_host.first.c_str(), cl.username, cl.password, NULL, srv_host.second, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy)); goto cleanup; + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } int exp_mysql_srv_st = SERVER_STATUS_AUTOCOMMIT; @@ -192,11 +214,11 @@ int main(int argc, char** argv) { "ProxySQL new server status should match expected - exp: '%d', act:'%d'", exp_proxy_srv_st, proxy->server_status ); + mysql_close(mysql); } cleanup: mysql_close(proxy); - mysql_close(mysql); mysql_close(admin); return exit_status(); diff --git a/test/tap/tests/test_session_status_flags-t.cpp b/test/tap/tests/test_session_status_flags-t.cpp index 181c2561b5..90812ace20 100644 --- a/test/tap/tests/test_session_status_flags-t.cpp +++ b/test/tap/tests/test_session_status_flags-t.cpp @@ -36,6 +36,8 @@ using std::function; using nlohmann::json; +CommandLine cl; + void parse_result_json_column(MYSQL_RES *result, json& j) { if(!result) return; MYSQL_ROW row; @@ -168,14 +170,22 @@ function capture_exception(const function }; } -int prepare_stmt_queries(const CommandLine& cl, const vector& p_queries) { +int prepare_stmt_queries(const vector& p_queries) { // 1. Prepare the stmt in a connection - MYSQL* proxy_mysql = mysql_init(NULL); + MYSQL* proxy_mysql = mysql_init(NULL); + if (cl.use_ssl) + mysql_ssl_set(proxy_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_mysql, MYSQL_OPT_COMPRESS, NULL); diag("%s: Openning INITIAL connection...", tap_curtime().c_str()); if (!mysql_real_connect(proxy_mysql, cl.root_host, cl.root_username, cl.root_password, NULL, cl.root_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_mysql)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_mysql->net.compress, "Compression: (%d)", proxy_mysql->net.compress); } vector queries {}; @@ -499,9 +509,8 @@ int exec_and_discard(MYSQL* proxy_mysql, const vector& queries) { using queries_exec_t = function&)>; -int exec_simple_conn_tests( - const CommandLine& cl, const vector& tests_def, const queries_exec_t& queries_exec -) { +int exec_simple_conn_tests(const vector& tests_def, const queries_exec_t& queries_exec) { + for (const auto& test_def : tests_def) { const string& test_name { std::get(test_def) }; const setup_teardown_t& setup_teardown = std::get(test_def); @@ -510,10 +519,18 @@ int exec_simple_conn_tests( diag("Starting test '%s'", test_name.c_str()); MYSQL* proxy_mysql = mysql_init(NULL); - + diag("Connecting: cl.root_username='%s' cl.use_ssl=%d cl.compression=%d", cl.root_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_mysql, cl.root_host, cl.root_username, cl.root_password, NULL, cl.root_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_mysql)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_mysql->net.compress, "Compression: (%d)", proxy_mysql->net.compress); } // TEST SETUP queries @@ -532,7 +549,7 @@ int exec_simple_conn_tests( return EXIT_SUCCESS; } -int text_exec_simple_conn_tests(const CommandLine& cl, const vector& tests_def) { +int text_exec_simple_conn_tests(const vector& tests_def) { for (const auto& test_def : tests_def) { const string& test_name { std::get(test_def) }; const setup_teardown_t& setup_teardown = std::get(test_def); @@ -541,10 +558,18 @@ int text_exec_simple_conn_tests(const CommandLine& cl, const vector& diag("Starting test '%s'", test_name.c_str()); MYSQL* proxy_mysql = mysql_init(NULL); - + diag("Connecting: cl.root_username='%s' cl.use_ssl=%d cl.compression=%d", cl.root_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_mysql, cl.root_host, cl.root_username, cl.root_password, NULL, cl.root_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_mysql)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_mysql->net.compress, "Compression: (%d)", proxy_mysql->net.compress); } // TEST SETUP queries @@ -565,9 +590,7 @@ int text_exec_simple_conn_tests(const CommandLine& cl, const vector& const double COLISSION_PROB = 1e-8; -int _wait_for_replication( - const CommandLine& cl, MYSQL* proxy_admin, const std::string& check, uint32_t timeout, uint32_t read_hg -) { +int _wait_for_replication(MYSQL* proxy_admin, const std::string& check, uint32_t timeout, uint32_t read_hg) { const std::string t_count_reader_hg_servers { "SELECT COUNT(*) FROM mysql_servers WHERE hostgroup_id=%d" }; @@ -601,9 +624,18 @@ int _wait_for_replication( while (elapsed.count() < timeout && queries < retries) { MYSQL* proxy = mysql_init(NULL); + diag("Connecting: cl.root_username='%s' cl.use_ssl=%d cl.compression=%d", cl.root_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy, cl.root_host, cl.root_username, cl.root_password, NULL, cl.root_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy->net.compress, "Compression: (%d)", proxy->net.compress); } int rc = mysql_query(proxy, check.c_str()); @@ -644,7 +676,7 @@ int _wait_for_replication( return result; } -int stmt_exec_simple_conn_tests(const CommandLine& cl, const vector& tests_def) { +int stmt_exec_simple_conn_tests(const vector& tests_def) { for (const auto& test_def : tests_def) { const string& test_name { std::get(test_def) }; const setup_teardown_t& setup_teardown = std::get(test_def); @@ -653,10 +685,18 @@ int stmt_exec_simple_conn_tests(const CommandLine& cl, const vector& diag("Starting test '%s'", test_name.c_str()); MYSQL* proxy_mysql = mysql_init(NULL); - + diag("Connecting: cl.root_username='%s' cl.use_ssl=%d cl.compression=%d", cl.root_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_mysql, cl.root_host, cl.root_username, cl.root_password, NULL, cl.root_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_mysql)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_mysql->net.compress, "Compression: (%d)", proxy_mysql->net.compress); } // TEST SETUP queries @@ -673,12 +713,21 @@ int stmt_exec_simple_conn_tests(const CommandLine& cl, const vector& diag("Executing query '%s' with REPLICATION WAIT", query.c_str()); MYSQL* admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == admin->net.compress, "Compression: (%d)", admin->net.compress); } - int wait_res = _wait_for_replication(cl, admin, query, 10, 1); + int wait_res = _wait_for_replication(admin, query, 10, 1); if (wait_res != EXIT_SUCCESS) { diag("Waiting for replication FAILED. EXITING"); return EXIT_FAILURE; @@ -688,7 +737,7 @@ int stmt_exec_simple_conn_tests(const CommandLine& cl, const vector& } } - prepare_stmt_queries(cl, test_queries); + prepare_stmt_queries(test_queries); exec_stmt_queries(proxy_mysql, test_queries); @@ -960,12 +1009,21 @@ const vector test_compression_queries { { "PROXYSQL INTERNAL SESSION", {}, {{{"conn","status","compression"}, check_if_tg_elem_is_true, "COMPRESSED_CONNECTION"}} }, }; -int test_client_conn_compression_st(const CommandLine& cl) { - MYSQL* proxysql_mysql = mysql_init(NULL); +int test_client_conn_compression_st() { + MYSQL* proxysql_mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_mysql, cl.root_host, cl.root_username, cl.root_password, NULL, cl.root_port, NULL, CLIENT_COMPRESS)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(proxysql_mysql->net.compress == 1, "Compression: (%d)", proxysql_mysql->net.compress); } exec_test_queries(proxysql_mysql, test_compression_queries); @@ -1003,11 +1061,6 @@ uint32_t compute_planned_tests(const vector text_tests_def, const ve } int main(int argc, char *argv[]) { - CommandLine cl; - - if(cl.getEnv()) { - return exit_status(); - } uint32_t computed_exp_tests = compute_planned_tests(text_tests_defs, stmt_compatible_tests); uint32_t compression_exp_tests = 2; @@ -1015,12 +1068,21 @@ int main(int argc, char *argv[]) { diag("Computed simple connection 'TEXT' and 'STMT' tests where: '%d'", computed_exp_tests); diag("Special connections tests where: '%d'", compression_exp_tests); - plan(compression_exp_tests + computed_exp_tests); + plan(2+2+2*6+2*4+2*102+2*10+2*4 + compression_exp_tests + computed_exp_tests); MYSQL* proxy_admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_admin->net.compress, "Compression: (%d)", proxy_admin->net.compress); } // Set a replication lag inferior to default one (60). This is to prevent reads @@ -1048,17 +1110,17 @@ int main(int argc, char *argv[]) { }; diag("####### START SPECIAL CONNECTIONS TESTS #######"); - int t_res = test_client_conn_compression_st(cl); + int t_res = test_client_conn_compression_st(); if (t_res) { goto cleanup; } diag("####### END SPECIAL PROTOCOL TESTS #######\n"); diag("####### START TEXT PROTOCOL TESTS #######"); - t_res = text_exec_simple_conn_tests(cl, text_tests_defs); + t_res = text_exec_simple_conn_tests(text_tests_defs); if (t_res) { goto cleanup; } diag("####### END TEXT PROTOCOL TESTS #######\n"); diag("####### START STMT PROTOCOL TESTS #######"); - t_res = stmt_exec_simple_conn_tests(cl, stmt_supp_tests); + t_res = stmt_exec_simple_conn_tests(stmt_supp_tests); if (t_res) { goto cleanup; } diag("####### END STMT PROTOCOL TESTS #######\n"); diff --git a/test/tap/tests/test_set_character_results-t.cpp b/test/tap/tests/test_set_character_results-t.cpp index a4499ac04c..81bd9318ba 100644 --- a/test/tap/tests/test_set_character_results-t.cpp +++ b/test/tap/tests/test_set_character_results-t.cpp @@ -10,39 +10,42 @@ #include "command_line.h" #include "utils.h" -int main(int argc, char** argv) { - CommandLine cl; +CommandLine cl; - if(cl.getEnv()) - return exit_status(); +int main(int argc, char** argv) { - plan(2); + plan(2+2 + 2); diag("Testing SET CHARACTER SET"); MYSQL* mysqladmin = mysql_init(NULL); - if (!mysqladmin) - return exit_status(); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysqladmin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysqladmin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysqladmin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysqladmin)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysqladmin)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysqladmin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysqladmin->net.compress, "Compression: (%d)", mysqladmin->net.compress); } MYSQL* mysql = mysql_init(NULL); - if (!mysql) - return exit_status(); - - if (mysql_options(mysql, MYSQL_SET_CHARSET_NAME, "utf8")) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysql)); - return exit_status(); - } - + mysql_options(mysql, MYSQL_SET_CHARSET_NAME, "utf8"); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - fprintf(stderr, "Failed to connect to database: Error: %s\n", - mysql_error(mysql)); + fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } MYSQL_QUERY(mysql, "set character_set_results=NULL"); diff --git a/test/tap/tests/test_set_collation-t.cpp b/test/tap/tests/test_set_collation-t.cpp index cc3a6df4b9..03c07470e2 100644 --- a/test/tap/tests/test_set_collation-t.cpp +++ b/test/tap/tests/test_set_collation-t.cpp @@ -18,6 +18,8 @@ #define N_ITERATION_2 2 #define N_ITERATION_3 3 +CommandLine cl; + MARIADB_CHARSET_INFO * proxysqlTap_find_charset_collate(const char *collatename) { MARIADB_CHARSET_INFO *c = (MARIADB_CHARSET_INFO *)mariadb_compiled_charsets; do { @@ -39,17 +41,26 @@ MARIADB_CHARSET_INFO * proxysqlTap_find_charset_collate(const char *collatename) * * @return Returns '0' in case of success, '-1' otherwise. */ -int create_proxysql_connections(const CommandLine& cl, const std::vector& collations, std::vector& conns) { +int create_proxysql_connections(const std::vector& collations, std::vector& conns) { std::vector _conns {}; for (const auto& collation : collations) { + MYSQL* mysql = mysql_init(NULL); const MARIADB_CHARSET_INFO* charset = proxysqlTap_find_charset_collate(collation.c_str()); mysql->charset = charset; - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysql)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } _conns.push_back(mysql); @@ -61,7 +72,7 @@ int create_proxysql_connections(const CommandLine& cl, const std::vector& collations, std::vector& conns) { +int run_change_user_on_all(const std::vector& collations, std::vector& conns) { // start a transaction in every connection // and then trigger a change user // we first create a transaction in order to force the reset of the backend using CHANGE_USER @@ -113,18 +124,13 @@ int query_and_check_session_variables(MYSQL *mysql, std::string collation, int i int main(int argc, char** argv) { - CommandLine cl; - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } std::vector conns {}; std::vector collations { "latin1_spanish_ci", "latin1_german2_ci", "latin1_danish_ci", "latin1_general_ci", "latin1_bin", "utf8_general_ci", "utf8_unicode_ci" }; int ntests = 0; - ntests += 1; // create all connections + ntests += 2*7 + 1; // create all connections ntests += (NUMBER_NEW_CONNECTIONS) * 4; ntests += (N_ITERATION_1 * collations.size()) * 4; ntests += collations.size() * 2; // number of times we will call mysql_change_user() @@ -132,7 +138,7 @@ int main(int argc, char** argv) { ntests += (N_ITERATION_3 * collations.size()) * 4; plan(ntests); - int conns_res = create_proxysql_connections(cl, collations, conns); + int conns_res = create_proxysql_connections(collations, conns); ok(conns_res == 0, "Successfully create all connections with different collations"); if (conns_res != 0) { @@ -160,7 +166,7 @@ int main(int argc, char** argv) { } // we now want to check what happens after resetting backend connections - if (run_change_user_on_all(cl, collations, conns)) + if (run_change_user_on_all(collations, conns)) return exit_status(); // we iterate and check through all the connections @@ -173,7 +179,7 @@ int main(int argc, char** argv) { // we now want to check what happens after resetting backend connections // we also reverse the order of collations std::reverse(collations.begin(), collations.end()); - if (run_change_user_on_all(cl, collations, conns)) + if (run_change_user_on_all(collations, conns)) return exit_status(); // we iterate and check through all the connections for (int i = 0; i < conns.size(); i++) { diff --git a/test/tap/tests/test_simple_embedded_HTTP_server-t.cpp b/test/tap/tests/test_simple_embedded_HTTP_server-t.cpp index 4f2860a729..869ee9a2e7 100644 --- a/test/tap/tests/test_simple_embedded_HTTP_server-t.cpp +++ b/test/tap/tests/test_simple_embedded_HTTP_server-t.cpp @@ -17,26 +17,27 @@ using std::string; +CommandLine cl; struct memory { - char *response; - size_t size; + char *response; + size_t size; }; static size_t cb(void *data, size_t size, size_t nmemb, void *userp) { - size_t realsize = size * nmemb; - struct memory *mem = (struct memory *)userp; + size_t realsize = size * nmemb; + struct memory *mem = (struct memory *)userp; - char *ptr = (char *)realloc((void *)mem->response, mem->size + realsize + 1); - if(ptr == NULL) - return 0; /* out of memory! */ + char *ptr = (char *)realloc((void *)mem->response, mem->size + realsize + 1); + if(ptr == NULL) + return 0; /* out of memory! */ - mem->response = ptr; - memcpy(&(mem->response[mem->size]), data, realsize); - mem->size += realsize; - mem->response[mem->size] = 0; + mem->response = ptr; + memcpy(&(mem->response[mem->size]), data, realsize); + mem->size += realsize; + mem->response[mem->size] = 0; - return realsize; + return realsize; } @@ -80,25 +81,22 @@ void run_request(const char *url) { } int main() { - CommandLine cl; - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - - plan(4); + plan(2 + 4); MYSQL* proxysql_admin = mysql_init(NULL); - // Initialize connections - if (!proxysql_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); - return -1; - } - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return -1; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } MYSQL_QUERY(proxysql_admin, "SET admin-web_enabled='true'"); diff --git a/test/tap/tests/test_sqlite3_server-t.cpp b/test/tap/tests/test_sqlite3_server-t.cpp index a9e2b06f93..9de918b88f 100644 --- a/test/tap/tests/test_sqlite3_server-t.cpp +++ b/test/tap/tests/test_sqlite3_server-t.cpp @@ -53,6 +53,8 @@ const int sqlite3_port = 0; #include "modules_server_test.h" +CommandLine cl; + void fetch_and_discard_results(MYSQL_RES* result, bool verbose=false) { MYSQL_ROW row = nullptr; unsigned int num_fields = 0; @@ -260,7 +262,7 @@ int check_errorlog_for_addrinuse(MYSQL* admin, fstream& logfile) { } } -string connect_with_retries(MYSQL* sqlite3, const CommandLine& cl, const pair& host_port) { +string connect_with_retries(MYSQL* sqlite3, const pair& host_port) { uint32_t n = 0; uint32_t retries = 10; bool conn_success = false; @@ -272,11 +274,21 @@ string connect_with_retries(MYSQL* sqlite3, const CommandLine& cl, const pairnet.compress, "Compression: (%d)", sqlite3->net.compress); } mysql_close(sqlite3); @@ -329,35 +341,30 @@ int enforce_sqlite_iface_change(MYSQL*admin, fstream& logfile, const uint32_t re } int main(int argc, char** argv) { - CommandLine cl; // plan as many tests as queries plan( + 2+2+2+2 + // connect 2 /* Fail to connect with wrong username and password */ + successful_queries.size() + unsuccessful_queries.size() + admin_queries.size() + sqlite_intf_queries.size() + 2 /* Check port is properly taken by ProxySQL without error after each change */ + 2 /* Connect to new/old interfaces when changed */ ); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - - MYSQL* proxysql_admin = mysql_init(NULL); - // Connect to ProxySQL Admin and check current SQLite3 configuration - if ( - !mysql_real_connect( - proxysql_admin, cl.host, cl.admin_username, cl.admin_password, - NULL, cl.admin_port, NULL, 0 - ) - ) { - fprintf( - stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, - mysql_error(proxysql_admin) - ); + MYSQL* proxysql_admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } { @@ -368,17 +375,16 @@ int main(int argc, char** argv) { goto cleanup; } - MYSQL* proxysql_sqlite3 = mysql_init(NULL); - // Connect with invalid username std::string inv_user_err {}; bool failed_to_connect = false; - if ( - !mysql_real_connect( - proxysql_sqlite3, host_port.first.c_str(), "foobar_user", cl.password, - NULL, host_port.second, NULL, 0 - ) - ) { + MYSQL* proxysql_sqlite3 = mysql_init(NULL); + diag("Connecting: username='%s' cl.use_ssl=%d cl.compression=%d", "foobar_user", cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_sqlite3, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_sqlite3, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(proxysql_sqlite3, host_port.first.c_str(), "foobar_user", cl.password, NULL, host_port.second, NULL, 0)) { inv_user_err = mysql_error(proxysql_sqlite3); failed_to_connect = true; } @@ -388,20 +394,18 @@ int main(int argc, char** argv) { "An invalid user should fail to connect to SQLite3 server, error was: %s", inv_user_err.c_str() ); - - // Reinitialize MYSQL handle mysql_close(proxysql_sqlite3); - proxysql_sqlite3 = mysql_init(NULL); // Connect with invalid password std::string inv_pass_err {}; failed_to_connect = false; - if ( - !mysql_real_connect( - proxysql_sqlite3, host_port.first.c_str(), cl.username, "foobar_pass", - NULL, host_port.second, NULL, 0 - ) - ) { + proxysql_sqlite3 = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_sqlite3, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_sqlite3, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(proxysql_sqlite3, host_port.first.c_str(), cl.username, "foobar_pass", NULL, host_port.second, NULL, 0)) { inv_pass_err = mysql_error(proxysql_sqlite3); failed_to_connect = true; } @@ -411,23 +415,22 @@ int main(int argc, char** argv) { "An invalid password should fail to connect to SQLite3 server, error was: %s", inv_pass_err.c_str() ); - - // Reinitialize MYSQL handle mysql_close(proxysql_sqlite3); - proxysql_sqlite3 = mysql_init(NULL); // Correctly connect to SQLite3 server - if ( - !mysql_real_connect( - proxysql_sqlite3, host_port.first.c_str(), cl.username, cl.password, - NULL, host_port.second, NULL, 0 - ) - ) { - fprintf( - stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, - mysql_error(proxysql_sqlite3) - ); + proxysql_sqlite3 = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_sqlite3, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_sqlite3, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(proxysql_sqlite3, host_port.first.c_str(), cl.username, cl.password, NULL, host_port.second, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_sqlite3)); goto cleanup; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_sqlite3); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_sqlite3->net.compress, "Compression: (%d)", proxysql_sqlite3->net.compress); } diag("Started performing successful queries"); @@ -465,7 +468,7 @@ int main(int argc, char** argv) { goto cleanup; } - std::string new_intf_conn_err { connect_with_retries(proxysql_sqlite3, cl, new_host_port) }; + std::string new_intf_conn_err { connect_with_retries(proxysql_sqlite3, new_host_port) }; ok( new_intf_conn_err.empty() == true, @@ -491,7 +494,7 @@ int main(int argc, char** argv) { // interface could be locked somehow by ProxySQL, and we avoid trying to stablish a connection that // could stall the test. Instead we intentionally fail. if (iface_err == 0) { - old_intf_conn_err = connect_with_retries(proxysql_sqlite3, cl, host_port); + old_intf_conn_err = connect_with_retries(proxysql_sqlite3, host_port); } else { old_intf_conn_err = "Interface failed to be changed. Skipping connection attempt..."; } diff --git a/test/tap/tests/test_sqlite3_server_and_fast_routing-t.cpp b/test/tap/tests/test_sqlite3_server_and_fast_routing-t.cpp index c53732373d..fae0e9d695 100644 --- a/test/tap/tests/test_sqlite3_server_and_fast_routing-t.cpp +++ b/test/tap/tests/test_sqlite3_server_and_fast_routing-t.cpp @@ -16,6 +16,8 @@ using query_spec = std::tuple; +CommandLine cl; + const int sqlite3_port = 0; // because the test itself is a benchmark that uses a lot of TCP ports, @@ -30,7 +32,7 @@ inline unsigned long long monotonic_time() { return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000); } -int benchmark_query_rules_fast_routing(CommandLine& cl, MYSQL* proxysql_admin, MYSQL* proxysql_mysql) { +int benchmark_query_rules_fast_routing(MYSQL* proxysql_admin, MYSQL* proxysql_mysql) { std::string s; std::pair host_port {}; @@ -74,13 +76,6 @@ int benchmark_query_rules_fast_routing(CommandLine& cl, MYSQL* proxysql_admin, M diag("Executing: %s", s.c_str()); MYSQL_QUERY(proxysql_admin, s.c_str()); - if (!mysql_real_connect(proxysql_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - fprintf( - stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, - mysql_error(proxysql_mysql) - ); - return EXIT_FAILURE; - } { unsigned long long begin; for (int i=0; i<10001; i++) { @@ -214,47 +209,70 @@ int benchmark_query_rules_fast_routing(CommandLine& cl, MYSQL* proxysql_admin, M } int main(int argc, char** argv) { - CommandLine cl; - - MYSQL * proxysql_mysql = mysql_init(NULL); - MYSQL* proxysql_admin = mysql_init(NULL); diag("This TAP test has several sleep() to give enough time to release TCP ports"); - plan(2); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - goto cleanup; - } + plan(2+2+2 + 2); // Connect to ProxySQL Admin and check current SQLite3 configuration - if ( - !mysql_real_connect( - proxysql_admin, cl.host, cl.admin_username, cl.admin_password, - NULL, cl.admin_port, NULL, 0 - ) - ) { - fprintf( - stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, - mysql_error(proxysql_admin) - ); - goto cleanup; + MYSQL* proxysql_admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); + return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); + } + + MYSQL* proxysql_mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_mysql, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(proxysql_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); + return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_mysql->net.compress, "Compression: (%d)", proxysql_mysql->net.compress); } MYSQL_QUERY(proxysql_admin, "SET mysql-query_rules_fast_routing_algorithm=1"); MYSQL_QUERY(proxysql_admin, "LOAD MYSQL QUERY RULES TO RUNTIME"); diag("Sleeping %d seconds at line %d", ST, __LINE__); - benchmark_query_rules_fast_routing(cl, proxysql_admin, proxysql_mysql); + benchmark_query_rules_fast_routing(proxysql_admin, proxysql_mysql); diag("Sleeping %d seconds at line %d", ST, __LINE__); MYSQL_QUERY(proxysql_admin, "SET mysql-query_rules_fast_routing_algorithm=2"); MYSQL_QUERY(proxysql_admin, "LOAD MYSQL QUERY RULES TO RUNTIME"); mysql_close(proxysql_mysql); + proxysql_mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_mysql, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(proxysql_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); + return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_mysql->net.compress, "Compression: (%d)", proxysql_mysql->net.compress); + } - benchmark_query_rules_fast_routing(cl, proxysql_admin, proxysql_mysql); + benchmark_query_rules_fast_routing(proxysql_admin, proxysql_mysql); diag("Sleeping %d seconds at line %d", ST, __LINE__); cleanup: diff --git a/test/tap/tests/test_ssl_connect-t.cpp b/test/tap/tests/test_ssl_connect-t.cpp index daa9d02f66..a044299f33 100644 --- a/test/tap/tests/test_ssl_connect-t.cpp +++ b/test/tap/tests/test_ssl_connect-t.cpp @@ -15,6 +15,8 @@ using std::string; +CommandLine cl; + /* this test: * enables mysql-have_ssl * retrieves all tables in the most important schemas @@ -22,13 +24,6 @@ using std::string; */ int main() { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - MYSQL* proxysql_admin = mysql_init(NULL); // Initialize connections diff --git a/test/tap/tests/test_ssl_fast_forward-1-t.cpp b/test/tap/tests/test_ssl_fast_forward-1-t.cpp index f8c5022c8d..72a596a316 100644 --- a/test/tap/tests/test_ssl_fast_forward-1-t.cpp +++ b/test/tap/tests/test_ssl_fast_forward-1-t.cpp @@ -12,6 +12,7 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; /* Several bugs were identified and fixed while developing this test: @@ -93,10 +94,6 @@ int run_queries_sets(std::vector& queries, MYSQL *my, const std::st #define ITER2 20 int main(int argc, char** argv) { - CommandLine cl; - - if(cl.getEnv()) - return exit_status(); unsigned int p = 0; p += 5*ITER1; diff --git a/test/tap/tests/test_ssl_fast_forward-2-t.cpp b/test/tap/tests/test_ssl_fast_forward-2-t.cpp index e90f4b8d94..932d4c2012 100644 --- a/test/tap/tests/test_ssl_fast_forward-2-t.cpp +++ b/test/tap/tests/test_ssl_fast_forward-2-t.cpp @@ -12,6 +12,7 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; /* this test uses a lot of code from test_ssl_fast_forward-t.cpp @@ -76,10 +77,6 @@ int run_queries_sets(std::vector& queries, MYSQL *my, const std::st #define UL 96000 // upper limit int main(int argc, char** argv) { - CommandLine cl; - - if(cl.getEnv()) - return exit_status(); unsigned int p = 0; p += 5*ITER1; diff --git a/test/tap/tests/test_ssl_fast_forward-3-t.cpp b/test/tap/tests/test_ssl_fast_forward-3-t.cpp index 24d36e3842..f080f0c319 100644 --- a/test/tap/tests/test_ssl_fast_forward-3-t.cpp +++ b/test/tap/tests/test_ssl_fast_forward-3-t.cpp @@ -98,9 +98,6 @@ void * my_conn_thread(void *arg) { int main(int argc, char** argv) { - if(cl.getEnv()) - return exit_status(); - plan(NTHR*(ITER+CPTH/2)); diag("Testing SSL and fast_forward"); diff --git a/test/tap/tests/test_ssl_large_query-1-t.cpp b/test/tap/tests/test_ssl_large_query-1-t.cpp index 896a2d955d..293f30433e 100644 --- a/test/tap/tests/test_ssl_large_query-1-t.cpp +++ b/test/tap/tests/test_ssl_large_query-1-t.cpp @@ -12,6 +12,7 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; char * username = (char *)"user1459"; char * password = (char *)"pass1459"; @@ -49,10 +50,6 @@ int run_queries_sets(std::vector& queries, MYSQL *my, const std::st int main(int argc, char** argv) { - CommandLine cl; - - if(cl.getEnv()) - return exit_status(); plan(33); diag("Testing SSL and fast_forward"); diff --git a/test/tap/tests/test_ssl_large_query-2-t.cpp b/test/tap/tests/test_ssl_large_query-2-t.cpp index eaaaada5db..897dc3dd90 100644 --- a/test/tap/tests/test_ssl_large_query-2-t.cpp +++ b/test/tap/tests/test_ssl_large_query-2-t.cpp @@ -12,6 +12,7 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; char * username = (char *)"user1459"; char * password = (char *)"pass1459"; @@ -38,10 +39,6 @@ int run_queries_sets(std::vector& queries, MYSQL *my, const std::st const std::string lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; int main(int argc, char** argv) { - CommandLine cl; - - if(cl.getEnv()) - return exit_status(); plan(2+2*ITER); diag("Testing SSL and fast_forward"); diff --git a/test/tap/tests/test_stats_proxysql_message_metrics-t.cpp b/test/tap/tests/test_stats_proxysql_message_metrics-t.cpp index 8970596977..5f5f6bde3d 100644 --- a/test/tap/tests/test_stats_proxysql_message_metrics-t.cpp +++ b/test/tap/tests/test_stats_proxysql_message_metrics-t.cpp @@ -17,6 +17,8 @@ using std::vector; using std::string; +CommandLine cl; + int induce_set_parsing_failure(MYSQL* proxy) { int rc = mysql_query(proxy, "SET NAMES"); if (rc != EXIT_FAILURE) { @@ -48,39 +50,42 @@ int test_table_reset(MYSQL* proxy_admin) { } int main(int argc, char** argv) { - CommandLine cl; plan( + 2+2 + // connection 2 + // Table reset and check empty table 3 + // Initial table population + Update check 2 // Check proper reset again ); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - MYSQL* proxy = mysql_init(NULL); - MYSQL* proxy_admin = mysql_init(NULL); - - // Initialize connections - if (!proxy) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy)); - return EXIT_FAILURE; - } - if (!proxy_admin) { - fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_admin)); - return EXIT_FAILURE; - } - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy->net.compress, "Compression: (%d)", proxy->net.compress); } + + MYSQL* proxy_admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxy_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxy_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxy_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxy_admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxy_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxy_admin->net.compress, "Compression: (%d)", proxy_admin->net.compress); } // Reset the target table and check it's empty but present in 'stats' db diff --git a/test/tap/tests/test_throttle_max_bytes_per_second_to_client-t.cpp b/test/tap/tests/test_throttle_max_bytes_per_second_to_client-t.cpp index d031f3c561..fb3ef52933 100644 --- a/test/tap/tests/test_throttle_max_bytes_per_second_to_client-t.cpp +++ b/test/tap/tests/test_throttle_max_bytes_per_second_to_client-t.cpp @@ -11,44 +11,53 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + inline unsigned long long monotonic_time() { - struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000); + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return (((unsigned long long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000); } - int main(int argc, char** argv) { - CommandLine cl; - - if(cl.getEnv()) - return exit_status(); - plan(1); + plan(2+2 + 1); MYSQL* mysqladmin = mysql_init(NULL); - if (!mysqladmin) - return exit_status(); - + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysqladmin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysqladmin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysqladmin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - fprintf(stderr, "File %s, line %d, Error: %s\n", - __FILE__, __LINE__, mysql_error(mysqladmin)); + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(mysqladmin)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysqladmin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysqladmin->net.compress, "Compression: (%d)", mysqladmin->net.compress); } + diag("Setting mysql-throttle_max_bytes_per_second_to_client=150000"); diag("Client will read from ProxySQL at no more than 150KB/s"); MYSQL_QUERY(mysqladmin, "SET mysql-throttle_max_bytes_per_second_to_client=150000"); MYSQL_QUERY(mysqladmin, "load mysql variables to runtime"); MYSQL* mysql = mysql_init(NULL); - if (!mysql) - return exit_status(); - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { - fprintf(stderr, "Failed to connect to database: Error: %s\n", - mysql_error(mysql)); + fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql)); return exit_status(); + } else { + const char * c = mysql_get_ssl_cipher(mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == mysql->net.compress, "Compression: (%d)", mysql->net.compress); } + MYSQL_RES *res; if (create_table_test_sbtest1(100,mysql)) { fprintf(stderr, "File %s, line %d, Error: create_table_test_sbtest1() failed\n", __FILE__, __LINE__); @@ -68,7 +77,11 @@ int main(int argc, char** argv) { unsigned long time_diff_ms = (end-begin)/1000; - ok(time_diff_ms>20000, "Total query execution time should be more than 20 seconds : %lums", time_diff_ms); + if (cl.compression) { + ok(time_diff_ms>5000, "Total query execution time should be more than 5 seconds : %lums", time_diff_ms); + } else { + ok(time_diff_ms>20000, "Total query execution time should be more than 20 seconds : %lums", time_diff_ms); + } MYSQL_QUERY(mysqladmin, "SET mysql-throttle_max_bytes_per_second_to_client=0"); MYSQL_QUERY(mysqladmin, "load mysql variables to runtime"); diff --git a/test/tap/tests/test_tokenizer-t.cpp b/test/tap/tests/test_tokenizer-t.cpp index a409a55ddb..95b3d34424 100644 --- a/test/tap/tests/test_tokenizer-t.cpp +++ b/test/tap/tests/test_tokenizer-t.cpp @@ -9,7 +9,6 @@ #include "tap.h" #include "command_line.h" - #include "utils.h" #include @@ -27,6 +26,8 @@ using std::pair; using std::string; using std::tuple; +CommandLine cl; + const vector> query_digest_pairs { // TODO: KnownIssue - 10 // { diff --git a/test/tap/tests/test_unshun_algorithm-t.cpp b/test/tap/tests/test_unshun_algorithm-t.cpp index 4a5714eaaf..e24efed7ce 100644 --- a/test/tap/tests/test_unshun_algorithm-t.cpp +++ b/test/tap/tests/test_unshun_algorithm-t.cpp @@ -77,6 +77,8 @@ const uint32_t SERVERS_COUNT = 10; using std::string; +CommandLine cl; + int shunn_server(MYSQL* proxysql_admin, uint32_t i, uint32_t j) { std::string t_simulator_error_query { "PROXYSQL_SIMULATOR mysql_error %d 127.0.0.1:330%d 1234" }; std::string simulator_error_q_i {}; @@ -395,29 +397,42 @@ int test_unshun_algorithm_behavior(MYSQL* proxysql_mysql, MYSQL* proxysql_admin) return EXIT_SUCCESS; } int main(int argc, char** argv) { - CommandLine cl; plan( + 2+2 + // connections 1 + (VALID_RANGE + 1) + 1 + // Variable tests SERVERS_COUNT + 1 + // Simulator error tests SERVERS_COUNT * 3 // Testing unshun_algorithm behavior ); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - MYSQL* proxysql_mysql = mysql_init(NULL); - MYSQL* proxysql_admin = mysql_init(NULL); - + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_mysql->net.compress, "Compression: (%d)", proxysql_mysql->net.compress); } + + MYSQL* proxysql_admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } { diff --git a/test/tap/tests/test_unsupported_queries-t.cpp b/test/tap/tests/test_unsupported_queries-t.cpp index 07afbb7884..ef64ae736c 100644 --- a/test/tap/tests/test_unsupported_queries-t.cpp +++ b/test/tap/tests/test_unsupported_queries-t.cpp @@ -21,6 +21,8 @@ #include "tap.h" #include "utils.h" +CommandLine cl; + /** * @brief List of the pairs holding the unsupported queries to be executed by ProxySQL * together with the error code that they should return. @@ -61,7 +63,7 @@ using query_test_info = int, // Function performing an internal 'ok' test checking that the // enabled / disabled query responds as expected - std::function + std::function >; // "SET mysql-enable_load_data_local_infile='true'", @@ -167,9 +169,8 @@ using mysql_res_row = std::vector; * @param test_for_success Select the operation mode of the test, 'true' for * testing for success, 'false' for failure. It's 'true' by default. */ -void helper_test_load_data_local_infile( - const CommandLine& cl, MYSQL* proxysql, int exp_err=0, bool test_for_success=true -) { +void helper_test_load_data_local_infile(MYSQL* proxysql, int exp_err=0, bool test_for_success=true) { + std::string datafile { std::string { cl.workdir } + "load_data_local_datadir/insert_data.txt" }; @@ -283,18 +284,21 @@ void helper_test_load_data_local_infile( * 'mysql-verbose_query_error' set to 'true'. This test only purpose is * to exercise the code performing the additional extra logging. */ -void test_verbose_error_load_data_local_infile( - const CommandLine& cl, MYSQL* proxysql, int exp_err=0, bool test_for_success=true -) { - MYSQL* proxysql_admin = mysql_init(NULL); +void test_verbose_error_load_data_local_infile(MYSQL* proxysql, int exp_err=0, bool test_for_success=true) { - if ( - !mysql_real_connect( - proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0 - ) - ) { + MYSQL* proxysql_admin = mysql_init(NULL); + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { diag("File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } std::vector verbose_query_error_true { @@ -309,7 +313,7 @@ void test_verbose_error_load_data_local_infile( } } - helper_test_load_data_local_infile(cl, proxysql, exp_err, test_for_success); + helper_test_load_data_local_infile(proxysql, exp_err, test_for_success); std::vector verbose_query_error_false { "SET mysql-verbose_query_error='false'", @@ -339,10 +343,8 @@ void test_verbose_error_load_data_local_infile( * @param test_for_success Select the operation mode of the test, 'true' for * testing for success, 'false' for failure. It's 'true' by default. */ -void test_load_data_local_infile( - const CommandLine& cl, MYSQL* proxysql, int exp_err=0, bool test_for_success=true -) { - helper_test_load_data_local_infile(cl, proxysql, exp_err, test_for_success); +void test_load_data_local_infile(MYSQL* proxysql, int exp_err=0, bool test_for_success=true) { + helper_test_load_data_local_infile(proxysql, exp_err, test_for_success); } /** @@ -359,9 +361,8 @@ void test_load_data_local_infile( * @param test_for_success Select the operation mode of the test, 'true' for * testing for success, 'false' for failure. It's 'true' by default. */ -void test_failing_load_data_local_infile( - const CommandLine& cl, MYSQL* proxysql, int exp_err=0, bool test_for_success=true -) { +void test_failing_load_data_local_infile(MYSQL* proxysql, int exp_err=0, bool test_for_success=true) { + // Supply an invalid file std::string datafile { std::string { cl.workdir } + "load_data_local_datadir/non_existing_file.txt" @@ -433,7 +434,7 @@ void test_failing_load_data_local_infile( std::vector queries_tests_info { std::make_tuple< std::string, std::string, std::string, std::string, int, - std::function + std::function >( // Query to be tested "LOAD DATA LOCAL INFILE", @@ -451,7 +452,7 @@ std::vector queries_tests_info { ), std::make_tuple< std::string, std::string, std::string, std::string, int, - std::function + std::function >( // Query to be tested "LOAD DATA LOCAL INFILE", @@ -469,7 +470,7 @@ std::vector queries_tests_info { ), std::make_tuple< std::string, std::string, std::string, std::string, int, - std::function + std::function >( // Query to be tested "LOAD DATA LOCAL INFILE", @@ -490,28 +491,37 @@ std::vector queries_tests_info { // ****************************************************************** // int main(int argc, char** argv) { - CommandLine cl; // plan as many tests as queries - plan(unsupported_queries.size() + 4 * queries_tests_info.size()); - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } + plan( + 2*unsupported_queries.size() + // connections + 2 + // connections + 2*queries_tests_info.size() + // connections + 4 + // connections + unsupported_queries.size() + 4 * queries_tests_info.size() // tests + ); // perform a different connection per query for (const auto& unsupported_query : unsupported_queries) { - MYSQL* proxysql_mysql = mysql_init(NULL); // extract the tuple elements const std::string query = std::get<0>(unsupported_query); const int exp_err_code = std::get<1>(unsupported_query); const std::string exp_err_msg = std::get<2>(unsupported_query); + MYSQL* proxysql_mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_mysql->net.compress, "Compression: (%d)", proxysql_mysql->net.compress); } int query_err = mysql_query(proxysql_mysql, query.c_str()); @@ -534,19 +544,22 @@ int main(int argc, char** argv) { // Create required connection to ProxySQL admin required to perform the // tests for conditionally enabled queries. MYSQL* proxysql_admin = mysql_init(NULL); - - if ( - !mysql_real_connect( - proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0 - ) - ) { + diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_admin, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_admin, MYSQL_OPT_COMPRESS, NULL); + if (!mysql_real_connect(proxysql_admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_admin); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_admin->net.compress, "Compression: (%d)", proxysql_admin->net.compress); } // Enable and test the queries that can be conditionally enabled for (const auto& query_test_info : queries_tests_info) { - MYSQL* proxysql_mysql = mysql_init(NULL); // extract the tuple elements const std::string query = std::get<0>(query_test_info); @@ -554,9 +567,19 @@ int main(int argc, char** argv) { int exp_err = std::get<4>(query_test_info); const auto& testing_fn = std::get<5>(query_test_info); + MYSQL* proxysql_mysql = mysql_init(NULL); + diag("Connecting: cl.username='%s' cl.use_ssl=%d cl.compression=%d", cl.username, cl.use_ssl, cl.compression); + if (cl.use_ssl) + mysql_ssl_set(proxysql_mysql, NULL, NULL, NULL, NULL, NULL); + if (cl.compression) + mysql_options(proxysql_mysql, MYSQL_OPT_COMPRESS, NULL); if (!mysql_real_connect(proxysql_mysql, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_mysql)); return EXIT_FAILURE; + } else { + const char * c = mysql_get_ssl_cipher(proxysql_mysql); + ok(cl.use_ssl == 0 ? c == NULL : c != NULL, "Cipher: %s", c == NULL ? "NULL" : c); + ok(cl.compression == proxysql_mysql->net.compress, "Compression: (%d)", proxysql_mysql->net.compress); } bool query_enabling_succeed = enable_query(proxysql_admin, query_test_info, true); @@ -566,7 +589,7 @@ int main(int argc, char** argv) { ); // Check that the query is now properly supported - testing_fn(cl, proxysql_mysql, 0, true); + testing_fn(proxysql_mysql, 0, true); bool query_disabling_succeed = enable_query(proxysql_admin, query_test_info, false); ok( @@ -575,7 +598,7 @@ int main(int argc, char** argv) { ); // Check that the query is now failing - testing_fn(cl, proxysql_mysql, exp_err, false); + testing_fn(proxysql_mysql, exp_err, false); mysql_close(proxysql_mysql); } diff --git a/test/tap/tests/test_wexecvp_syscall_failures-t.cpp b/test/tap/tests/test_wexecvp_syscall_failures-t.cpp index 68156b9472..ecc2cbf435 100644 --- a/test/tap/tests/test_wexecvp_syscall_failures-t.cpp +++ b/test/tap/tests/test_wexecvp_syscall_failures-t.cpp @@ -14,6 +14,9 @@ #include "proxysql_utils.h" #include "tap.h" #include "utils.h" +#include "command_line.h" + +CommandLine cl; using std::string; using std::vector; diff --git a/test/tap/tests_group_ssl-matrix/admin-listen_on_unix-t b/test/tap/tests_group_ssl-matrix/admin-listen_on_unix-t new file mode 120000 index 0000000000..3e1f080f00 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/admin-listen_on_unix-t @@ -0,0 +1 @@ +../tests/admin-listen_on_unix-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/admin_show_create_table-t b/test/tap/tests_group_ssl-matrix/admin_show_create_table-t new file mode 120000 index 0000000000..b5c8bab84c --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/admin_show_create_table-t @@ -0,0 +1 @@ +../tests/admin_show_create_table-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/admin_show_fields_from-t b/test/tap/tests_group_ssl-matrix/admin_show_fields_from-t new file mode 120000 index 0000000000..d0db1f19e9 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/admin_show_fields_from-t @@ -0,0 +1 @@ +../tests/admin_show_fields_from-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/admin_show_table_status-t b/test/tap/tests_group_ssl-matrix/admin_show_table_status-t new file mode 120000 index 0000000000..a59e3a4455 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/admin_show_table_status-t @@ -0,0 +1 @@ +../tests/admin_show_table_status-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/admin_various_commands-t b/test/tap/tests_group_ssl-matrix/admin_various_commands-t new file mode 120000 index 0000000000..24738836eb --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/admin_various_commands-t @@ -0,0 +1 @@ +../tests/admin_various_commands-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/admin_various_commands2-t b/test/tap/tests_group_ssl-matrix/admin_various_commands2-t new file mode 120000 index 0000000000..768b93b4b4 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/admin_various_commands2-t @@ -0,0 +1 @@ +../tests/admin_various_commands2-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/admin_various_commands3-t b/test/tap/tests_group_ssl-matrix/admin_various_commands3-t new file mode 120000 index 0000000000..f15f5900c6 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/admin_various_commands3-t @@ -0,0 +1 @@ +../tests/admin_various_commands3-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/aws_ssl_certs b/test/tap/tests_group_ssl-matrix/aws_ssl_certs new file mode 120000 index 0000000000..2b8931c9fd --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/aws_ssl_certs @@ -0,0 +1 @@ +../tests/aws_ssl_certs \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/charset_unsigned_int-t b/test/tap/tests_group_ssl-matrix/charset_unsigned_int-t new file mode 120000 index 0000000000..e214022639 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/charset_unsigned_int-t @@ -0,0 +1 @@ +../tests/charset_unsigned_int-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/client_host_err b/test/tap/tests_group_ssl-matrix/client_host_err new file mode 120000 index 0000000000..be02947454 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/client_host_err @@ -0,0 +1 @@ +../tests/client_host_err \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/firewall_commands1-t b/test/tap/tests_group_ssl-matrix/firewall_commands1-t new file mode 120000 index 0000000000..f2b829dc54 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/firewall_commands1-t @@ -0,0 +1 @@ +../tests/firewall_commands1-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/generate_set_session_csv b/test/tap/tests_group_ssl-matrix/generate_set_session_csv new file mode 120000 index 0000000000..3bafe424d1 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/generate_set_session_csv @@ -0,0 +1 @@ +../tests/generate_set_session_csv \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/kill_connection-t b/test/tap/tests_group_ssl-matrix/kill_connection-t new file mode 120000 index 0000000000..50c7908557 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/kill_connection-t @@ -0,0 +1 @@ +../tests/kill_connection-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/kill_connection2-t b/test/tap/tests_group_ssl-matrix/kill_connection2-t new file mode 120000 index 0000000000..49d8bd4131 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/kill_connection2-t @@ -0,0 +1 @@ +../tests/kill_connection2-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/kill_connection3-t b/test/tap/tests_group_ssl-matrix/kill_connection3-t new file mode 120000 index 0000000000..310f3eb36c --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/kill_connection3-t @@ -0,0 +1 @@ +../tests/kill_connection3-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/load_data_local_datadir b/test/tap/tests_group_ssl-matrix/load_data_local_datadir new file mode 120000 index 0000000000..86cb178179 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/load_data_local_datadir @@ -0,0 +1 @@ +../tests/load_data_local_datadir \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/max_connections_ff-t b/test/tap/tests_group_ssl-matrix/max_connections_ff-t new file mode 120000 index 0000000000..986b927dd0 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/max_connections_ff-t @@ -0,0 +1 @@ +../tests/max_connections_ff-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/multiple_prepared_statements-t b/test/tap/tests_group_ssl-matrix/multiple_prepared_statements-t new file mode 120000 index 0000000000..3c82605b7e --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/multiple_prepared_statements-t @@ -0,0 +1 @@ +../tests/multiple_prepared_statements-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/mysql-fast_forward-t b/test/tap/tests_group_ssl-matrix/mysql-fast_forward-t new file mode 120000 index 0000000000..43ba9f0187 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/mysql-fast_forward-t @@ -0,0 +1 @@ +../tests/mysql-fast_forward-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/mysql-init_connect-1-t b/test/tap/tests_group_ssl-matrix/mysql-init_connect-1-t new file mode 120000 index 0000000000..bedb7a9680 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/mysql-init_connect-1-t @@ -0,0 +1 @@ +../tests/mysql-init_connect-1-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/mysql-init_connect-2-t b/test/tap/tests_group_ssl-matrix/mysql-init_connect-2-t new file mode 120000 index 0000000000..275d35381b --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/mysql-init_connect-2-t @@ -0,0 +1 @@ +../tests/mysql-init_connect-2-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/mysql-last_insert_id-t b/test/tap/tests_group_ssl-matrix/mysql-last_insert_id-t new file mode 120000 index 0000000000..0dc79e6c64 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/mysql-last_insert_id-t @@ -0,0 +1 @@ +../tests/mysql-last_insert_id-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/mysql-mirror1-t b/test/tap/tests_group_ssl-matrix/mysql-mirror1-t new file mode 120000 index 0000000000..b40c1ce5ad --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/mysql-mirror1-t @@ -0,0 +1 @@ +../tests/mysql-mirror1-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/mysql-set_transaction-t b/test/tap/tests_group_ssl-matrix/mysql-set_transaction-t new file mode 120000 index 0000000000..cac03487b5 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/mysql-set_transaction-t @@ -0,0 +1 @@ +../tests/mysql-set_transaction-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/mysql-sql_log_bin-error-t b/test/tap/tests_group_ssl-matrix/mysql-sql_log_bin-error-t new file mode 120000 index 0000000000..9e441a3d2d --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/mysql-sql_log_bin-error-t @@ -0,0 +1 @@ +../tests/mysql-sql_log_bin-error-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/mysql-test_ssl_CA-t b/test/tap/tests_group_ssl-matrix/mysql-test_ssl_CA-t new file mode 120000 index 0000000000..91d444995e --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/mysql-test_ssl_CA-t @@ -0,0 +1 @@ +../tests/mysql-test_ssl_CA-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/mysql_hostgroup_attributes-servers_defaults-t b/test/tap/tests_group_ssl-matrix/mysql_hostgroup_attributes-servers_defaults-t new file mode 120000 index 0000000000..b3c6800f37 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/mysql_hostgroup_attributes-servers_defaults-t @@ -0,0 +1 @@ +../tests/mysql_hostgroup_attributes-servers_defaults-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/mysql_stmt_send_long_data-t b/test/tap/tests_group_ssl-matrix/mysql_stmt_send_long_data-t new file mode 120000 index 0000000000..0c45b8c586 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/mysql_stmt_send_long_data-t @@ -0,0 +1 @@ +../tests/mysql_stmt_send_long_data-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/mysql_stmt_send_long_data_large-t b/test/tap/tests_group_ssl-matrix/mysql_stmt_send_long_data_large-t new file mode 120000 index 0000000000..19d8bb0be0 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/mysql_stmt_send_long_data_large-t @@ -0,0 +1 @@ +../tests/mysql_stmt_send_long_data_large-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/prepare_statement_err3024-t b/test/tap/tests_group_ssl-matrix/prepare_statement_err3024-t new file mode 120000 index 0000000000..50259dee69 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/prepare_statement_err3024-t @@ -0,0 +1 @@ +../tests/prepare_statement_err3024-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/reg_test_3223_scripts b/test/tap/tests_group_ssl-matrix/reg_test_3223_scripts new file mode 120000 index 0000000000..45041975a5 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/reg_test_3223_scripts @@ -0,0 +1 @@ +../tests/reg_test_3223_scripts \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/reg_test_3504-change_user_libmariadb_helper b/test/tap/tests_group_ssl-matrix/reg_test_3504-change_user_libmariadb_helper new file mode 120000 index 0000000000..1ebe840c60 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/reg_test_3504-change_user_libmariadb_helper @@ -0,0 +1 @@ +../tests/reg_test_3504-change_user_libmariadb_helper \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/reg_test_3504-change_user_libmysql_helper b/test/tap/tests_group_ssl-matrix/reg_test_3504-change_user_libmysql_helper new file mode 120000 index 0000000000..a12716f628 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/reg_test_3504-change_user_libmysql_helper @@ -0,0 +1 @@ +../tests/reg_test_3504-change_user_libmysql_helper \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/reg_test_3838_scripts b/test/tap/tests_group_ssl-matrix/reg_test_3838_scripts new file mode 120000 index 0000000000..49799fc217 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/reg_test_3838_scripts @@ -0,0 +1 @@ +../tests/reg_test_3838_scripts \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/reg_test_3847_node_datadir b/test/tap/tests_group_ssl-matrix/reg_test_3847_node_datadir new file mode 120000 index 0000000000..4ab1fcf39c --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/reg_test_3847_node_datadir @@ -0,0 +1 @@ +../tests/reg_test_3847_node_datadir \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/savepoint-3749-t b/test/tap/tests_group_ssl-matrix/savepoint-3749-t new file mode 120000 index 0000000000..06afc62323 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/savepoint-3749-t @@ -0,0 +1 @@ +../tests/savepoint-3749-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/savepoint-948-t b/test/tap/tests_group_ssl-matrix/savepoint-948-t new file mode 120000 index 0000000000..dbaa7e4860 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/savepoint-948-t @@ -0,0 +1 @@ +../tests/savepoint-948-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/set_character_set-t b/test/tap/tests_group_ssl-matrix/set_character_set-t new file mode 120000 index 0000000000..80960dd6fc --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/set_character_set-t @@ -0,0 +1 @@ +../tests/set_character_set-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/set_testing-240-t b/test/tap/tests_group_ssl-matrix/set_testing-240-t new file mode 120000 index 0000000000..38fc862ed6 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/set_testing-240-t @@ -0,0 +1 @@ +../tests/set_testing-240-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/set_testing-multi-t b/test/tap/tests_group_ssl-matrix/set_testing-multi-t new file mode 120000 index 0000000000..c69bc16cd8 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/set_testing-multi-t @@ -0,0 +1 @@ +../tests/set_testing-multi-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/set_testing-t b/test/tap/tests_group_ssl-matrix/set_testing-t new file mode 120000 index 0000000000..0fe913b015 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/set_testing-t @@ -0,0 +1 @@ +../tests/set_testing-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/set_testing-t.csv b/test/tap/tests_group_ssl-matrix/set_testing-t.csv new file mode 120000 index 0000000000..130dac69ca --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/set_testing-t.csv @@ -0,0 +1 @@ +../tests/set_testing-t.csv \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/setparser_test b/test/tap/tests_group_ssl-matrix/setparser_test new file mode 120000 index 0000000000..e02b918537 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/setparser_test @@ -0,0 +1 @@ +../tests/setparser_test \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/setparser_test2 b/test/tap/tests_group_ssl-matrix/setparser_test2 new file mode 120000 index 0000000000..87e7a997ed --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/setparser_test2 @@ -0,0 +1 @@ +../tests/setparser_test2 \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/setparser_test3 b/test/tap/tests_group_ssl-matrix/setparser_test3 new file mode 120000 index 0000000000..59701a77c0 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/setparser_test3 @@ -0,0 +1 @@ +../tests/setparser_test3 \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/sqlite_autocommit-t b/test/tap/tests_group_ssl-matrix/sqlite_autocommit-t new file mode 120000 index 0000000000..4f908d6eb3 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/sqlite_autocommit-t @@ -0,0 +1 @@ +../tests/sqlite_autocommit-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_admin_stats-t b/test/tap/tests_group_ssl-matrix/test_admin_stats-t new file mode 120000 index 0000000000..9e61dfa6e4 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_admin_stats-t @@ -0,0 +1 @@ +../tests/test_admin_stats-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_auto_increment_delay_multiplex-t b/test/tap/tests_group_ssl-matrix/test_auto_increment_delay_multiplex-t new file mode 120000 index 0000000000..0ec2580574 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_auto_increment_delay_multiplex-t @@ -0,0 +1 @@ +../tests/test_auto_increment_delay_multiplex-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_backend_conn_ping-t b/test/tap/tests_group_ssl-matrix/test_backend_conn_ping-t new file mode 120000 index 0000000000..582e0566d8 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_backend_conn_ping-t @@ -0,0 +1 @@ +../tests/test_backend_conn_ping-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_binlog_fast_forward-t b/test/tap/tests_group_ssl-matrix/test_binlog_fast_forward-t new file mode 120000 index 0000000000..c3f6ea4fc5 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_binlog_fast_forward-t @@ -0,0 +1 @@ +../tests/test_binlog_fast_forward-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_binlog_reader-t b/test/tap/tests_group_ssl-matrix/test_binlog_reader-t new file mode 120000 index 0000000000..2f3e7751b7 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_binlog_reader-t @@ -0,0 +1 @@ +../tests/test_binlog_reader-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_binlog_reader_uses_previous_hostgroup-t b/test/tap/tests_group_ssl-matrix/test_binlog_reader_uses_previous_hostgroup-t new file mode 120000 index 0000000000..6582658419 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_binlog_reader_uses_previous_hostgroup-t @@ -0,0 +1 @@ +../tests/test_binlog_reader_uses_previous_hostgroup-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_clickhouse_server-t b/test/tap/tests_group_ssl-matrix/test_clickhouse_server-t new file mode 120000 index 0000000000..077ebb2cd1 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_clickhouse_server-t @@ -0,0 +1 @@ +../tests/test_clickhouse_server-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_client_limit_error-t b/test/tap/tests_group_ssl-matrix/test_client_limit_error-t new file mode 120000 index 0000000000..b3d7a2ade7 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_client_limit_error-t @@ -0,0 +1 @@ +../tests/test_client_limit_error-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_cluster1-t b/test/tap/tests_group_ssl-matrix/test_cluster1-t new file mode 120000 index 0000000000..b1d3e68a27 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_cluster1-t @@ -0,0 +1 @@ +../tests/test_cluster1-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_cluster_sync-t b/test/tap/tests_group_ssl-matrix/test_cluster_sync-t new file mode 120000 index 0000000000..155a4ed647 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_cluster_sync-t @@ -0,0 +1 @@ +../tests/test_cluster_sync-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_cluster_sync_config b/test/tap/tests_group_ssl-matrix/test_cluster_sync_config new file mode 120000 index 0000000000..a01b0b59fd --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_cluster_sync_config @@ -0,0 +1 @@ +../tests/test_cluster_sync_config \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_com_reset_connection_com_change_user-t b/test/tap/tests_group_ssl-matrix/test_com_reset_connection_com_change_user-t new file mode 120000 index 0000000000..f6509d8059 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_com_reset_connection_com_change_user-t @@ -0,0 +1 @@ +../tests/test_com_reset_connection_com_change_user-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_connection_annotation-t b/test/tap/tests_group_ssl-matrix/test_connection_annotation-t new file mode 120000 index 0000000000..59f1073b1b --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_connection_annotation-t @@ -0,0 +1 @@ +../tests/test_connection_annotation-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_csharp_connector_support-t b/test/tap/tests_group_ssl-matrix/test_csharp_connector_support-t new file mode 120000 index 0000000000..d07439d654 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_csharp_connector_support-t @@ -0,0 +1 @@ +../tests/test_csharp_connector_support-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_debug_filters-t b/test/tap/tests_group_ssl-matrix/test_debug_filters-t new file mode 120000 index 0000000000..9c0595ec36 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_debug_filters-t @@ -0,0 +1 @@ +../tests/test_debug_filters-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_default_conn_collation-t b/test/tap/tests_group_ssl-matrix/test_default_conn_collation-t new file mode 120000 index 0000000000..890eb86a75 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_default_conn_collation-t @@ -0,0 +1 @@ +../tests/test_default_conn_collation-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_default_value_transaction_isolation-t b/test/tap/tests_group_ssl-matrix/test_default_value_transaction_isolation-t new file mode 120000 index 0000000000..a9d1c27f90 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_default_value_transaction_isolation-t @@ -0,0 +1 @@ +../tests/test_default_value_transaction_isolation-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_default_value_transaction_isolation_attr-t b/test/tap/tests_group_ssl-matrix/test_default_value_transaction_isolation_attr-t new file mode 120000 index 0000000000..5a53a98234 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_default_value_transaction_isolation_attr-t @@ -0,0 +1 @@ +../tests/test_default_value_transaction_isolation_attr-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_digest_umap_aux-t b/test/tap/tests_group_ssl-matrix/test_digest_umap_aux-t new file mode 120000 index 0000000000..15ad7b5c0d --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_digest_umap_aux-t @@ -0,0 +1 @@ +../tests/test_digest_umap_aux-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_dns_cache-t b/test/tap/tests_group_ssl-matrix/test_dns_cache-t new file mode 120000 index 0000000000..37ec487f18 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_dns_cache-t @@ -0,0 +1 @@ +../tests/test_dns_cache-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_empty_query-t b/test/tap/tests_group_ssl-matrix/test_empty_query-t new file mode 120000 index 0000000000..edd46e92af --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_empty_query-t @@ -0,0 +1 @@ +../tests/test_empty_query-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_enforce_autocommit_on_reads-t b/test/tap/tests_group_ssl-matrix/test_enforce_autocommit_on_reads-t new file mode 120000 index 0000000000..7d2476e09d --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_enforce_autocommit_on_reads-t @@ -0,0 +1 @@ +../tests/test_enforce_autocommit_on_reads-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_filtered_set_statements-t b/test/tap/tests_group_ssl-matrix/test_filtered_set_statements-t new file mode 120000 index 0000000000..db16535fbb --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_filtered_set_statements-t @@ -0,0 +1 @@ +../tests/test_filtered_set_statements-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_firewall-t b/test/tap/tests_group_ssl-matrix/test_firewall-t new file mode 120000 index 0000000000..7abbe111f9 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_firewall-t @@ -0,0 +1 @@ +../tests/test_firewall-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_flagOUT_weight-t b/test/tap/tests_group_ssl-matrix/test_flagOUT_weight-t new file mode 120000 index 0000000000..41df9bd8a6 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_flagOUT_weight-t @@ -0,0 +1 @@ +../tests/test_flagOUT_weight-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_greeting_capabilities-t b/test/tap/tests_group_ssl-matrix/test_greeting_capabilities-t new file mode 120000 index 0000000000..9017c497cb --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_greeting_capabilities-t @@ -0,0 +1 @@ +../tests/test_greeting_capabilities-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_gtid_forwarding-t b/test/tap/tests_group_ssl-matrix/test_gtid_forwarding-t new file mode 120000 index 0000000000..a855bda536 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_gtid_forwarding-t @@ -0,0 +1 @@ +../tests/test_gtid_forwarding-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_keep_multiplexing_variables-t b/test/tap/tests_group_ssl-matrix/test_keep_multiplexing_variables-t new file mode 120000 index 0000000000..eb0705e45c --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_keep_multiplexing_variables-t @@ -0,0 +1 @@ +../tests/test_keep_multiplexing_variables-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_max_transaction_time-t b/test/tap/tests_group_ssl-matrix/test_max_transaction_time-t new file mode 120000 index 0000000000..aec135cdf5 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_max_transaction_time-t @@ -0,0 +1 @@ +../tests/test_max_transaction_time-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_mysql_connect_retries-t b/test/tap/tests_group_ssl-matrix/test_mysql_connect_retries-t new file mode 120000 index 0000000000..c784b2640f --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_mysql_connect_retries-t @@ -0,0 +1 @@ +../tests/test_mysql_connect_retries-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_mysql_connect_retries_delay-t b/test/tap/tests_group_ssl-matrix/test_mysql_connect_retries_delay-t new file mode 120000 index 0000000000..26ebd9a186 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_mysql_connect_retries_delay-t @@ -0,0 +1 @@ +../tests/test_mysql_connect_retries_delay-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_mysql_hostgroup_attributes-1-t b/test/tap/tests_group_ssl-matrix/test_mysql_hostgroup_attributes-1-t new file mode 120000 index 0000000000..cc0547989f --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_mysql_hostgroup_attributes-1-t @@ -0,0 +1 @@ +../tests/test_mysql_hostgroup_attributes-1-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_mysql_query_rules_fast_routing-t b/test/tap/tests_group_ssl-matrix/test_mysql_query_rules_fast_routing-t new file mode 120000 index 0000000000..872943c267 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_mysql_query_rules_fast_routing-t @@ -0,0 +1 @@ +../tests/test_mysql_query_rules_fast_routing-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_mysqlsh-t b/test/tap/tests_group_ssl-matrix/test_mysqlsh-t new file mode 120000 index 0000000000..59ee01b562 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_mysqlsh-t @@ -0,0 +1 @@ +../tests/test_mysqlsh-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_prometheus_metrics-t b/test/tap/tests_group_ssl-matrix/test_prometheus_metrics-t new file mode 120000 index 0000000000..64f8aaae19 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_prometheus_metrics-t @@ -0,0 +1 @@ +../tests/test_prometheus_metrics-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_ps_async-t b/test/tap/tests_group_ssl-matrix/test_ps_async-t new file mode 120000 index 0000000000..9a0ad6e3d5 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_ps_async-t @@ -0,0 +1 @@ +../tests/test_ps_async-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_ps_hg_routing-t b/test/tap/tests_group_ssl-matrix/test_ps_hg_routing-t new file mode 120000 index 0000000000..374dd37faf --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_ps_hg_routing-t @@ -0,0 +1 @@ +../tests/test_ps_hg_routing-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_ps_large_result-t b/test/tap/tests_group_ssl-matrix/test_ps_large_result-t new file mode 120000 index 0000000000..e02163a9e1 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_ps_large_result-t @@ -0,0 +1 @@ +../tests/test_ps_large_result-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_ps_no_store-t b/test/tap/tests_group_ssl-matrix/test_ps_no_store-t new file mode 120000 index 0000000000..77f1303f0a --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_ps_no_store-t @@ -0,0 +1 @@ +../tests/test_ps_no_store-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_query_cache_soft_ttl_pct-t b/test/tap/tests_group_ssl-matrix/test_query_cache_soft_ttl_pct-t new file mode 120000 index 0000000000..98a1d3f084 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_query_cache_soft_ttl_pct-t @@ -0,0 +1 @@ +../tests/test_query_cache_soft_ttl_pct-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_query_rules_fast_routing_algorithm-t b/test/tap/tests_group_ssl-matrix/test_query_rules_fast_routing_algorithm-t new file mode 120000 index 0000000000..f36e16c494 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_query_rules_fast_routing_algorithm-t @@ -0,0 +1 @@ +../tests/test_query_rules_fast_routing_algorithm-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_query_rules_routing-t b/test/tap/tests_group_ssl-matrix/test_query_rules_routing-t new file mode 120000 index 0000000000..fd9ea02b3f --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_query_rules_routing-t @@ -0,0 +1 @@ +../tests/test_query_rules_routing-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_query_timeout-t b/test/tap/tests_group_ssl-matrix/test_query_timeout-t new file mode 120000 index 0000000000..476d58d86d --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_query_timeout-t @@ -0,0 +1 @@ +../tests/test_query_timeout-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_read_only_actions_offline_hard_servers-t b/test/tap/tests_group_ssl-matrix/test_read_only_actions_offline_hard_servers-t new file mode 120000 index 0000000000..2fb6601223 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_read_only_actions_offline_hard_servers-t @@ -0,0 +1 @@ +../tests/test_read_only_actions_offline_hard_servers-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_rw_binary_data-t b/test/tap/tests_group_ssl-matrix/test_rw_binary_data-t new file mode 120000 index 0000000000..8fab3abf12 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_rw_binary_data-t @@ -0,0 +1 @@ +../tests/test_rw_binary_data-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_server_sess_status-t b/test/tap/tests_group_ssl-matrix/test_server_sess_status-t new file mode 120000 index 0000000000..a2fa5aa819 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_server_sess_status-t @@ -0,0 +1 @@ +../tests/test_server_sess_status-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_session_status_flags-t b/test/tap/tests_group_ssl-matrix/test_session_status_flags-t new file mode 120000 index 0000000000..4c3991f0ee --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_session_status_flags-t @@ -0,0 +1 @@ +../tests/test_session_status_flags-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_set_character_results-t b/test/tap/tests_group_ssl-matrix/test_set_character_results-t new file mode 120000 index 0000000000..08f5401be7 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_set_character_results-t @@ -0,0 +1 @@ +../tests/test_set_character_results-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_set_collation-t b/test/tap/tests_group_ssl-matrix/test_set_collation-t new file mode 120000 index 0000000000..a468da8a32 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_set_collation-t @@ -0,0 +1 @@ +../tests/test_set_collation-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_simple_embedded_HTTP_server-t b/test/tap/tests_group_ssl-matrix/test_simple_embedded_HTTP_server-t new file mode 120000 index 0000000000..ea0b9de01a --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_simple_embedded_HTTP_server-t @@ -0,0 +1 @@ +../tests/test_simple_embedded_HTTP_server-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_sqlite3_server-t b/test/tap/tests_group_ssl-matrix/test_sqlite3_server-t new file mode 120000 index 0000000000..c5f6c3d1bd --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_sqlite3_server-t @@ -0,0 +1 @@ +../tests/test_sqlite3_server-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_sqlite3_server_and_fast_routing-t b/test/tap/tests_group_ssl-matrix/test_sqlite3_server_and_fast_routing-t new file mode 120000 index 0000000000..038590ba35 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_sqlite3_server_and_fast_routing-t @@ -0,0 +1 @@ +../tests/test_sqlite3_server_and_fast_routing-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_stats_proxysql_message_metrics-t b/test/tap/tests_group_ssl-matrix/test_stats_proxysql_message_metrics-t new file mode 120000 index 0000000000..2007940dab --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_stats_proxysql_message_metrics-t @@ -0,0 +1 @@ +../tests/test_stats_proxysql_message_metrics-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_throttle_max_bytes_per_second_to_client-t b/test/tap/tests_group_ssl-matrix/test_throttle_max_bytes_per_second_to_client-t new file mode 120000 index 0000000000..4cecf0a5d9 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_throttle_max_bytes_per_second_to_client-t @@ -0,0 +1 @@ +../tests/test_throttle_max_bytes_per_second_to_client-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_unshun_algorithm-t b/test/tap/tests_group_ssl-matrix/test_unshun_algorithm-t new file mode 120000 index 0000000000..9d987d99d5 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_unshun_algorithm-t @@ -0,0 +1 @@ +../tests/test_unshun_algorithm-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/test_unsupported_queries-t b/test/tap/tests_group_ssl-matrix/test_unsupported_queries-t new file mode 120000 index 0000000000..cf49905db3 --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/test_unsupported_queries-t @@ -0,0 +1 @@ +../tests/test_unsupported_queries-t \ No newline at end of file diff --git a/test/tap/tests_group_ssl-matrix/tokenizer_payloads b/test/tap/tests_group_ssl-matrix/tokenizer_payloads new file mode 120000 index 0000000000..39dd22a1cc --- /dev/null +++ b/test/tap/tests_group_ssl-matrix/tokenizer_payloads @@ -0,0 +1 @@ +../tests/tokenizer_payloads \ No newline at end of file diff --git a/test/tap/tests_with_deps/deprecate_eof_support/deprecate_eof_cache-t.cpp b/test/tap/tests_with_deps/deprecate_eof_support/deprecate_eof_cache-t.cpp index e46e2d3f94..a5a9f80c49 100644 --- a/test/tap/tests_with_deps/deprecate_eof_support/deprecate_eof_cache-t.cpp +++ b/test/tap/tests_with_deps/deprecate_eof_support/deprecate_eof_cache-t.cpp @@ -23,6 +23,8 @@ using std::vector; using std::string; using std::pair; +CommandLine cl; + /** * @brief Creates the tables required for the test. * @param mysql_server The initialized connection to the server. @@ -54,7 +56,6 @@ std::vector queries { }; int main(int argc, char** argv) { - CommandLine cl; uint32_t c_operations = 50; to_opts_t opts { 10000*1000, 100*1000, 500*1000, 2000*1000 }; @@ -64,11 +65,6 @@ int main(int argc, char** argv) { p += c_operations*12; // 12 tests each time plan(p); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } - MYSQL* proxy_mysql = mysql_init(NULL); MYSQL* proxy_admin = mysql_init(NULL); diff --git a/test/tap/tests_with_deps/deprecate_eof_support/eof_cache_mixed_flags-t.cpp b/test/tap/tests_with_deps/deprecate_eof_support/eof_cache_mixed_flags-t.cpp index f7f95a694d..484b806cee 100644 --- a/test/tap/tests_with_deps/deprecate_eof_support/eof_cache_mixed_flags-t.cpp +++ b/test/tap/tests_with_deps/deprecate_eof_support/eof_cache_mixed_flags-t.cpp @@ -18,13 +18,9 @@ #include "command_line.h" #include "utils.h" -int main(int argc, char** argv) { - CommandLine cl; +CommandLine cl; - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } +int main(int argc, char** argv) { MYSQL* proxy_admin = mysql_init(NULL); if (!proxy_admin) { diff --git a/test/tap/tests_with_deps/deprecate_eof_support/eof_conn_options_check-t.cpp b/test/tap/tests_with_deps/deprecate_eof_support/eof_conn_options_check-t.cpp index ea64d518c8..7d099f27d8 100644 --- a/test/tap/tests_with_deps/deprecate_eof_support/eof_conn_options_check-t.cpp +++ b/test/tap/tests_with_deps/deprecate_eof_support/eof_conn_options_check-t.cpp @@ -27,6 +27,8 @@ using nlohmann::json; +CommandLine cl; + /** * @brief Extracts all the columns from a `MYSQL_RES` into a `nlohmann::json`. * @@ -98,12 +100,6 @@ int queryInternalEOFStatus(MYSQL *mysql, std::pair& c_s_flags) { } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } std::vector> states { {0, 0}, diff --git a/test/tap/tests_with_deps/deprecate_eof_support/eof_fast_forward-t.cpp b/test/tap/tests_with_deps/deprecate_eof_support/eof_fast_forward-t.cpp index e6260d0a7d..089a529c34 100644 --- a/test/tap/tests_with_deps/deprecate_eof_support/eof_fast_forward-t.cpp +++ b/test/tap/tests_with_deps/deprecate_eof_support/eof_fast_forward-t.cpp @@ -31,6 +31,8 @@ using std::vector; using std::string; using std::pair; +CommandLine cl; + std::vector queries { "SELECT * FROM test.ok_packet_mariadb_test WHERE id=%d", "INSERT INTO test.ok_packet_mariadb_test (c, pad) VALUES ('%s', '%s')", @@ -183,12 +185,6 @@ int perform_workload_on_connection(MYSQL* proxy, MYSQL* admin) { } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } MYSQL* proxy = mysql_init(NULL); MYSQL* admin = mysql_init(NULL); diff --git a/test/tap/tests_with_deps/deprecate_eof_support/eof_mixed_flags_queries-t.cpp b/test/tap/tests_with_deps/deprecate_eof_support/eof_mixed_flags_queries-t.cpp index 2222e6a19c..71fe79f5c3 100644 --- a/test/tap/tests_with_deps/deprecate_eof_support/eof_mixed_flags_queries-t.cpp +++ b/test/tap/tests_with_deps/deprecate_eof_support/eof_mixed_flags_queries-t.cpp @@ -28,6 +28,8 @@ using std::string; using std::vector; +CommandLine cl; + vector> get_all_bin_vec(size_t tg_size) { vector> all_bin_strs {}; vector bin_vec(tg_size, 0); @@ -63,12 +65,6 @@ vector gen_all_configs(const string& ff_user) { } int main(int argc, char** argv) { - CommandLine cl; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } const string FF_USER { cl.username }; @@ -82,7 +78,7 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - const auto execute_target_test = [&cl, &admin, &FF_USER] (const string test_file, bool clear_conns) -> int { + const auto execute_target_test = [&admin, &FF_USER] (const string test_file, bool clear_conns) -> int { vector all_test_confs { gen_all_configs(FF_USER) }; for (const conn_cnf_t& cnf : all_test_confs) { diff --git a/test/tap/tests_with_deps/deprecate_eof_support/eof_packet_mixed_queries-t.cpp b/test/tap/tests_with_deps/deprecate_eof_support/eof_packet_mixed_queries-t.cpp index d55fa7f2f6..9fbd5243e2 100644 --- a/test/tap/tests_with_deps/deprecate_eof_support/eof_packet_mixed_queries-t.cpp +++ b/test/tap/tests_with_deps/deprecate_eof_support/eof_packet_mixed_queries-t.cpp @@ -31,6 +31,8 @@ using std::pair; using std::string; using std::vector; +CommandLine cl; + std::vector queries { "SELECT * FROM test.ok_packet_mariadb_test WHERE id=%d", "INSERT INTO test.ok_packet_mariadb_test (c, pad) VALUES ('%s', '%s')", @@ -501,18 +503,12 @@ int test_target_queries(MYSQL* proxy) { const uint32_t HG_ID = 0; int main(int argc, char** argv) { - CommandLine cl; plan( 3 + // TEXT protocol checks 2 // Binary protocol checks ); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - MYSQL* admin = mysql_init(NULL); if (!admin) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(admin)); diff --git a/test/tap/tests_with_deps/deprecate_eof_support/fwd_eof_query.cpp b/test/tap/tests_with_deps/deprecate_eof_support/fwd_eof_query.cpp index 5eb35f4c61..1b2299dcec 100644 --- a/test/tap/tests_with_deps/deprecate_eof_support/fwd_eof_query.cpp +++ b/test/tap/tests_with_deps/deprecate_eof_support/fwd_eof_query.cpp @@ -22,6 +22,8 @@ using namespace nlohmann; using std::string; using std::vector; +CommandLine cl; + int check_arguments(int argc, char** argv) { int err_code = 0; @@ -74,14 +76,8 @@ void MySQL_result_to_JSON(MYSQL_RES* resultset, json& j_res) { } int main(int argc, char** argv) { - CommandLine cl; - int res_code { 0 }; - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; - } + int res_code { 0 }; int check_res = check_arguments(argc, argv); if (check_res) { return -1; }