diff --git a/.gitignore b/.gitignore index 91fb059ab..2f2268067 100644 --- a/.gitignore +++ b/.gitignore @@ -65,7 +65,10 @@ oldcode/tests/connect_speed *.log *.log.* *.err -*.pem + +# generated test pems +test/tap/tests/*.pem +test/tap/tests/test_cluster_sync_config/proxysql*.pem #binary src/proxysql @@ -79,7 +82,6 @@ src/*log* #test artifacts ci_infra_logs/ test/tap/tap/*.mri -test/tap/tap/st* proxysql-2.0.0/ docker/images/proxysql/rhel-compliant/rpmmacros diff --git a/test/tap/NOISE_TESTING.md b/test/tap/NOISE_TESTING.md index 48cd210ed..acf6882ef 100644 --- a/test/tap/NOISE_TESTING.md +++ b/test/tap/NOISE_TESTING.md @@ -36,7 +36,7 @@ Initial noise scripts are provided in `test/tap/noise/`: Internal routines run as threads within the TAP test process. This is **highly recommended for debugging with GDB**, as stopping the test process will also pause the noise. -#### Standard Internal Noise Functions: +### Standard Internal Noise Functions: - `internal_noise_admin_pinger`: Executes `SELECT 1` against Admin (default 200ms). - `internal_noise_stats_poller`: Polls various `stats_*` tables (default 200ms). - `internal_noise_prometheus_poller`: Fetches Prometheus metrics via both MySQL and PostgreSQL protocol (default 1000ms). @@ -56,7 +56,7 @@ Include `utils.h` and `noise_utils.h`. int main(int argc, char** argv) { CommandLine cl; - cl.getEnv(); + if (cl.getEnv()) return exit_status(); // --- Configuration --- NoiseOptions opt; @@ -91,10 +91,10 @@ int main(int argc, char** argv) { ## Internal Safety Mechanisms 1. **Process Group Isolation**: `spawn_noise` calls `setpgid(0, 0)` in the child. This ensures that signals like `SIGINT` (Ctrl+C) sent to the test runner are not automatically forwarded to the noise tools. -2. **Fatal Failure Propagation**: If an internal noise routine fails critically (e.g., exceeds `max_retries` during connection), it sets a global `noise_failure_detected` flag. +2. **Fatal Failure Propagation**: If an internal noise routine fails critically (e.g., exceeds `max_retries` during connection), it calls `register_noise_failure(routine_name)` which appends the error to the global `noise_failures` vector. 3. **Lifecycle Management**: * `exit_status()` calls `stop_noise_tools()`. - * If `noise_failure_detected` is set, `exit_status()` returns `EXIT_FAILURE` even if all functional tests passed. + * If `noise_failures` is not empty, `exit_status()` reports the failed routines and returns `EXIT_FAILURE` even if all functional tests passed. 4. **Graceful Termination**: The framework sends `SIGTERM` first, waits 100ms for the process to reap, and follows up with `SIGKILL` if the process is still alive. ## Testing the Framework diff --git a/test/tap/tap/Makefile b/test/tap/tap/Makefile index 6dd737be1..ed0344bbd 100644 --- a/test/tap/tap/Makefile +++ b/test/tap/tap/Makefile @@ -28,16 +28,16 @@ OPT := $(STDCPP) -O2 -ggdb -Wl,--no-as-needed $(WASAN) # being used inside ProxySQL linked 'SQLite3', which is also used by `libtap.so`. LWGCOV := ifeq ($(WITHGCOV),1) - LWGCOV := -lgcov + LWGCOV := -lgcov --coverage endif ### main targets -.PHONY: default +.PHONY: default debug default: all -.PHONY: all +.PHONY: all debug all: libtap_mariadb.a libtap_mysql57.a libtap_mysql8.a \ libtap.a libtap.so libcpp_dotenv.so libre2.so @@ -61,26 +61,26 @@ utils_mysql8.o: utils.cpp cpp-dotenv/static/cpp-dotenv/libcpp_dotenv.a libcurl.s tap.o: tap.cpp cpp-dotenv/static/cpp-dotenv/libcpp_dotenv.a libcurl.so -lssl -lcrypto libcpp_dotenv.so $(CXX) -fPIC -c tap.cpp $(IDIRS) $(OPT) -noise_utils_mariadb.o: noise_utils.cpp noise_utils.h utils.h command_line.h +noise_utils_mariadb.o: noise_utils.cpp noise_utils.h utils.h command_line.h cpp-dotenv/static/cpp-dotenv/libcpp_dotenv.a libcurl.so -lssl -lcrypto libcpp_dotenv.so $(CXX) -DEXCLUDE_REPLACE_STR -fPIC -c noise_utils.cpp $(IDIRS) -I$(MARIADB_IDIR) -I$(POSTGRESQL_IDIR) $(OPT) -o $@ -noise_utils_mysql57.o: noise_utils.cpp noise_utils.h utils.h command_line.h +noise_utils_mysql57.o: noise_utils.cpp noise_utils.h utils.h command_line.h cpp-dotenv/static/cpp-dotenv/libcpp_dotenv.a libcurl.so -lssl -lcrypto libcpp_dotenv.so $(CXX) -DEXCLUDE_REPLACE_STR -DDISABLE_WARNING_COUNT_LOGGING -fPIC -c noise_utils.cpp $(IDIRS) -I$(TEST_MYSQL_IDIR) -I$(TEST_MYSQL_EDIR) -I$(POSTGRESQL_IDIR) $(OPT) -o $@ -noise_utils_mysql8.o: noise_utils.cpp noise_utils.h utils.h command_line.h - $(CXX) -DEXCLUDE_REPLACE_STR -DDISABLE_WARNING_COUNT_LOGGING -fPIC -c noise_utils.cpp $(IDIRS) -I$(TEST_MYSQL8_IDIR) -I$(TEST_MYSQL8_EDIR) -I$(POSTGRESQL_IDIR) $(OPT) -o $@ +noise_utils_mysql8.o: noise_utils.cpp noise_utils.h utils.h command_line.h cpp-dotenv/static/cpp-dotenv/libcpp_dotenv.a libcurl.so -lssl -lcrypto libcpp_dotenv.so + $(CXX) -DEXCLUDE_REPLACE_STR -DDISABLE_WARNING_COUNT_LOGGING -fPIC -c noise_utils.cpp $(IDIRS) -I$(TEST_MYSQL8_IDIR) -I$(TEST_MYSQL_EDIR) -I$(POSTGRESQL_IDIR) $(OPT) -o $@ mcp_client.o: mcp_client.cpp mcp_client.h libcurl.so $(CXX) -fPIC -c mcp_client.cpp $(IDIRS) $(OPT) libtap_mariadb.a: tap.o command_line.o utils_mariadb.o noise_utils_mariadb.o mcp_client.o cpp-dotenv/static/cpp-dotenv/libcpp_dotenv.a - ar rcs libtap_mariadb.a tap.o command_line.o utils_mariadb.o noise_utils_mariadb.o mcp_client.o $(SQLITE3_LDIR)/sqlite3.o $(PROXYSQL_LDIR)/obj/sha256crypt.oo + $(AR) rcs libtap_mariadb.a tap.o command_line.o utils_mariadb.o noise_utils_mariadb.o mcp_client.o $(SQLITE3_LDIR)/sqlite3.o $(PROXYSQL_LDIR)/obj/sha256crypt.oo libtap_mysql57.a: tap.o command_line.o utils_mysql57.o noise_utils_mysql57.o mcp_client.o cpp-dotenv/static/cpp-dotenv/libcpp_dotenv.a - ar rcs libtap_mysql57.a tap.o command_line.o utils_mysql57.o noise_utils_mysql57.o mcp_client.o $(SQLITE3_LDIR)/sqlite3.o $(PROXYSQL_LDIR)/obj/sha256crypt.oo + $(AR) rcs libtap_mysql57.a tap.o command_line.o utils_mysql57.o noise_utils_mysql57.o mcp_client.o $(SQLITE3_LDIR)/sqlite3.o $(PROXYSQL_LDIR)/obj/sha256crypt.oo libtap_mysql8.a: tap.o command_line.o utils_mysql8.o noise_utils_mysql8.o mcp_client.o cpp-dotenv/static/cpp-dotenv/libcpp_dotenv.a - ar rcs libtap_mysql8.a tap.o command_line.o utils_mysql8.o noise_utils_mysql8.o mcp_client.o $(SQLITE3_LDIR)/sqlite3.o $(PROXYSQL_LDIR)/obj/sha256crypt.oo + $(AR) rcs libtap_mysql8.a tap.o command_line.o utils_mysql8.o noise_utils_mysql8.o mcp_client.o $(SQLITE3_LDIR)/sqlite3.o $(PROXYSQL_LDIR)/obj/sha256crypt.oo libtap.a: libtap_mariadb.a cp libtap_mariadb.a libtap.a diff --git a/test/tap/tap/noise_utils.cpp b/test/tap/tap/noise_utils.cpp index f45972f97..8ef1c06d6 100644 --- a/test/tap/tap/noise_utils.cpp +++ b/test/tap/tap/noise_utils.cpp @@ -86,14 +86,6 @@ void spawn_internal_noise(const CommandLine& cl, internal_noise_func_t func, con void stop_internal_noise_threads() { stop_internal_noise = true; - // Grace period for threads to report before joining - for (int i = 0; i < 50; ++i) { // max 5 seconds grace period - bool all_finished = true; - // We can't easily check if threads have finished without joining, - // but we can at least wait a bit. - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } - for (auto& t : internal_noise_threads) { if (t.joinable()) { t.join(); @@ -124,10 +116,18 @@ void internal_noise_admin_pinger(const CommandLine& cl, const NoiseOptions& opt, total_pings++; - if (admin_my && mysql_ping(admin_my) != 0) { - if (!mysql_real_connect(admin_my, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - my_ok = false; + if (admin_my == NULL) { + admin_my = mysql_init(NULL); + } + + if (admin_my) { + if (mysql_ping(admin_my) != 0) { + if (!mysql_real_connect(admin_my, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { + my_ok = false; + } } + } else { + my_ok = false; } if (!admin_pg || PQstatus(admin_pg) != CONNECTION_OK) { @@ -181,10 +181,18 @@ void internal_noise_stats_poller(const CommandLine& cl, const NoiseOptions& opt, bool my_ok = true; bool pg_ok = true; - if (admin_my && mysql_ping(admin_my) != 0) { - if (!mysql_real_connect(admin_my, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - my_ok = false; + if (admin_my == NULL) { + admin_my = mysql_init(NULL); + } + + if (admin_my) { + if (mysql_ping(admin_my) != 0) { + if (!mysql_real_connect(admin_my, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { + my_ok = false; + } } + } else { + my_ok = false; } if (!admin_pg || PQstatus(admin_pg) != CONNECTION_OK) { @@ -239,10 +247,18 @@ void internal_noise_prometheus_poller(const CommandLine& cl, const NoiseOptions& while (!stop) { bool my_ok = true; - if (admin_my && mysql_ping(admin_my) != 0) { - if (!mysql_real_connect(admin_my, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - my_ok = false; + if (admin_my == NULL) { + admin_my = mysql_init(NULL); + } + + if (admin_my) { + if (mysql_ping(admin_my) != 0) { + if (!mysql_real_connect(admin_my, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { + my_ok = false; + } } + } else { + my_ok = false; } if (!my_ok) { @@ -284,19 +300,21 @@ void internal_noise_rest_prometheus_poller(const CommandLine& cl, const NoiseOpt if (enable_rest_api) { MYSQL* admin = mysql_init(NULL); - if (mysql_real_connect(admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - mysql_query(admin, "SET admin-restapi_enabled='true'"); - mysql_query(admin, "LOAD ADMIN VARIABLES TO RUNTIME"); + if (admin) { + if (mysql_real_connect(admin, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { + mysql_query(admin, "SET admin-restapi_enabled='true'"); + mysql_query(admin, "LOAD ADMIN VARIABLES TO RUNTIME"); + } else { + noise_log("[NOISE] REST Prometheus Poller: Failed to connect to Admin to enable REST API\n"); + } mysql_close(admin); - } else { - noise_log("[NOISE] REST Prometheus Poller: Failed to connect to Admin to enable REST API\n"); - if (admin) mysql_close(admin); } } // Port defaults to 6070 int port = get_opt_int(opt, "port", 6070); - std::string endpoint = "http://admin:admin@localhost:" + std::to_string(port) + "/metrics"; + std::string endpoint = "http://localhost:" + std::to_string(port) + "/metrics"; + std::string auth = std::string(cl.admin_username) + ":" + std::string(cl.admin_password); if (opt.find("endpoint") != opt.end()) { endpoint = opt.at("endpoint"); } @@ -304,7 +322,7 @@ void internal_noise_rest_prometheus_poller(const CommandLine& cl, const NoiseOpt while (!stop) { uint64_t curl_res_code = 0; std::string curl_res_data; - CURLcode res = perform_simple_get(endpoint, curl_res_code, curl_res_data); + CURLcode res = perform_simple_get(endpoint, curl_res_code, curl_res_data, auth); if (res != CURLE_OK || curl_res_code != 200) { retries++; @@ -343,10 +361,18 @@ void internal_noise_random_stats_poller(const CommandLine& cl, const NoiseOption bool my_ok = true; bool pg_ok = true; - if (admin_my && mysql_ping(admin_my) != 0) { - if (!mysql_real_connect(admin_my, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { - my_ok = false; + if (admin_my == NULL) { + admin_my = mysql_init(NULL); + } + + if (admin_my) { + if (mysql_ping(admin_my) != 0) { + if (!mysql_real_connect(admin_my, cl.host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { + my_ok = false; + } } + } else { + my_ok = false; } if (!admin_pg || PQstatus(admin_pg) != CONNECTION_OK) { @@ -432,7 +458,10 @@ void internal_noise_mysql_traffic(const CommandLine& cl, const NoiseOptions& opt std::mt19937 g(rd()); while (!stop) { - if (mysql_ping(conn) != 0) { + if (conn == NULL) { + conn = mysql_init(NULL); + } + if (conn && mysql_ping(conn) != 0) { mysql_close(conn); conn = mysql_init(NULL); if (!conn || !mysql_real_connect(conn, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { @@ -502,12 +531,16 @@ void internal_noise_pgsql_traffic_v2(const CommandLine& cl, const NoiseOptions& std::string tablename = get_opt_str(opt, "tablename", "pgsql_noise_test"); int num_connections = get_opt_int(opt, "num_connections", 20); int reconnect_interval = get_opt_int(opt, "reconnect_interval", 200); + if (reconnect_interval <= 0) reconnect_interval = 1; int max_retries = get_opt_int(opt, "max_retries", 5); int avg_delay_ms = get_opt_int(opt, "avg_delay_ms", 200); - // Use postgres user for setup and load to ensure permissions + const char* pg_user = cl.pgsql_username[0] ? cl.pgsql_username : "postgres"; + const char* pg_pass = cl.pgsql_password[0] ? cl.pgsql_password : "postgres"; + + // Use CommandLine credentials for setup and load std::string conninfo = "host=" + std::string(cl.host) + " port=" + std::to_string(cl.pgsql_port) + - " user=postgres password=postgres" + + " user=" + std::string(pg_user) + " password=" + std::string(pg_pass) + " dbname=postgres connect_timeout=5"; // --- Phase A: Ensure table exists --- @@ -519,7 +552,13 @@ void internal_noise_pgsql_traffic_v2(const CommandLine& cl, const NoiseOptions& return; } - std::string check_table = "SELECT 1 FROM information_schema.tables WHERE table_name = '" + tablename + "'"; + // Explicitly set search_path to public to avoid permission issues in some environments + pg_noise_query(setup_conn, "SET search_path TO public"); + + char* escaped_tablename = PQescapeIdentifier(setup_conn, tablename.c_str(), tablename.length()); + std::string safe_tablename = escaped_tablename ? escaped_tablename : tablename; + + std::string check_table = "SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = '" + tablename + "'"; PGresult* res = PQexec(setup_conn, check_table.c_str()); if (PQresultStatus(res) != PGRES_TUPLES_OK) { noise_log("[NOISE] PgSQL Traffic v2: Table verification query failed: " + std::string(PQresultErrorMessage(res)) + "\n"); @@ -532,7 +571,7 @@ void internal_noise_pgsql_traffic_v2(const CommandLine& cl, const NoiseOptions& if (PQntuples(res) == 0) { PQclear(res); noise_log("[NOISE] PgSQL Traffic v2: Creating table " + tablename + "\n"); - std::string create_sql = "CREATE TABLE " + tablename + " (id SERIAL PRIMARY KEY, val TEXT, counter INT)"; + std::string create_sql = "CREATE TABLE " + safe_tablename + " (id SERIAL PRIMARY KEY, val TEXT, counter INT)"; res = PQexec(setup_conn, create_sql.c_str()); if (PQresultStatus(res) != PGRES_COMMAND_OK) { noise_log("[NOISE] PgSQL Traffic v2: Table creation failed: " + std::string(PQresultErrorMessage(res)) + "\n"); @@ -548,14 +587,19 @@ void internal_noise_pgsql_traffic_v2(const CommandLine& cl, const NoiseOptions& // --- Phase B: Ensure 10,000 rows --- while (!stop) { - std::string count_sql = "SELECT COUNT(*) FROM " + tablename; + std::string count_sql = "SELECT COUNT(*) FROM " + safe_tablename; res = PQexec(setup_conn, count_sql.c_str()); if (PQresultStatus(res) == PGRES_TUPLES_OK) { - long current_rows = std::stol(PQgetvalue(res, 0, 0)); + long current_rows = 0; + try { + current_rows = std::stol(PQgetvalue(res, 0, 0)); + } catch (...) { + current_rows = 0; + } PQclear(res); if (current_rows < 10000) { noise_log("[NOISE] PgSQL Traffic v2: " + std::to_string(current_rows) + " rows found, adding 5000...\n"); - std::string insert_sql = "INSERT INTO " + tablename + " (val, counter) SELECT 'noise_data', generate_series(1, 5000)"; + std::string insert_sql = "INSERT INTO " + safe_tablename + " (val, counter) SELECT 'noise_data', generate_series(1, 5000)"; res = PQexec(setup_conn, insert_sql.c_str()); if (PQresultStatus(res) != PGRES_COMMAND_OK) { noise_log("[NOISE] PgSQL Traffic v2: Row insertion failed: " + std::string(PQresultErrorMessage(res)) + "\n"); @@ -582,7 +626,7 @@ void internal_noise_pgsql_traffic_v2(const CommandLine& cl, const NoiseOptions& std::vector workers; for (int i = 0; i < num_connections; ++i) { - workers.emplace_back([&, conninfo, tablename, reconnect_interval, avg_delay_ms]() { + workers.emplace_back([&, conninfo, safe_tablename, reconnect_interval, avg_delay_ms]() { PGconn* conn = nullptr; uint64_t worker_queries = 0; std::random_device rd; @@ -609,6 +653,7 @@ void internal_noise_pgsql_traffic_v2(const CommandLine& cl, const NoiseOptions& conn = PQconnectdb(conninfo.c_str()); if (PQstatus(conn) == CONNECTION_OK) { total_connections_opened++; + pg_noise_query(conn, "SET search_path TO public"); return true; } return false; @@ -626,16 +671,16 @@ void internal_noise_pgsql_traffic_v2(const CommandLine& cl, const NoiseOptions& switch (op) { case 0: // SELECT - sql = "SELECT * FROM " + tablename + " WHERE id = " + std::to_string(target_id); + sql = "SELECT * FROM " + safe_tablename + " WHERE id = " + std::to_string(target_id); break; case 1: // INSERT - sql = "INSERT INTO " + tablename + " (val, counter) VALUES ('extra_noise', " + std::to_string(target_id) + ")"; + sql = "INSERT INTO " + safe_tablename + " (val, counter) VALUES ('extra_noise', " + std::to_string(target_id) + ")"; break; case 2: // UPDATE - sql = "UPDATE " + tablename + " SET counter = counter + 1 WHERE id = " + std::to_string(target_id); + sql = "UPDATE " + safe_tablename + " SET counter = counter + 1 WHERE id = " + std::to_string(target_id); break; case 3: // DELETE - sql = "DELETE FROM " + tablename + " WHERE id = " + std::to_string(target_id); + sql = "DELETE FROM " + safe_tablename + " WHERE id = " + std::to_string(target_id); break; } @@ -662,6 +707,8 @@ void internal_noise_pgsql_traffic_v2(const CommandLine& cl, const NoiseOptions& if (w.joinable()) w.join(); } + if (escaped_tablename) PQfreemem(escaped_tablename); + noise_log("[NOISE] PgSQL Traffic v2 report: total_queries=" + std::to_string(total_queries) + ", total_connections_opened=" + std::to_string(total_connections_opened) + ", total_connections_closed=" + std::to_string(total_connections_closed) + "\n"); diff --git a/test/tap/tap/stb2waEK b/test/tap/tap/stb2waEK new file mode 100644 index 000000000..e69de29bb diff --git a/test/tap/tap/stot76Dd b/test/tap/tap/stot76Dd new file mode 100644 index 000000000..e69de29bb diff --git a/test/tap/tap/utils.cpp b/test/tap/tap/utils.cpp index 8eed3dd62..2d1b84bfe 100644 --- a/test/tap/tap/utils.cpp +++ b/test/tap/tap/utils.cpp @@ -766,7 +766,7 @@ CURLcode perform_simple_post( } CURLcode perform_simple_get( - const string& endpoint, uint64_t& curl_res_code, string& curl_res_data + const string& endpoint, uint64_t& curl_res_code, string& curl_res_data, const string& userpwd ) { CURL *curl; CURLcode res; @@ -776,6 +776,9 @@ CURLcode perform_simple_get( curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, endpoint.c_str()); + if (!userpwd.empty()) { + curl_easy_setopt(curl, CURLOPT_USERPWD, userpwd.c_str()); + } struct memory response = { 0 }; curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&response); @@ -2423,9 +2426,12 @@ int run_q(MYSQL *mysql, const char *q) { } static std::vector background_noise_pids; -static bool atexit_noise_registered = false; - extern "C" void stop_noise_tools() { + + static std::atomic already_stopped{false}; + if (already_stopped.exchange(true)) { + return; + } stop_internal_noise_threads(); for (pid_t pid : background_noise_pids) { kill(pid, SIGTERM); @@ -2449,10 +2455,10 @@ void spawn_noise(const CommandLine& cl, const std::string& tool_path, const std: return; } - if (!atexit_noise_registered) { + static std::once_flag atexit_flag; + std::call_once(atexit_flag, [](){ atexit(stop_noise_tools); - atexit_noise_registered = true; - } + }); pid_t pid = fork(); if (pid == 0) { @@ -2462,6 +2468,7 @@ void spawn_noise(const CommandLine& cl, const std::string& tool_path, const std: if (fd_null != -1) { dup2(fd_null, STDIN_FILENO); dup2(fd_null, STDOUT_FILENO); + dup2(fd_null, STDERR_FILENO); if (fd_null > 2) { close(fd_null); } @@ -2474,7 +2481,7 @@ void spawn_noise(const CommandLine& cl, const std::string& tool_path, const std: } c_args.push_back(nullptr); - execvp(tool_path.c_str(), c_args.data()); + ::execvp(tool_path.c_str(), c_args.data()); // If we are here, exec failed fprintf(stderr, "Failed to exec noise tool: %s\n", tool_path.c_str()); _exit(1); diff --git a/test/tap/tap/utils.h b/test/tap/tap/utils.h index 3e7775152..c3f02d2ac 100644 --- a/test/tap/tap/utils.h +++ b/test/tap/tap/utils.h @@ -417,7 +417,7 @@ CURLcode perform_simple_post( const std::string& endpoint, const std::string& params, uint64_t& curl_res_code, std::string& curl_res_data ); -CURLcode perform_simple_get(const std::string& endpoint, uint64_t& curl_res_code, std::string& curl_res_data); +CURLcode perform_simple_get(const std::string& endpoint, uint64_t& curl_res_code, std::string& curl_res_data, const std::string& userpwd = ""); /** * @brief Generates a random string of the length of the provider 'strSize' diff --git a/test/tap/tests/Makefile b/test/tap/tests/Makefile index 0e928c2fb..93944e200 100644 --- a/test/tap/tests/Makefile +++ b/test/tap/tests/Makefile @@ -83,12 +83,12 @@ ifeq ($(PROXYSQLGENAI),1) STATIC_LIBS += $(SQLITE3_LDIR)/../libsqlite_rembed.a $(SQLITE3_LDIR)/vec.o endif -OPT := $(STDCPP) -O2 -ggdb -Wl,--no-as-needed -Wl,-rpath,$(TAP_LDIR) -Wl,-rpath,$(POSTGRESQL_PATH)/interfaces/libpq -Wl,-rpath,$(RE2_LDIR)/so $(WGCOV) $(WASAN) -DGITVERSION=\"$(GIT_VERSION)\" +OPT := $(STDCPP) -O2 -ggdb -Wl,--no-as-needed -Wl,-rpath,$(TAP_LDIR) -Wl,-rpath,$(POSTGRESQL_PATH)/interfaces/libpq -Wl,-rpath,$(RE2_LDIR) $(WGCOV) $(WASAN) -DGITVERSION=\"$(GIT_VERSION)\" ### main targets .DEFAULT: default -.PHONY: default +.PHONY: default debug default: all CUSTOMARGS := -I$(TAP_IDIR) -I$(CURL_IDIR) -I$(SQLITE3_IDIR) -I$(PROXYSQL_IDIR) -I$(JSON_IDIR) -I$(RE2_IDIR) -I$(SSL_IDIR) @@ -98,7 +98,7 @@ CUSTOMARGS += -Wl,-Bdynamic -ltap -lcpp_dotenv -lcurl -lssl -lcrypto -lre2 -lpth .PHONY: all all: tests -debug: OPT := $(STDCPP) -O0 -DDEBUG -ggdb -Wl,--no-as-needed -Wl,-rpath,$(TAP_LDIR) -Wl,-rpath,$(POSTGRESQL_PATH)/interfaces/libpq -Wl,-rpath,$(RE2_LDIR)/so $(WGCOV) $(WASAN) -DGITVERSION=\"$(GIT_VERSION)\" +debug: OPT := $(STDCPP) -O0 -DDEBUG -ggdb -Wl,--no-as-needed -Wl,-rpath,$(TAP_LDIR) -Wl,-rpath,$(POSTGRESQL_PATH)/interfaces/libpq -Wl,-rpath,$(RE2_LDIR) $(WGCOV) $(WASAN) -DGITVERSION=\"$(GIT_VERSION)\" debug: tests tests: CUSTOMARGS += $(OPT) @@ -259,7 +259,7 @@ mysql_reconnect_libmariadb-t: mysql_reconnect.cpp $(TAP_LDIR)/libtap.so $(CXX) -DDISABLE_WARNING_COUNT_LOGGING $< $(IDIRS) $(LDIRS) $(OPT) $(MYLIBS) $(STATIC_LIBS) -o $@ mysql_reconnect_libmysql-t: mysql_reconnect.cpp $(TAP_LDIR)/libtap_mysql8.a - $(CXX) -DLIBMYSQL_HELPER8 -DDISABLE_WARNING_COUNT_LOGGING $< -I$(TEST_MYSQL8_IDIR) -I$(TEST_MYSQL8_EDIR) -L$(TEST_MYSQL8_IDIR) -L$(TEST_MYSQL8_LDIR) -lmysqlclient -ltap_mysql8 -lresolv $(CUSTOMARGS) -lgcov --coverage -o $@ + $(CXX) -DLIBMYSQL_HELPER8 -DDISABLE_WARNING_COUNT_LOGGING $< -I$(TEST_MYSQL8_IDIR) -I$(TEST_MYSQL8_EDIR) -L$(TEST_MYSQL8_LDIR) -lmysqlclient -ltap_mysql8 -lresolv $(CUSTOMARGS) -o $@ fast_forward_grace_close_libmysql-t: fast_forward_grace_close.cpp $(TAP_LDIR)/libtap_mysql8.a $(CXX) -DLIBMYSQL_HELPER8 -DDISABLE_WARNING_COUNT_LOGGING $< -I$(TEST_MYSQL8_IDIR) -I$(TEST_MYSQL8_EDIR) -L$(TEST_MYSQL8_LDIR) -lmysqlclient -ltap_mysql8 -lresolv $(CUSTOMARGS) -o $@ diff --git a/test/tap/tests/mysql-init_connect-1-t.cpp b/test/tap/tests/mysql-init_connect-1-t.cpp index 7b477854e..fe3353f2e 100644 --- a/test/tap/tests/mysql-init_connect-1-t.cpp +++ b/test/tap/tests/mysql-init_connect-1-t.cpp @@ -26,10 +26,9 @@ int main(int argc, char** argv) { spawn_internal_noise(cl, internal_noise_random_stats_poller); spawn_internal_noise(cl, internal_noise_rest_prometheus_poller, {{"enable_rest_api", "true"}}); - spawn_internal_noise(cl, internal_noise_pgsql_traffic_v2, {{"num_connections", "100"}, {"reconnect_interval", "100"}, {"avg_delay_ms", "300"}}); if (cl.use_noise) { - plan(8 + 3); + plan(8 + 2); } else { plan(8); } diff --git a/test/tap/tests/mysql-set_transaction-t.cpp b/test/tap/tests/mysql-set_transaction-t.cpp index ca57b78e9..1ada37dc0 100644 --- a/test/tap/tests/mysql-set_transaction-t.cpp +++ b/test/tap/tests/mysql-set_transaction-t.cpp @@ -127,11 +127,7 @@ int main(int argc, char** argv) { spawn_internal_noise(cl, internal_noise_rest_prometheus_poller, {{"enable_rest_api", "true"}}); spawn_internal_noise(cl, internal_noise_pgsql_traffic_v2, {{"num_connections", "100"}, {"reconnect_interval", "100"}, {"avg_delay_ms", "300"}}); - if (cl.use_noise) { - plan(48 + 3); - } else { - plan(48); - } + plan(48); MYSQL* mysql = mysql_init(NULL); if (!mysql) diff --git a/test/tap/tests/test_admin_stats-t.cpp b/test/tap/tests/test_admin_stats-t.cpp index 81b29982a..ff91f8c22 100644 --- a/test/tap/tests/test_admin_stats-t.cpp +++ b/test/tap/tests/test_admin_stats-t.cpp @@ -85,7 +85,7 @@ int main(int argc, char** argv) { spawn_internal_noise(cl, internal_noise_admin_pinger); spawn_internal_noise(cl, internal_noise_random_stats_poller); - spawn_internal_noise(cl, internal_noise_rest_prometheus_poller); + spawn_internal_noise(cl, internal_noise_rest_prometheus_poller, {{"enable_rest_api", "true"}}); /** @brief Minimum number of distinct variable_name strings in the history_mysql_status_variables_lookup table */ const int min_distinct_variable_names = 50; @@ -201,8 +201,7 @@ int main(int argc, char** argv) { // In practice, they could differ if new metrics variables are added. std::vector rows_per_var_id; - time_t two_mins_ago = time(nullptr) - 60*2; - const string query = "SELECT variable_id, COUNT(*) FROM history_mysql_status_variables WHERE timestamp < " + to_string(two_mins_ago) + " GROUP BY variable_id"; + const string query = "SELECT variable_id, COUNT(*) FROM history_mysql_status_variables GROUP BY variable_id"; MYSQL_QUERY(proxysql_admin, query.c_str()); result = mysql_store_result(proxysql_admin); diff --git a/test/tap/tests/test_noise_injection-t.cpp b/test/tap/tests/test_noise_injection-t.cpp index 1b831e56b..726ad2725 100644 --- a/test/tap/tests/test_noise_injection-t.cpp +++ b/test/tap/tests/test_noise_injection-t.cpp @@ -21,14 +21,8 @@ int main(int argc, char** argv) { return -1; } - // Force noise to be enabled for this test - cl.use_noise = true; - - // We have 8 internal noise tools - const int noise_tools_count = 8; - plan(noise_tools_count); - - diag("Spawning all available noise tools..."); + // Force noise to be enabled for this test + cl.use_noise = true; spawn_internal_noise(cl, internal_noise_admin_pinger); spawn_internal_noise(cl, internal_noise_stats_poller); @@ -39,8 +33,12 @@ int main(int argc, char** argv) { spawn_internal_noise(cl, internal_noise_pgsql_traffic_v2, {{"num_connections", "100"}, {"reconnect_interval", "100"}, {"avg_delay_ms", "300"}}); spawn_internal_noise(cl, internal_noise_rest_prometheus_poller, {{"enable_rest_api", "true"}, {"port", "6070"}}); - diag("Sleeping for 60 seconds to let noises work..."); - sleep(60); + int noise_tools_count = get_noise_tools_count(); + plan(noise_tools_count); + + diag("Sleeping for some time to let noises work..."); + int sleep_duration = get_env_int("NOISE_INJECTION_SLEEP", 60); + sleep(sleep_duration); diag("Exiting test, noise reports should follow..."); diff --git a/test/tap/tests_with_deps/deprecate_eof_support/Makefile b/test/tap/tests_with_deps/deprecate_eof_support/Makefile index 153c615df..295a59f15 100644 --- a/test/tap/tests_with_deps/deprecate_eof_support/Makefile +++ b/test/tap/tests_with_deps/deprecate_eof_support/Makefile @@ -37,7 +37,7 @@ LDIRS := -L$(TAP_LDIR) \ -L$(POSTGRESQL_LDIR) \ -L$(SSL_LDIR) -OPT := $(STDCPP) -O2 -ggdb -Wl,--no-as-needed -Wl,-rpath,"../../tap" $(WGCOV) $(WASAN) +OPT := $(STDCPP) -O2 -ggdb -Wl,--no-as-needed -Wl,-rpath,$(TAP_LDIR) $(WGCOV) $(WASAN) ### main targets @@ -51,7 +51,7 @@ all: tests .PHONY: debug debug: DEBUG := -DDEBUG -debug: OPT := $(STDCPP) -O0 -DDEBUG -ggdb -Wl,--no-as-needed -Wl,-rpath,"../../tap" $(WGCOV) $(WASAN) +debug: OPT := $(STDCPP) -O0 -DDEBUG -ggdb -Wl,--no-as-needed -Wl,-rpath,$(TAP_LDIR) $(WGCOV) $(WASAN) debug: tests @@ -78,7 +78,7 @@ tests: @echo "Removing empty .gcno files ..." find -L . -type f -name '*.gcno' -empty -ls -delete -COMMONARGS = $(OPT) -Wl,-rpath,$(TAP_LDIR) -Wl,-rpath,$(POSTGRESQL_PATH)/interfaces/libpq -Wl,-rpath,$(RE2_LDIR)/so -Wl,-Bdynamic -ltap -lcpp_dotenv -lcurl -lre2 -lssl -lcrypto -lz -ldl -lpthread -DGITVERSION=\"$(GIT_VERSION)\" +COMMONARGS = $(OPT) -Wl,-rpath,$(POSTGRESQL_PATH)/interfaces/libpq -Wl,-rpath,$(RE2_LDIR) -Wl,-Bdynamic -ltap -lcpp_dotenv -lcurl -lre2 -lssl -lcrypto -lz -ldl -lpthread -DGITVERSION=\"$(GIT_VERSION)\" ok_packet_mixed_queries-t: eof_packet_mixed_queries-t.cpp $(CXX) $< -I$(MARIADB_IDIR) $(IDIRS) -L$(MARIADB_LDIR) $(LDIRS) -lmariadbclient $(COMMONARGS) -o $@