From df76a3dc06ce679dc1a27ffe46c7494bd6609341 Mon Sep 17 00:00:00 2001 From: Rene Cannao Date: Sun, 22 Feb 2026 01:07:31 +0000 Subject: [PATCH] test: implement comprehensive noise injection across MySQL TAP tests Integrated the enhanced noise framework into multiple MySQL-specific tests. Each test now optionally spawns: - Random Stats Poller - REST Prometheus Poller (with auto-enable support) - PgSQL Traffic v2 (configured with 100 conns and 300ms delay) This significantly increases the background load during test execution to better uncover potential race conditions and stability issues. --- test/tap/tap/utils.h | 5 +++++ test/tap/tests/mysql-fast_forward-t.cpp | 19 ++++++++++++++----- test/tap/tests/mysql-last_insert_id-t.cpp | 4 +++- test/tap/tests/mysql-mirror1-t.cpp | 19 ++++++++++++++----- .../mysql-protocol_compression_level-t.cpp | 13 +++++++++++-- ...mysql-select_version_without_backend-t.cpp | 15 ++++++++++++--- test/tap/tests/mysql-set_wait_timeout-t.cpp | 13 +++++++++++-- test/tap/tests/mysql-show_ssl_version-t.cpp | 11 ++++++++++- .../tests/mysql-test_malformed_packet-t.cpp | 11 ++++++++++- test/tap/tests/mysql-watchdog_test-t.cpp | 11 ++++++++++- ...ostgroup_attributes-servers_defaults-t.cpp | 13 +++++++++++-- .../tests/mysql_query_logging_memory-t.cpp | 11 ++++++++++- .../test_mysql_query_digests_stages-t.cpp | 11 ++++++++++- 13 files changed, 131 insertions(+), 25 deletions(-) diff --git a/test/tap/tap/utils.h b/test/tap/tap/utils.h index 576a0b423..3e7775152 100644 --- a/test/tap/tap/utils.h +++ b/test/tap/tap/utils.h @@ -1077,4 +1077,9 @@ void spawn_noise(const CommandLine& cl, const std::string& tool_path, const std: */ extern "C" void stop_noise_tools(); +/** + * @brief Returns the number of background noise tools currently running. + */ +extern "C" int get_noise_tools_count(); + #endif // #define UTILS_H diff --git a/test/tap/tests/mysql-fast_forward-t.cpp b/test/tap/tests/mysql-fast_forward-t.cpp index 4a37ad0e9..1e47ce644 100644 --- a/test/tap/tests/mysql-fast_forward-t.cpp +++ b/test/tap/tests/mysql-fast_forward-t.cpp @@ -6,6 +6,7 @@ #include "tap.h" #include "command_line.h" +#include "noise_utils.h" #include "utils.h" @@ -44,6 +45,15 @@ int create_connections(CommandLine& cl) { int main(int argc, char** argv) { CommandLine cl; + if (cl.getEnv()) { + diag("Failed to get the required environmental variables."); + return -1; + } + + 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"}}); + int np = 0; np += 3; // for processlist np += NUM_CONNS ; // to kill connections @@ -55,11 +65,10 @@ int main(int argc, char** argv) { np += 2; // to count rows np += NUM_CONNS ; // to run third DO 1 - plan(np); - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; + if (cl.use_noise) { + plan(np + 3); + } else { + plan(np); } diff --git a/test/tap/tests/mysql-last_insert_id-t.cpp b/test/tap/tests/mysql-last_insert_id-t.cpp index 6ca510b13..046bd5d9c 100644 --- a/test/tap/tests/mysql-last_insert_id-t.cpp +++ b/test/tap/tests/mysql-last_insert_id-t.cpp @@ -31,9 +31,11 @@ int main(int argc, char** argv) { spawn_internal_noise(cl, internal_noise_mysql_traffic); 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 + 2); + plan(8 + 4); } else { plan(8); } diff --git a/test/tap/tests/mysql-mirror1-t.cpp b/test/tap/tests/mysql-mirror1-t.cpp index 12fe407c1..4245efd9b 100644 --- a/test/tap/tests/mysql-mirror1-t.cpp +++ b/test/tap/tests/mysql-mirror1-t.cpp @@ -7,6 +7,7 @@ #include "tap.h" #include "command_line.h" +#include "noise_utils.h" #include "utils.h" @@ -47,15 +48,23 @@ int create_connections(CommandLine& cl) { int main(int argc, char** argv) { CommandLine cl; + if (cl.getEnv()) { + diag("Failed to get the required environmental variables."); + return -1; + } + + 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"}}); + int np = 0; np += 6; np += NUM_CONNS; // new admin connections - plan(np); - - if (cl.getEnv()) { - diag("Failed to get the required environmental variables."); - return -1; + if (cl.use_noise) { + plan(np + 3); + } else { + plan(np); } diff --git a/test/tap/tests/mysql-protocol_compression_level-t.cpp b/test/tap/tests/mysql-protocol_compression_level-t.cpp index 307db5382..20ef1a789 100644 --- a/test/tap/tests/mysql-protocol_compression_level-t.cpp +++ b/test/tap/tests/mysql-protocol_compression_level-t.cpp @@ -25,6 +25,7 @@ #include "tap.h" #include "command_line.h" +#include "noise_utils.h" #include "utils.h" using std::string; @@ -112,8 +113,6 @@ int check_perf_diff(const string tcase, double time1, double time2, double exp_d } int main(int argc, char** argv) { - plan(8); - CommandLine cl; if (cl.getEnv()) { @@ -121,6 +120,16 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } + 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); + } else { + plan(8); + } + MYSQL* admin = init_mysql_conn(cl.host, cl.admin_port, cl.admin_username, cl.admin_password); if (!admin) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(admin)); diff --git a/test/tap/tests/mysql-select_version_without_backend-t.cpp b/test/tap/tests/mysql-select_version_without_backend-t.cpp index 5decf433d..9b68e1dd4 100644 --- a/test/tap/tests/mysql-select_version_without_backend-t.cpp +++ b/test/tap/tests/mysql-select_version_without_backend-t.cpp @@ -80,6 +80,7 @@ #include "tap.h" #include "command_line.h" +#include "noise_utils.h" #include "utils.h" using std::string; @@ -181,15 +182,23 @@ int test_mode(MYSQL* admin, MYSQL* proxy, int mode, bool expect_success) { } int main(int argc, char** argv) { - // We have 2 queries × 2 modes = 4 tests total - plan(4); - CommandLine cl; if (cl.getEnv()) { diag("Failed to get the required environmental variables."); return exit_status(); } + 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"}}); + + // We have 2 queries × 2 modes = 4 tests total + if (cl.use_noise) { + plan(4 + 3); + } else { + plan(4); + } + MYSQL* admin = init_mysql_conn(cl.host, cl.admin_username, cl.admin_password, cl.admin_port); if (!admin) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(admin)); diff --git a/test/tap/tests/mysql-set_wait_timeout-t.cpp b/test/tap/tests/mysql-set_wait_timeout-t.cpp index 4f3268b04..29538d147 100644 --- a/test/tap/tests/mysql-set_wait_timeout-t.cpp +++ b/test/tap/tests/mysql-set_wait_timeout-t.cpp @@ -9,6 +9,7 @@ #include "tap.h" #include "command_line.h" +#include "noise_utils.h" #include "utils.h" #include "json.hpp" @@ -180,14 +181,22 @@ int test_wait_timeout_json_values(CommandLine *cl, MYSQL *admin) { } int main(int argc, char** argv) { - plan(12); // 4 + 8 tests for new JSON validation function - CommandLine cl; if (cl.getEnv()) { diag("Failed to get the required environmental variables."); return exit_status(); } + 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(12 + 3); + } else { + plan(12); + } + MYSQL* admin = init_mysql_conn(cl.host, cl.admin_username, cl.admin_password, cl.admin_port); if (!admin) { fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(admin)); diff --git a/test/tap/tests/mysql-show_ssl_version-t.cpp b/test/tap/tests/mysql-show_ssl_version-t.cpp index c6276486a..8e9c1e084 100644 --- a/test/tap/tests/mysql-show_ssl_version-t.cpp +++ b/test/tap/tests/mysql-show_ssl_version-t.cpp @@ -14,6 +14,7 @@ #include "tap.h" #include "command_line.h" +#include "noise_utils.h" #include "utils.h" using std::string; @@ -25,6 +26,10 @@ int main(int argc, char** argv) { return exit_status(); } + 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"}}); + std::vector ssl_version_queries = { "SHOW STATUS LIKE 'Ssl_version'", "SHOW STATUS LIKE 'ssl_version'", @@ -38,7 +43,11 @@ int main(int argc, char** argv) { }; int num_plans = ssl_version_queries.size() + 1; // +1 for query count check - plan(num_plans); + if (cl.use_noise) { + plan(num_plans + 3); + } else { + plan(num_plans); + } MYSQL* admin = init_mysql_conn(cl.host, cl.admin_port, cl.admin_username, cl.admin_password); if (!admin) { diff --git a/test/tap/tests/mysql-test_malformed_packet-t.cpp b/test/tap/tests/mysql-test_malformed_packet-t.cpp index 3f6670265..5c5a06995 100644 --- a/test/tap/tests/mysql-test_malformed_packet-t.cpp +++ b/test/tap/tests/mysql-test_malformed_packet-t.cpp @@ -9,6 +9,7 @@ #include "mysql.h" #include "tap.h" #include "command_line.h" +#include "noise_utils.h" #include "utils.h" constexpr size_t BUFFER_SIZE = 1024; @@ -126,6 +127,10 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } + 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"}}); + std::vector> malformed_pkts = { {0x01, 0x00}, {0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFE, 0x00, 0x00}, @@ -138,7 +143,11 @@ int main(int argc, char** argv) { {0x03, 0x00, 0x00, 0x2F, 0x2A, 0xE0, 0x00}, }; - plan(malformed_pkts.size() * 4); + if (cl.use_noise) { + plan(malformed_pkts.size() * 4 + 3); + } else { + plan(malformed_pkts.size() * 4); + } { diag(">>> Sending malformed packets to BACKEND connection <<<"); diff --git a/test/tap/tests/mysql-watchdog_test-t.cpp b/test/tap/tests/mysql-watchdog_test-t.cpp index 0c86df045..82b3789ce 100644 --- a/test/tap/tests/mysql-watchdog_test-t.cpp +++ b/test/tap/tests/mysql-watchdog_test-t.cpp @@ -10,6 +10,7 @@ #include "mysql.h" #include "tap.h" #include "command_line.h" +#include "noise_utils.h" using std::string; @@ -41,7 +42,15 @@ int main() { return -1; } - plan(1); // One test for MySQL + 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(1 + 3); + } else { + plan(1); + } MYSQL* proxysql_admin = mysql_init(NULL); if (!proxysql_admin) { 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 6b4245f40..a9adc3d8b 100644 --- a/test/tap/tests/mysql_hostgroup_attributes-servers_defaults-t.cpp +++ b/test/tap/tests/mysql_hostgroup_attributes-servers_defaults-t.cpp @@ -22,6 +22,7 @@ #include "tap.h" #include "utils.h" +#include "noise_utils.h" #include "command_line.h" using nlohmann::json; @@ -106,8 +107,6 @@ void check_matching_logline(fstream& f_log, string regex) { } int main(int, char**) { - plan(12); - CommandLine cl; if (cl.getEnv()) { @@ -115,6 +114,16 @@ int main(int, char**) { return EXIT_FAILURE; } + 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(12 + 3); + } else { + plan(12); + } + // Open the error log and fetch the final position const string f_path { get_env("REGULAR_INFRA_DATADIR") + "/proxysql.log" }; fstream f_log {}; diff --git a/test/tap/tests/mysql_query_logging_memory-t.cpp b/test/tap/tests/mysql_query_logging_memory-t.cpp index 51c1a628a..36550e9b3 100644 --- a/test/tap/tests/mysql_query_logging_memory-t.cpp +++ b/test/tap/tests/mysql_query_logging_memory-t.cpp @@ -19,6 +19,7 @@ #include "tap.h" #include "command_line.h" +#include "noise_utils.h" #include "utils.h" using std::string; @@ -185,6 +186,10 @@ int main() { return -1; } + 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"}}); + const unsigned int num_selects = 200; // Number of "SELECT 1" queries to run unsigned int p = 2; // Number of tests for table structure checks p += num_selects/10; // Number of tests for SELECT 1 queries (one every 10 iterations) @@ -192,7 +197,11 @@ int main() { p += 1; // Number of tests for empty hostgroup error p += 1; // Number of tests for non-existing schema error p += 2; // Number of tests for checking query results in stats and history tables - plan(p); + if (cl.use_noise) { + plan(p + 3); + } else { + plan(p); + } MYSQL* admin_conn = mysql_init(nullptr); if (!admin_conn) { 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 f9dd58b1f..5842b20bd 100644 --- a/test/tap/tests/test_mysql_query_digests_stages-t.cpp +++ b/test/tap/tests/test_mysql_query_digests_stages-t.cpp @@ -38,6 +38,7 @@ #include "proxysql_utils.h" #include "re2/re2.h" #include "command_line.h" +#include "noise_utils.h" #include "tap.h" __thread int mysql_thread___query_digests_max_query_length = 65000; @@ -783,6 +784,10 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } + 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"}}); + bool exec_crashing_tests = true; bool exec_grouping_tests = true; bool exec_regular_tests = true; @@ -849,7 +854,11 @@ int main(int argc, char** argv) { if (exec_grouping_tests) { tests_planned += grouping_tests_num; }; if (exec_crashing_tests) { tests_planned += crashing_tests_num; }; - plan(tests_planned); + if (cl.use_noise) { + plan(tests_planned + 3); + } else { + plan(tests_planned); + } if (exec_regular_tests) { process_digest_tests(regular_tests_defs);