From f06c1098089a81d140e23865a31e6d7eeaf612f2 Mon Sep 17 00:00:00 2001 From: Miro Stauder Date: Fri, 20 Oct 2023 17:07:00 +0000 Subject: [PATCH] use 'CommandLine cl' as a TAP test global --- test/tap/tap/utils.cpp | 4 +- test/tap/tap/utils.h | 2 +- test/tap/tests/admin-listen_on_unix-t.cpp | 3 +- test/tap/tests/admin_show_create_table-t.cpp | 3 +- test/tap/tests/admin_show_fields_from-t.cpp | 3 +- test/tap/tests/admin_show_table_status-t.cpp | 3 +- test/tap/tests/admin_various_commands-t.cpp | 3 +- test/tap/tests/admin_various_commands2-t.cpp | 3 +- test/tap/tests/admin_various_commands3-t.cpp | 4 +- test/tap/tests/basic-t.cpp | 25 +- test/tap/tests/charset_unsigned_int-t.cpp | 3 +- test/tap/tests/envvars-t.cpp | 8 +- test/tap/tests/firewall_commands1-t.cpp | 3 +- test/tap/tests/kill_connection-t.cpp | 2 +- test/tap/tests/kill_connection2-t.cpp | 8 +- test/tap/tests/kill_connection3-t.cpp | 13 +- test/tap/tests/max_connections_ff-t.cpp | 21 +- .../tests/multiple_prepared_statements-t.cpp | 3 +- test/tap/tests/mysql-fast_forward-t.cpp | 8 +- test/tap/tests/mysql-init_connect-1-t.cpp | 3 +- test/tap/tests/mysql-init_connect-2-t.cpp | 3 +- test/tap/tests/mysql-last_insert_id-t.cpp | 14 +- test/tap/tests/mysql-mirror1-t.cpp | 8 +- test/tap/tests/mysql-set_transaction-t.cpp | 3 +- test/tap/tests/mysql-sql_log_bin-error-t.cpp | 3 +- test/tap/tests/mysql-test_ssl_CA-t.cpp | 4 +- ...ostgroup_attributes-servers_defaults-t.cpp | 5 +- .../tap/tests/mysql_stmt_send_long_data-t.cpp | 3 +- .../mysql_stmt_send_long_data_large-t.cpp | 3 +- .../tap/tests/prepare_statement_err3024-t.cpp | 3 +- .../reg_test_1493-mixed_compression-t.cpp | 8 +- ...4-mariadb_read_stmt_execute_response-t.cpp | 8 +- .../tests/reg_test_1574-stmt_metadata-t.cpp | 8 +- .../tap/tests/reg_test_2793-compression-t.cpp | 8 +- .../reg_test_3184-set_wait_timeout-t.cpp | 8 +- .../reg_test_3223-restapi_return_codes-t.cpp | 8 +- .../tests/reg_test_3247-mycli_support-t.cpp | 8 +- test/tap/tests/reg_test_3273_ssl_con-t.cpp | 12 +- ..._3317-lock_hostgroup_special_queries-t.cpp | 8 +- ..._3327-process_query_set_status_flags-t.cpp | 8 +- .../reg_test_3427-stmt_first_comment1-t.cpp | 9 +- .../tests/reg_test_3434-text_stmt_mix-t.cpp | 25 +- .../reg_test_3493-USE_with_comment-t.cpp | 8 +- .../tap/tests/reg_test_3504-change_user-t.cpp | 8 +- .../reg_test_3504-change_user_helper.cpp | 3 + .../reg_test_3546-stmt_empty_params-t.cpp | 9 +- .../reg_test_3549-autocommit_tracking-t.cpp | 8 +- .../tests/reg_test_3585-stmt_metadata-t.cpp | 8 +- .../tests/reg_test_3591-restapi_num_fds-t.cpp | 7 +- .../tests/reg_test_3603-stmt_metadata-t.cpp | 8 +- .../tests/reg_test_3606-mysql_warnings-t.cpp | 8 +- ...5-sqlite3_session_client_error_limit-t.cpp | 8 +- .../reg_test_3690-admin_large_pkts-t.cpp | 8 +- .../tap/tests/reg_test_3765_ssl_pollout-t.cpp | 20 +- .../tests/reg_test_3838-restapi_eintr-t.cpp | 8 +- test/tap/tests/reg_test_3847_admin_lock-t.cpp | 12 +- ...ast_forward_malformed_packet-mysqlsh-t.cpp | 8 +- ...t_3992_fast_forward_malformed_packet-t.cpp | 12 +- ...eg_test_4001-restapi_scripts_num_fds-t.cpp | 8 +- test/tap/tests/reg_test_4055_restapi-t.cpp | 10 +- .../tests/reg_test_4072-show-warnings-t.cpp | 8 +- .../tap/tests/reg_test_4158_change_user-t.cpp | 5 - .../tests/reg_test_4264-commit_rollback-t.cpp | 154 ++++---- .../reg_test_4300-dollar_quote_check-t.cpp | 12 +- .../reg_test_compression_split_packets-t.cpp | 16 +- .../reg_test_fast_forward_split_packet-t.cpp | 8 +- .../reg_test_mariadb_stmt_store_result-t.cpp | 8 +- .../tests/reg_test_sql_calc_found_rows-t.cpp | 8 +- .../reg_test_stmt_resultset_err_no_rows-t.cpp | 9 +- ..._test_stmt_resultset_err_no_rows_php-t.cpp | 7 +- .../tests/repro_3404-mysql_close_fd_leak.cpp | 7 +- test/tap/tests/repro_test_leak_3350.cpp | 8 +- test/tap/tests/repro_test_leak_3525.cpp | 6 +- test/tap/tests/set_character_set-t.cpp | 3 +- test/tap/tests/set_testing-240-t.cpp | 2 +- test/tap/tests/set_testing-240.h | 2 +- test/tap/tests/set_testing-multi-t.cpp | 2 +- test/tap/tests/set_testing-t.cpp | 2 +- test/tap/tests/set_testing.h | 2 +- test/tap/tests/setparser_test-t.cpp | 6 +- test/tap/tests/setparser_test.cpp | 4 + test/tap/tests/setparser_test2.cpp | 45 ++- test/tap/tests/setparser_test3.cpp | 45 ++- test/tap/tests/setparser_test_common.h | 358 +++++++++--------- test/tap/tests/sqlite3-t.cpp | 6 +- test/tap/tests/sqlite_autocommit-t.cpp | 3 +- ...metheus_metrics_dump-t_disabled_gh3571.cpp | 3 +- test/tap/tests/test_admin_stats-t.cpp | 3 +- .../test_auto_increment_delay_multiplex-t.cpp | 4 +- test/tap/tests/test_backend_conn_ping-t.cpp | 18 +- test/tap/tests/test_binlog_reader-t.cpp | 11 +- ...inlog_reader_uses_previous_hostgroup-t.cpp | 3 +- test/tap/tests/test_client_limit_error-t.cpp | 70 ++-- test/tap/tests/test_cluster1-t.cpp | 11 +- test/tap/tests/test_cluster_sync-t.cpp | 64 ++-- ...com_binlog_dump_enables_fast_forward-t.cpp | 8 +- ..._register_slave_enables_fast_forward-t.cpp | 3 + ...com_reset_connection_com_change_user-t.cpp | 23 +- .../tests/test_connection_annotation-t.cpp | 3 +- .../tests/test_csharp_connector_support-t.cpp | 3 +- test/tap/tests/test_debug_filters-t.cpp | 13 +- ..._default_value_transaction_isolation-t.cpp | 3 +- ...ult_value_transaction_isolation_attr-t.cpp | 4 +- test/tap/tests/test_digest_umap_aux-t.cpp | 5 - test/tap/tests/test_dns_cache-t.cpp | 3 +- test/tap/tests/test_empty_query-t.cpp | 5 +- .../test_enforce_autocommit_on_reads-t.cpp | 6 +- .../tests/test_filtered_set_statements-t.cpp | 4 +- test/tap/tests/test_firewall-t.cpp | 3 +- test/tap/tests/test_flagOUT_weight-t.cpp | 2 +- test/tap/tests/test_format_utils-t.cpp | 3 + test/tap/tests/test_gtid_forwarding-t.cpp | 3 +- .../test_keep_multiplexing_variables-t.cpp | 22 +- .../tap/tests/test_ldap_stats_mysql_users.cpp | 5 +- test/tap/tests/test_log_last_insert_id-t.cpp | 6 +- .../tap/tests/test_max_transaction_time-t.cpp | 3 +- .../test_mysql_connect_retries_delay-t.cpp | 8 +- .../test_mysql_hostgroup_attributes-1-t.cpp | 2 +- .../test_mysql_query_digests_stages-t.cpp | 12 +- .../test_mysql_query_rules_fast_routing-t.cpp | 4 +- test/tap/tests/test_mysqlsh-t.cpp | 3 +- test/tap/tests/test_ps_async-t.cpp | 13 +- test/tap/tests/test_ps_hg_routing-t.cpp | 8 +- test/tap/tests/test_ps_large_result-t.cpp | 3 +- test/tap/tests/test_ps_no_store-t.cpp | 7 +- ...t_query_rules_fast_routing_algorithm-t.cpp | 11 +- test/tap/tests/test_query_rules_routing-t.cpp | 3 +- test/tap/tests/test_query_timeout-t.cpp | 13 +- test/tap/tests/test_rw_binary_data-t.cpp | 4 +- test/tap/tests/test_server_sess_status-t.cpp | 3 +- .../tests/test_set_character_results-t.cpp | 6 +- .../test_simple_embedded_HTTP_server-t.cpp | 26 +- test/tap/tests/test_sqlite3_server-t.cpp | 9 +- test/tap/tests/test_ssl_connect-t.cpp | 9 +- test/tap/tests/test_ssl_fast_forward-1-t.cpp | 5 +- test/tap/tests/test_ssl_fast_forward-2-t.cpp | 5 +- test/tap/tests/test_ssl_fast_forward-3-t.cpp | 3 - test/tap/tests/test_ssl_large_query-1-t.cpp | 5 +- test/tap/tests/test_ssl_large_query-2-t.cpp | 5 +- .../test_stats_proxysql_message_metrics-t.cpp | 3 +- ...ottle_max_bytes_per_second_to_client-t.cpp | 10 +- test/tap/tests/test_tokenizer-t.cpp | 3 +- test/tap/tests/test_unshun_algorithm-t.cpp | 3 +- .../tests/test_wexecvp_syscall_failures-t.cpp | 3 + .../deprecate_eof_support/Makefile | 8 +- .../deprecate_eof_cache-t.cpp | 8 +- .../eof_cache_mixed_flags-t.cpp | 8 +- .../eof_conn_options_check-t.cpp | 8 +- .../eof_fast_forward-t.cpp | 8 +- .../eof_mixed_flags_queries-t.cpp | 10 +- .../eof_packet_mixed_queries-t.cpp | 8 +- .../deprecate_eof_support/fwd_eof_query.cpp | 10 +- 152 files changed, 785 insertions(+), 978 deletions(-) diff --git a/test/tap/tap/utils.cpp b/test/tap/tap/utils.cpp index 4a13d9fe40..5f260e8f19 100644 --- a/test/tap/tap/utils.cpp +++ b/test/tap/tap/utils.cpp @@ -699,7 +699,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 95b227032d..aa10fbe7ef 100644 --- a/test/tap/tap/utils.h +++ b/test/tap/tap/utils.h @@ -242,7 +242,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/admin-listen_on_unix-t.cpp b/test/tap/tests/admin-listen_on_unix-t.cpp index 7865be8b26..71be632df4 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,7 +43,6 @@ std::string get_admin_mysql_ifaces(MYSQL *admin) { int main(int argc, char** argv) { - CommandLine cl; plan(2+2 + 13); diff --git a/test/tap/tests/admin_show_create_table-t.cpp b/test/tap/tests/admin_show_create_table-t.cpp index 5bbb829b88..6653d78043 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,7 +24,6 @@ using std::string; */ int main() { - CommandLine cl; 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); diff --git a/test/tap/tests/admin_show_fields_from-t.cpp b/test/tap/tests/admin_show_fields_from-t.cpp index 289c29cdfe..472bbd83ef 100644 --- a/test/tap/tests/admin_show_fields_from-t.cpp +++ b/test/tap/tests/admin_show_fields_from-t.cpp @@ -15,13 +15,14 @@ using std::string; +CommandLine cl; + /* this test: * enables mysql-have_ssl * retrieves all tables in the most important schemas */ int main() { - CommandLine cl; 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); diff --git a/test/tap/tests/admin_show_table_status-t.cpp b/test/tap/tests/admin_show_table_status-t.cpp index daa4eb9923..40d53dc75d 100644 --- a/test/tap/tests/admin_show_table_status-t.cpp +++ b/test/tap/tests/admin_show_table_status-t.cpp @@ -15,13 +15,14 @@ using std::string; +CommandLine cl; + /* this test: * enables mysql-have_ssl * retrieves all tables in the most important schemas */ int main() { - CommandLine cl; 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); diff --git a/test/tap/tests/admin_various_commands-t.cpp b/test/tap/tests/admin_various_commands-t.cpp index 251aa51a20..054c7b5617 100644 --- a/test/tap/tests/admin_various_commands-t.cpp +++ b/test/tap/tests/admin_various_commands-t.cpp @@ -15,13 +15,14 @@ using std::string; +CommandLine cl; + /* this test: * enables mysql-have_ssl * retrieves all tables in the most important schemas */ int main() { - CommandLine cl; 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); diff --git a/test/tap/tests/admin_various_commands2-t.cpp b/test/tap/tests/admin_various_commands2-t.cpp index 0945649291..78abe2600d 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,7 +110,6 @@ int run_q(MYSQL *mysql, const char *q) { return 0; } int main() { - CommandLine cl; 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); diff --git a/test/tap/tests/admin_various_commands3-t.cpp b/test/tap/tests/admin_various_commands3-t.cpp index 0e91e8076f..91114dd9a8 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,11 +44,9 @@ int run_q(MYSQL *mysql, const char *q) { return 0; } int main() { - CommandLine cl; srandom(123); - for (auto it = vals.begin() ; it != vals.end() ; it++) { std::string q = "PROXYSQLTEST 1 " + std::to_string(*it); queries.push_back(q); 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 781b193a36..aa506d780f 100644 --- a/test/tap/tests/charset_unsigned_int-t.cpp +++ b/test/tap/tests/charset_unsigned_int-t.cpp @@ -10,8 +10,9 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + int main(int argc, char** argv) { - CommandLine cl; plan(2+2+2+2+2 + 6); diag("Testing correct collation set with proxysql"); 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 529f8c625e..ab905d4ff6 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,7 +58,6 @@ int run_q(MYSQL *mysql, const char *q) { return 0; } int main() { - CommandLine cl; 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); diff --git a/test/tap/tests/kill_connection-t.cpp b/test/tap/tests/kill_connection-t.cpp index 33af021d25..e2bfc713a9 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,7 +29,6 @@ int run_q(MYSQL *mysql, const char *q) { } int main(int argc, char** argv) { - CommandLine cl; int np = 0; np += 2 * NUM_CONNS; // connections diff --git a/test/tap/tests/kill_connection2-t.cpp b/test/tap/tests/kill_connection2-t.cpp index 312be2492f..23d805c03d 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,7 +27,7 @@ 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); @@ -68,7 +69,6 @@ int find_tids() { } int main(int argc, char** argv) { - CommandLine cl; int np = 2; np += 2 * NUM_CONNS ; // connection @@ -105,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(); } @@ -147,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 93ab99e3f1..7607bfe4b6 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,7 +27,7 @@ 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); @@ -68,7 +69,6 @@ int find_tids() { } int main(int argc, char** argv) { - CommandLine cl; int np = 2; // conection admin np += 2; // for processlist @@ -87,11 +87,6 @@ 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); diag("Connecting: cl.admin_username='%s' cl.use_ssl=%d cl.compression=%d", cl.admin_username, cl.use_ssl, cl.compression); @@ -115,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(); } @@ -170,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 695c304058..26af2c4949 100644 --- a/test/tap/tests/max_connections_ff-t.cpp +++ b/test/tap/tests/max_connections_ff-t.cpp @@ -41,7 +41,9 @@ 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 {}; @@ -150,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"; @@ -219,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; @@ -291,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; @@ -340,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; @@ -461,7 +463,6 @@ int test_ff_only_one_free_conn(const CommandLine& cl, MYSQL* proxy_admin, int ma } int main(int argc, char** argv) { - CommandLine cl; plan( 2 + // connection admin @@ -486,13 +487,13 @@ int main(int argc, char** argv) { } // 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 3025772d32..49d286adb6 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,7 +128,6 @@ int execute_stmt(int idx) { } int main(int argc, char** argv) { - CommandLine cl; plan( 1*2 + // connection admin diff --git a/test/tap/tests/mysql-fast_forward-t.cpp b/test/tap/tests/mysql-fast_forward-t.cpp index ee56091dab..374effc182 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,7 +28,7 @@ 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); @@ -53,7 +54,6 @@ int create_connections(CommandLine& cl) { int main(int argc, char** argv) { - CommandLine cl; int np = 0; np += 2; // admin create connection ssl? compress? @@ -96,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(); } @@ -149,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 7ca9186745..e66882e77b 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,7 +26,6 @@ inline unsigned long long monotonic_time() { } int main(int argc, char** argv) { - CommandLine cl; plan(2+2+2+2+2 + 8); diff --git a/test/tap/tests/mysql-init_connect-2-t.cpp b/test/tap/tests/mysql-init_connect-2-t.cpp index c8551d6499..d4fd5c38b9 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,7 +30,6 @@ inline unsigned long long monotonic_time() { } int main(int argc, char** argv) { - CommandLine cl; plan(2+2+2+2+2 + 8); diff --git a/test/tap/tests/mysql-last_insert_id-t.cpp b/test/tap/tests/mysql-last_insert_id-t.cpp index 5c75610356..d3d5dc55a9 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,10 +20,13 @@ 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; plan(2 + 8); diff --git a/test/tap/tests/mysql-mirror1-t.cpp b/test/tap/tests/mysql-mirror1-t.cpp index d4f606d4f5..659e8c8a88 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,7 +33,7 @@ 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); @@ -56,7 +57,6 @@ int create_connections(CommandLine& cl) { } int main(int argc, char** argv) { - CommandLine cl; int np = 2; np += 6; @@ -99,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(); } @@ -156,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(); } diff --git a/test/tap/tests/mysql-set_transaction-t.cpp b/test/tap/tests/mysql-set_transaction-t.cpp index 9ac2915c4e..fca2392c29 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,7 +119,6 @@ int check_transaction_access_mode(MYSQL* mysql) { } int main(int argc, char** argv) { - CommandLine cl; plan(2 + 48); 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 a0d76f1744..6b0d975362 100644 --- a/test/tap/tests/mysql-sql_log_bin-error-t.cpp +++ b/test/tap/tests/mysql-sql_log_bin-error-t.cpp @@ -11,8 +11,9 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + int main(int argc, char** argv) { - CommandLine cl; plan(2 + 1); diff --git a/test/tap/tests/mysql-test_ssl_CA-t.cpp b/test/tap/tests/mysql-test_ssl_CA-t.cpp index d2294ae9bc..f5a90a1c99 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,8 +28,6 @@ inline unsigned long long monotonic_time() { } int main(int argc, char** argv) { - CommandLine cl; - char * p_infra_datadir = std::getenv("REGULAR_INFRA_DATADIR"); if (p_infra_datadir == NULL) { 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 2c6c6d1673..e59e8b3790 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,9 +108,8 @@ void check_matching_logline(fstream& f_log, string regex) { } int main(int, char**) { - plan(2 + 12); - CommandLine cl; + plan(2 + 12); // Open the error log and fetch the final position const string f_path { get_env("REGULAR_INFRA_DATADIR") + "/proxysql.log" }; 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 fa4379fa2f..8f0b463878 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,7 +30,6 @@ int idx2 = 0; int k = 0; int main(int argc, char** argv) { - CommandLine cl; int plans = 2; // connection plans += 4 * 3 * NUM_EXECUTIONS; // 4 INSERT queries each of them triggers a SELECT and a data comparison 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 ddeb9f001f..00f7b31c73 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,7 +41,6 @@ int idx2 = 0; int k = 0; int main(int argc, char** argv) { - CommandLine cl; int plans = 2; // connect plans += 2 * 3 * NUM_EXECUTIONS; // 4 INSERT queries each of them triggers a SELECT and a data comparison diff --git a/test/tap/tests/prepare_statement_err3024-t.cpp b/test/tap/tests/prepare_statement_err3024-t.cpp index 4af17ebb6d..68023b66f3 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,7 +127,6 @@ int create_table_test_sbtest1(int num_rows, MYSQL *mysql) { using std::string; int main(int argc, char** argv) { - CommandLine cl; plan(2 + 3 + NUM_EXECUTIONS*3*2); // 3 prepare + 3 * execution * 2 (execute + store) 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 75edafffba..bcd47acf32 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 a803d0d2d6..e3f217eeee 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 742ee3aed7..c7ec174955 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 5f493f0b7d..96d231d02b 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 ff5b5cdcc5..879e9844ce 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 440e5c64f9..5570313269 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 0cb9505c73..9886a22095 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 6cc59cd3d4..17407f229e 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,18 +79,12 @@ 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; - } plan(2 + tc_rules.size()); 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"); @@ -184,7 +180,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 46264349c1..564daa4529 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 8f6c0506ed..774ccf7c97 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 4b03f23fdc..56b2de69ff 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 b232ab5c27..346eb5a0ec 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 2589fae9b0..1013d9a334 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); 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 e61137567c..d11bc91478 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,12 +147,6 @@ 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); 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 4a58f73158..bd829f4f84 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; 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 82c0e3323f..bc0e88867e 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 65656a4b7f..07a1ae0dd6 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 c6a19cb872..754064ae78 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 b376364393..08f010bf7b 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); 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 1f4eb5b693..e5ce731ed0 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 617f9b3f9f..db29c7a3b7 100644 --- a/test/tap/tests/reg_test_3606-mysql_warnings-t.cpp +++ b/test/tap/tests/reg_test_3606-mysql_warnings-t.cpp @@ -32,6 +32,8 @@ using std::vector; using std::tuple; using std::string; +CommandLine cl; + enum query_type { TEXT_SELECT_WARNING = 0, TEXT_SELECT_NO_WARNING, @@ -82,7 +84,6 @@ int create_testing_tables(MYSQL* mysql_server) { } int main(int argc, char** argv) { - CommandLine cl; uint32_t c_operations = 500; @@ -95,11 +96,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); 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 bf25349f8e..724d2e35fb 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,11 +40,6 @@ 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 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 486c46bd54..f4689be842 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 7570c4642e..e2fbeb0768 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; const double MAX_ALLOWED_CPU_USAGE = 13.0; -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 cd081cd0b1..6c3e05c8c9 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 8fad233ef9..823f7e628e 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 51fd91de47..4679a91a0c 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 7335ed7b67..a51bf1d48d 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 e8c162c88e..86973c2d59 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 d0bcf6dbb4..6fabc4f34e 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 8b01a319c4..8be2eff15a 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 15369d8895..bb4a6b91bd 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 72ecc5b70c..57ad869982 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 a302543202..e13aefd7c3 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 aa21489f1f..18d2337a23 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 10aef61c33..15abb64ead 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 514b5d627e..2426dd5c79 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 03a1f0143e..4f5aeb6431 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 83b1e28770..2dba75503f 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 6d51b66367..a65dd063d3 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 5ac66cbe4a..950a426eae 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/set_character_set-t.cpp b/test/tap/tests/set_character_set-t.cpp index c1ba41b6b3..3d235a46f9 100644 --- a/test/tap/tests/set_character_set-t.cpp +++ b/test/tap/tests/set_character_set-t.cpp @@ -42,8 +42,9 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + int main(int argc, char** argv) { - CommandLine cl; plan(2 + 11); diag("Testing SET CHARACTER SET"); diff --git a/test/tap/tests/set_testing-240-t.cpp b/test/tap/tests/set_testing-240-t.cpp index d1747fef89..683663058c 100644 --- a/test/tap/tests/set_testing-240-t.cpp +++ b/test/tap/tests/set_testing-240-t.cpp @@ -437,7 +437,7 @@ int main(int argc, char *argv[]) { std::string fileName2(std::string(cl.workdir) + "/set_testing-240.csv"); - if (detect_version(cl, is_mariadb) != 0) { + if (detect_version(is_mariadb) != 0) { diag("Cannot detect MySQL version"); return exit_status(); } 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 f5d6e80cdd..ddb4ab303b 100644 --- a/test/tap/tests/set_testing-multi-t.cpp +++ b/test/tap/tests/set_testing-multi-t.cpp @@ -360,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(); } diff --git a/test/tap/tests/set_testing-t.cpp b/test/tap/tests/set_testing-t.cpp index 52e593dae3..c0b05f425a 100644 --- a/test/tap/tests/set_testing-t.cpp +++ b/test/tap/tests/set_testing-t.cpp @@ -360,7 +360,7 @@ int main(int argc, char *argv[]) { 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(); } diff --git a/test/tap/tests/set_testing.h b/test/tap/tests/set_testing.h index b93d036d44..a8d552bc61 100644 --- a/test/tap/tests/set_testing.h +++ b/test/tap/tests/set_testing.h @@ -478,7 +478,7 @@ bool check_session_track_gtids(const std::string& expVal, const std::string& sVa return res; } -int detect_version(CommandLine& cl, bool& is_mariadb, bool& is_cluster) { +int detect_version(bool& is_mariadb, bool& is_cluster) { MYSQL* mysql = mysql_init(NULL); if (!mysql) return 1; diff --git a/test/tap/tests/setparser_test-t.cpp b/test/tap/tests/setparser_test-t.cpp index dcf018c7d5..fa5187a32a 100644 --- a/test/tap/tests/setparser_test-t.cpp +++ b/test/tap/tests/setparser_test-t.cpp @@ -8,11 +8,9 @@ #include -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 e41f0068e3..c3c8caafd6 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 @@ -12,6 +11,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 621b5503f8..e4adc4721b 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,7 +20,6 @@ But they have been left in this way to easily identify the failed check int main(int argc, char** argv) { - CommandLine cl; plan(2 + 48); diag("Testing autocommit and transaction in SQLite3 Server"); 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 633c1543f6..314a5743c1 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,10 +19,11 @@ using std::string; +CommandLine cl; + std::size_t supported_metrics = 121; int main(int argc, char** argv) { - CommandLine cl; plan(2 + 3); diff --git a/test/tap/tests/test_admin_stats-t.cpp b/test/tap/tests/test_admin_stats-t.cpp index 3d2bd1bafb..246e5bc387 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,7 +77,6 @@ int wait_for_history_update(MYSQL* proxysql_admin, uint32_t timeout) { } int main(int argc, char** argv) { - CommandLine cl; /** @brief Minimum number of distinct variable_name strings in the history_mysql_status_variables_lookup table */ const int min_distinct_variable_names = 50; 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 685d98a5cc..227fcabcce 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,7 +899,6 @@ const vector> conn_delay_multiplex_tests { }; int main(int argc, char** argv) { - CommandLine cl; plan( 2 + 2 + // connections diff --git a/test/tap/tests/test_backend_conn_ping-t.cpp b/test/tap/tests/test_backend_conn_ping-t.cpp index ece3c5ca48..7dc0ac6a32 100644 --- a/test/tap/tests/test_backend_conn_ping-t.cpp +++ b/test/tap/tests/test_backend_conn_ping-t.cpp @@ -85,7 +85,7 @@ 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); @@ -153,7 +153,7 @@ int change_mysql_cfg(const CommandLine& cl, const string& host, const string& po return res; } -int create_new_backend_conn(const CommandLine& cl, int tg_hg, vector& mysql_conns) { +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); @@ -212,14 +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; } } @@ -229,7 +229,7 @@ int check_backend_conns(const CommandLine& cl, const test_params_t& test_params, 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; } } @@ -577,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(); @@ -611,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"; @@ -642,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()); } @@ -659,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_reader-t.cpp b/test/tap/tests/test_binlog_reader-t.cpp index f31dd695c3..57b7b032a0 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,7 +126,7 @@ map> extract_hosgtroups_stats(const vector(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 e5953386bb..f66507c6bc 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,6 +22,8 @@ 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" }; @@ -79,7 +81,6 @@ int conn_pool_hg_stat_conn_closed(MYSQL* proxy_admin, int hg_id, vector& } int main(int argc, char** argv) { - CommandLine cl; 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); diff --git a/test/tap/tests/test_client_limit_error-t.cpp b/test/tap/tests/test_client_limit_error-t.cpp index 885a96f69f..7b2ba5b6aa 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,7 +117,7 @@ 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) { +int valid_proxysql_conn(const std::string& addr, std::string& err_msg) { int my_err = EXIT_SUCCESS; MYSQL* proxysql = mysql_init(NULL); @@ -148,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("-------------------------------------------------------------"); @@ -163,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; @@ -206,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("-------------------------------------------------------------"); @@ -219,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; @@ -263,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("-------------------------------------------------------------"); @@ -284,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); } } @@ -338,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("-------------------------------------------------------------"); @@ -363,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); } } @@ -417,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"); @@ -472,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, @@ -480,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." @@ -510,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("-------------------------------------------------------------"); @@ -534,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); } @@ -546,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( @@ -568,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("-------------------------------------------------------------"); @@ -596,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); } } @@ -614,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 { @@ -668,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"); @@ -706,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__); } @@ -729,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; @@ -762,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("-------------------------------------------------------------"); @@ -793,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); @@ -813,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); } } @@ -848,8 +850,8 @@ int test_cache_populated_timeout_conns(const CommandLine& cl, MYSQL* proxysql_ad } int main(int, char**) { + int res = 0; - CommandLine cl; plan(5*2 + 30); @@ -915,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 9c77823073..6dd18f5914 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,7 +140,7 @@ 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); @@ -184,18 +185,12 @@ 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); 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) @@ -247,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 39e08293eb..5a0ffea7bc 100644 --- a/test/tap/tests/test_cluster_sync-t.cpp +++ b/test/tap/tests/test_cluster_sync-t.cpp @@ -69,6 +69,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. * @@ -126,7 +128,7 @@ const uint32_t SYNC_TIMEOUT = 10; const uint32_t CONNECT_TIMEOUT = 10; const uint32_t R_PORT = 96062; -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"; @@ -213,9 +215,7 @@ 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]); @@ -251,10 +251,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"); @@ -407,7 +404,7 @@ int check_mysql_servers_sync( } struct sync_payload_t { - function update_module_val; + function update_module_val; string module; string sync_variable; }; @@ -432,7 +429,7 @@ int64_t fetch_single_int_res(MYSQL* admin) { return val; } -int update_variable_val(const CommandLine& cl, MYSQL* admin, const string& type, const string& var_name) { +int update_variable_val(MYSQL* admin, const string& type, const string& var_name) { cfmt_t select_query { cstr_format("SELECT variable_value FROM global_variables WHERE variable_name='%s'", var_name.c_str()) }; @@ -455,7 +452,7 @@ int update_variable_val(const CommandLine& cl, MYSQL* admin, const string& type, return EXIT_SUCCESS; } -int update_mysql_servers(const CommandLine& cl, MYSQL* admin) { +int update_mysql_servers(MYSQL* admin) { const char select_max_conns_t[] { "SELECT max_connections FROM mysql_servers WHERE hostgroup_id=" "(SELECT default_hostgroup FROM mysql_users WHERE username='%s')" @@ -479,7 +476,7 @@ int update_mysql_servers(const CommandLine& cl, MYSQL* admin) { return EXIT_SUCCESS; } -int update_mysql_query_rules(const CommandLine& cl, MYSQL* admin) { +int update_mysql_query_rules(MYSQL* admin) { const char update_mysql_query_rules[] { "INSERT INTO mysql_query_rules (active) VALUES (1)" }; @@ -494,7 +491,7 @@ int update_mysql_query_rules(const CommandLine& cl, MYSQL* admin) { * @brief Assumes that 'proxysql_servers' holds at least the one entry required for this test. * @details It's assumed that primary ProxySQL is part of a Cluster. */ -int update_proxysql_servers(const CommandLine& cl, MYSQL* admin) { +int update_proxysql_servers(MYSQL* admin) { const char update_proxysql_servers_t[] { "UPDATE proxysql_servers SET comment='%s' WHERE hostname='%s' and port=%d" }; @@ -525,15 +522,15 @@ const vector module_sync_payloads { "admin-cluster_proxysql_servers_diffs_before_sync", }, { - [] (const CommandLine& cl, MYSQL* admin) -> int { - return update_variable_val(cl, admin, "mysql", "mysql-ping_timeout_server"); + [] (MYSQL* admin) -> int { + return update_variable_val(admin, "mysql", "mysql-ping_timeout_server"); }, "mysql_variables", "admin-cluster_mysql_variables_diffs_before_sync" }, { - [] (const CommandLine& cl, MYSQL* admin) -> int { - return update_variable_val(cl, admin, "admin", "admin-refresh_interval"); + [] (MYSQL* admin) -> int { + return update_variable_val(admin, "admin", "admin-refresh_interval"); }, "admin_variables", "admin-cluster_admin_variables_diffs_before_sync" @@ -595,7 +592,7 @@ int wait_for_node_sync(MYSQL* admin, const vector queries, uint32_t time return not_synced; }; -string fetch_remote_checksum(MYSQL* admin, const CommandLine& cl, const string& module) { +string fetch_remote_checksum(MYSQL* admin, const string& module) { const char select_core_module_checksum_t[] { "SELECT checksum FROM stats_proxysql_servers_checksums WHERE hostname='%s' AND port='%d' AND name='%s'" }; @@ -650,7 +647,7 @@ string fetch_runtime_checksum(MYSQL* admin, const string& module) { }; int check_module_checksums_sync( - MYSQL* admin, MYSQL* r_admin, const CommandLine& cl, const sync_payload_t& module_sync, int diffs_sync + MYSQL* admin, MYSQL* r_admin, const sync_payload_t& module_sync, int diffs_sync ) { const char new_remote_checksum_query_t[] { "SELECT count(*) FROM stats_proxysql_servers_checksums WHERE " @@ -680,7 +677,7 @@ int check_module_checksums_sync( return EXIT_FAILURE; } - string cur_remote_checksum { fetch_remote_checksum(r_admin, cl, module) }; + string cur_remote_checksum { fetch_remote_checksum(r_admin, module) }; if (cur_remote_checksum.empty()) { diag("Failed to fetch current fetch for module '%s'", module.c_str()); return EXIT_FAILURE; @@ -694,7 +691,7 @@ int check_module_checksums_sync( if (of_err != EXIT_SUCCESS) { return of_err; } // Perform update operation - int upd_res = module_sync.update_module_val(cl, admin); + int upd_res = module_sync.update_module_val(admin); if (upd_res) { diag("Failed to perform the update operation for module '%s'", module.c_str()); return EXIT_FAILURE; @@ -707,7 +704,7 @@ int check_module_checksums_sync( int sync_res = wait_for_node_sync(r_admin, { new_remote_checksum_query.str }, CHECKSUM_SYNC_TIMEOUT); // Fetch the new remote checksum after the synchronization - string new_remote_checksum { fetch_remote_checksum(r_admin, cl, module) }; + string new_remote_checksum { fetch_remote_checksum(r_admin, module) }; if (new_remote_checksum.empty()) { diag("Failed to fetch current fetch for module '%s'", module.c_str()); return EXIT_FAILURE; @@ -852,7 +849,7 @@ int check_module_checksums_sync( return EXIT_SUCCESS; } -int check_modules_checksums_sync(MYSQL* admin, MYSQL* r_admin, const CommandLine& cl) { +int check_modules_checksums_sync(MYSQL* admin, MYSQL* r_admin) { const int module_diffs_sync = 2; for (const sync_payload_t& sync_payload : module_sync_payloads) { @@ -865,7 +862,7 @@ int check_modules_checksums_sync(MYSQL* admin, MYSQL* r_admin, const CommandLine diag("Start test with sync Enabled for all modules"); for (const sync_payload_t& sync_payload : module_sync_payloads) { - int check_sync = check_module_checksums_sync(admin, r_admin, cl, sync_payload, module_diffs_sync); + int check_sync = check_module_checksums_sync(admin, r_admin, sync_payload, module_diffs_sync); if (check_sync) { diag("Enabled sync test failed for module '%s'. Aborting further testing.", sync_payload.module.c_str()); return EXIT_FAILURE; @@ -890,7 +887,7 @@ int check_modules_checksums_sync(MYSQL* admin, MYSQL* r_admin, const CommandLine const sync_payload_t& sync_payload = module_sync_payloads[j]; const int diffs_sync = j == dis_module ? 0 : module_diffs_sync; - int check_sync = check_module_checksums_sync(admin, r_admin, cl, sync_payload, diffs_sync); + int check_sync = check_module_checksums_sync(admin, r_admin, sync_payload, diffs_sync); if (check_sync) { if (diffs_sync) { diag("Enabled sync test failed for module '%s'. Aborting further testing.", sync_payload.module.c_str()); @@ -907,7 +904,6 @@ int check_modules_checksums_sync(MYSQL* admin, MYSQL* r_admin, const CommandLine int main(int, char**) { int res = 0; - CommandLine cl; std::atomic save_proxy_stderr(false); const size_t num_payloads = module_sync_payloads.size(); @@ -945,7 +941,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; } @@ -968,7 +964,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) @@ -977,7 +973,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"; @@ -1037,7 +1033,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"), @@ -1046,7 +1042,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"), @@ -1055,7 +1051,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); } { @@ -2276,7 +2272,7 @@ int main(int, char**) { // Check sync disable via 'admin-cluster_*_sync' variables { - int checksum_sync_res = check_modules_checksums_sync(proxy_admin, r_proxy_admin, cl); + int checksum_sync_res = check_modules_checksums_sync(proxy_admin, r_proxy_admin); if (checksum_sync_res != EXIT_SUCCESS) { goto cleanup; } @@ -2364,7 +2360,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_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 5d42f890fa..2657e994e5 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,7 +446,7 @@ 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) { +int test_simple_reset_admin(MYSQL*, const std::vector&, bool) { int res = EXIT_FAILURE; MYSQL* admin = mysql_init(NULL); @@ -478,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, @@ -533,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( @@ -715,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); @@ -843,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]); @@ -976,7 +978,7 @@ 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); @@ -1123,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 }, @@ -1138,7 +1140,6 @@ std::vector> tests_fns { }; int main(int argc, char** argv) { - CommandLine cl; // One 'reset_connection' and 'change_user_test' plan(2+2+2+2+2 + tests_fns.size() * 2); @@ -1230,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()); } @@ -1241,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 9be8b74b1a..747bab2f32 100644 --- a/test/tap/tests/test_connection_annotation-t.cpp +++ b/test/tap/tests/test_connection_annotation-t.cpp @@ -17,8 +17,9 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + int main(int argc, char** argv) { - CommandLine cl; plan(2+2 + 1); diff --git a/test/tap/tests/test_csharp_connector_support-t.cpp b/test/tap/tests/test_csharp_connector_support-t.cpp index 5403cd29b5..ef38e25c64 100644 --- a/test/tap/tests/test_csharp_connector_support-t.cpp +++ b/test/tap/tests/test_csharp_connector_support-t.cpp @@ -12,8 +12,9 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + int main(int argc, char** argv) { - CommandLine cl; plan(2 + 4); diff --git a/test/tap/tests/test_debug_filters-t.cpp b/test/tap/tests/test_debug_filters-t.cpp index 84ba380003..8fe75967a1 100644 --- a/test/tap/tests/test_debug_filters-t.cpp +++ b/test/tap/tests/test_debug_filters-t.cpp @@ -31,7 +31,9 @@ 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); @@ -53,7 +55,7 @@ int create_and_close_proxy_conn(const CommandLine& cl) { 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); @@ -152,15 +154,14 @@ int check_log_line(const function& proxy_action, const string& err_id, c } int main(int argc, char** argv) { - CommandLine cl; 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 }, @@ -263,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_value_transaction_isolation-t.cpp b/test/tap/tests/test_default_value_transaction_isolation-t.cpp index 301a9f5bc3..e6e0b21084 100644 --- a/test/tap/tests/test_default_value_transaction_isolation-t.cpp +++ b/test/tap/tests/test_default_value_transaction_isolation-t.cpp @@ -11,8 +11,9 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + int main(int argc, char** argv) { - CommandLine cl; plan(2+2+2+2 + 3); diag("Testing default value for session varable transaction isolation"); 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 b99c775f0b..fb34ed90c8 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,7 +194,6 @@ int extract_exp_iso_level( } int main(int argc, char** argv) { - CommandLine cl; plan(2+2+2*c_user_attributes.size() + c_user_attributes.size()*4); diff --git a/test/tap/tests/test_digest_umap_aux-t.cpp b/test/tap/tests/test_digest_umap_aux-t.cpp index 852270e1d8..8ce175446d 100644 --- a/test/tap/tests/test_digest_umap_aux-t.cpp +++ b/test/tap/tests/test_digest_umap_aux-t.cpp @@ -181,11 +181,6 @@ 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(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); diff --git a/test/tap/tests/test_dns_cache-t.cpp b/test/tap/tests/test_dns_cache-t.cpp index 6b9d8d7c09..83e5a6fc86 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,7 +130,6 @@ bool check_result(const std::string& key, const std::map& p } int main(int argc, char** argv) { - CommandLine cl; // Initialize Admin connection MYSQL* proxysql_admin = mysql_init(NULL); diff --git a/test/tap/tests/test_empty_query-t.cpp b/test/tap/tests/test_empty_query-t.cpp index 8cd35e6f23..72b098e444 100644 --- a/test/tap/tests/test_empty_query-t.cpp +++ b/test/tap/tests/test_empty_query-t.cpp @@ -8,12 +8,13 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + uint32_t EXECUTIONS = 100; int main(int argc, char** argv) { - plan(2 + 1); - CommandLine cl; + 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); 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 40d0f7e956..c11e4f8c61 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,10 +20,6 @@ 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(2+2 + 96); diag("Testing mysql-enforce_autocommit_on_reads"); diff --git a/test/tap/tests/test_filtered_set_statements-t.cpp b/test/tap/tests/test_filtered_set_statements-t.cpp index 793b30c0d8..6d776a57d3 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,7 +73,6 @@ std::vector get_valid_set_query_set(const std::string& set_query, c } int main(int argc, char** argv) { - CommandLine cl; // plan one test per statement attempt + one check 'SUM(sum_time) == 0' for each 'filtered_set_queries' plan(2+2 + filtered_set_queries.size() + filtered_set_queries.size()*get_valid_set_query_set("", "").size()); diff --git a/test/tap/tests/test_firewall-t.cpp b/test/tap/tests/test_firewall-t.cpp index dacc69abc4..4f4c62599d 100644 --- a/test/tap/tests/test_firewall-t.cpp +++ b/test/tap/tests/test_firewall-t.cpp @@ -11,8 +11,9 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + int main(int argc, char** argv) { - CommandLine cl; plan(2+2 + 7); diag("Testing firewall whitelist functionality"); diff --git a/test/tap/tests/test_flagOUT_weight-t.cpp b/test/tap/tests/test_flagOUT_weight-t.cpp index d1b3a4051f..b8a776544a 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,7 +55,6 @@ int run_queries_sets(std::vector& queries, MYSQL *my, const std::st int main(int argc, char** argv) { - CommandLine cl; plan(2+2 + 4); 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_gtid_forwarding-t.cpp b/test/tap/tests/test_gtid_forwarding-t.cpp index 5b46df8132..d7d756a78b 100644 --- a/test/tap/tests/test_gtid_forwarding-t.cpp +++ b/test/tap/tests/test_gtid_forwarding-t.cpp @@ -23,10 +23,11 @@ #include "proxysql_utils.h" #include "re2/re2.h" +CommandLine cl; + int LOOPS = 1000; int main(int, char**) { - CommandLine cl; plan(2 + 3*LOOPS); diff --git a/test/tap/tests/test_keep_multiplexing_variables-t.cpp b/test/tap/tests/test_keep_multiplexing_variables-t.cpp index 190d4b6d96..006ae22856 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,7 +34,7 @@ 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) { +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); @@ -69,12 +71,6 @@ 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(2+2*4+2*2*select_queries.size() + 26); @@ -101,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."); } @@ -119,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."); } @@ -137,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."); } } @@ -150,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 7208ad5361..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,6 +88,7 @@ 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 ??? @@ -97,8 +100,6 @@ int main(int argc, char** argv) { 5 // Check that conns fails to be created over 'LDAP_MAX_CONNS' ); - CommandLine cl; - struct rlimit limits { 0, 0 }; getrlimit(RLIMIT_NOFILE, &limits); diag("Old process limits: { %ld, %ld }", limits.rlim_cur, limits.rlim_max); 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 f0351cb6f6..a2e902ec00 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) { diff --git a/test/tap/tests/test_max_transaction_time-t.cpp b/test/tap/tests/test_max_transaction_time-t.cpp index 00a4ebc88e..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,7 +39,6 @@ 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(2+2 + NUMQUERIES*2+1); 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 1fbb87558e..a934d0e651 100644 --- a/test/tap/tests/test_mysql_connect_retries_delay-t.cpp +++ b/test/tap/tests/test_mysql_connect_retries_delay-t.cpp @@ -29,21 +29,17 @@ 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(2+2 + test_retry_delays.size()); - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return EXIT_FAILURE; - } - 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) 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 a754ae0d28..7b114f6f48 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,7 +53,6 @@ int run_one_test(MYSQL *mysqladmin, const char *expected_checksum, const char *q } int main(int argc, char** argv) { - CommandLine cl; std::unordered_map queries_and_checksums = { { 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 80c02823b5..f30a2ff72c 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,12 +11,12 @@ #include "command_line.h" #include "utils.h" +CommandLine cl; + std::vector params = { 100, 1234, 2356, 129645, 345123, 412317 }; int main(int argc, char** argv) { - CommandLine cl; - // Initialize TAP with planned number of checks and print the name of the test plan(2 + params.size()); diag("Testing query rules fast routing"); diff --git a/test/tap/tests/test_mysqlsh-t.cpp b/test/tap/tests/test_mysqlsh-t.cpp index 91a812e7bc..b51f252883 100644 --- a/test/tap/tests/test_mysqlsh-t.cpp +++ b/test/tap/tests/test_mysqlsh-t.cpp @@ -17,8 +17,9 @@ using std::string; +CommandLine cl; + int main(int argc, char** argv) { - CommandLine cl; plan(2 + 3); diff --git a/test/tap/tests/test_ps_async-t.cpp b/test/tap/tests/test_ps_async-t.cpp index 0c964e910f..0a6ad916fb 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); @@ -453,7 +455,6 @@ int test_ps_async(MYSQL* proxy, MYSQL* admin) { } int main(int argc, char** argv) { - CommandLine cl; plan(2+2+2 + 4); diag("Testing PS async store result"); diff --git a/test/tap/tests/test_ps_hg_routing-t.cpp b/test/tap/tests/test_ps_hg_routing-t.cpp index c8a5e08d1d..2cbac287ea 100644 --- a/test/tap/tests/test_ps_hg_routing-t.cpp +++ b/test/tap/tests/test_ps_hg_routing-t.cpp @@ -13,15 +13,13 @@ #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(2+2 + 1); diag("Testing PS host groups routing"); diff --git a/test/tap/tests/test_ps_large_result-t.cpp b/test/tap/tests/test_ps_large_result-t.cpp index 6c9e020720..098bda36ea 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,7 +28,6 @@ int restore_admin(MYSQL* mysqladmin) { } int main(int argc, char** argv) { - CommandLine cl; plan(2+2 + 9); diag("Testing PS large resultset"); diff --git a/test/tap/tests/test_ps_no_store-t.cpp b/test/tap/tests/test_ps_no_store-t.cpp index 808a6a9bed..7d96ede23a 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,10 +25,6 @@ int restore_admin(MYSQL* mysqladmin) { } int main(int argc, char** argv) { - CommandLine cl; - - if(cl.getEnv()) - return exit_status(); plan(2+2 + 3); diag("Testing PS large resultset"); 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 f2a3136528..a432ec269e 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 @@ -22,9 +22,6 @@ #include "json.hpp" - -CommandLine cl; - using std::pair; using std::string; using nlohmann::json; @@ -34,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; @@ -161,9 +160,7 @@ int create_mysql_servers_range(MYSQL* admin, const pair& host_port, 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) }; @@ -240,7 +237,7 @@ int test_fast_routing_algorithm(MYSQL* admin, MYSQL* proxy, const 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(2+2+2 + 6); diff --git a/test/tap/tests/test_set_character_results-t.cpp b/test/tap/tests/test_set_character_results-t.cpp index 5802fee8aa..a6febe2082 100644 --- a/test/tap/tests/test_set_character_results-t.cpp +++ b/test/tap/tests/test_set_character_results-t.cpp @@ -10,11 +10,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(2+2 + 2); diag("Testing SET CHARACTER SET"); 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 096428c085..03ca039ef5 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,7 +81,6 @@ void run_request(const char *url) { } int main() { - CommandLine cl; plan(2 + 4); diff --git a/test/tap/tests/test_sqlite3_server-t.cpp b/test/tap/tests/test_sqlite3_server-t.cpp index 206cdcb75c..326c0af8c3 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; @@ -339,7 +341,6 @@ 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( @@ -467,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, @@ -493,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_ssl_connect-t.cpp b/test/tap/tests/test_ssl_connect-t.cpp index f517c5a82d..5d98bee5b3 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 b075ef632f..3d3e71f569 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 dd5b0b9a3b..e7257fd2b3 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 af48b854d4..d22ab9c6f4 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 fd9ef63a9e..92be528a18 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 eb780cf2b4..c2d766ece6 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 e13f82c9ff..567711c3ab 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,7 +50,6 @@ int test_table_reset(MYSQL* proxy_admin) { } int main(int argc, char** argv) { - CommandLine cl; plan( 2+2 + // connection 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 a962257d2b..8e4e2e5c71 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,15 +11,15 @@ #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; plan(2+2 + 1); 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 f8ac2db65d..7a36fdc79a 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,7 +397,6 @@ 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 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_with_deps/deprecate_eof_support/Makefile b/test/tap/tests_with_deps/deprecate_eof_support/Makefile index 4db69b67f1..6c0b1ff219 100644 --- a/test/tap/tests_with_deps/deprecate_eof_support/Makefile +++ b/test/tap/tests_with_deps/deprecate_eof_support/Makefile @@ -4,13 +4,13 @@ MARIADB_BASE_FOLDER=$(TEST_DEPS)/mariadb-client-library-3.1.9/ MARIADB_TEST_DEP=$(TEST_DEPS)/mariadb-client-library-3.1.9/mariadb-connector-c BASE_DIR_EXIST := $(shell if [ -d $(MARIADB_BASE_FOLDER) ]; then echo 1; else echo 0; fi) -DEP_FOLDER_EMPTY := $(shell if [ -f $(MARIADB_TEST_DEP)/CMakeLists.txt ]; then echo 1; else echo 0; fi) +#DEP_FOLDER_EMPTY := $(shell if [ -f $(MARIADB_TEST_DEP)/CMakeLists.txt ]; then echo 1; else echo 0; fi) ifeq ($(BASE_DIR_EXIST), 1) -ifeq ($(DEP_FOLDER_EMPTY), 0) - $(error "Dependency folder '$(MARIADB_TEST_DEP)' is empty. Make sure folder is initialized") -endif +#ifeq ($(DEP_FOLDER_EMPTY), 0) +# $(error "Dependency folder '$(MARIADB_TEST_DEP)' is empty. Make sure folder is initialized") +#endif .PHONY: all all: build_deps tests 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 66c4e8b8c1..6202c7131a 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 @@ -21,6 +21,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. @@ -52,7 +54,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 }; @@ -62,11 +63,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 22f6ee9ffc..5804809cee 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 bb9cbfe999..fe64bb3db7 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 @@ -26,6 +26,8 @@ using nlohmann::json; +CommandLine cl; + /** * @brief Extracts all the columns from a `MYSQL_RES` into a `nlohmann::json`. * @@ -97,12 +99,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 976c4931c5..901a878b96 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 @@ -30,6 +30,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')", @@ -182,12 +184,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 d860ed25c3..d01a9e0596 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 6584afb920..db8f91a852 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 faf18c8599..8438db512d 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 @@ -20,6 +20,8 @@ using namespace nlohmann; using std::string; using std::vector; +CommandLine cl; + int check_arguments(int argc, char** argv) { int err_code = 0; @@ -72,14 +74,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; }