From 925cc1a90acc17099595a2f13833bc3f63d359f3 Mon Sep 17 00:00:00 2001 From: Rene Cannao Date: Sat, 21 Feb 2026 21:10:51 +0000 Subject: [PATCH] test: add test_noise_injection-t to verify noise framework - Created a new test that spawns all 7 internal noise routines. - Implemented a 10-second sleep to allow noise tools to operate. - Verified synchronized final reporting and shutdown grace period. --- test/tap/tests/test_noise_injection-t.cpp | 79 +++++++++-------------- 1 file changed, 30 insertions(+), 49 deletions(-) diff --git a/test/tap/tests/test_noise_injection-t.cpp b/test/tap/tests/test_noise_injection-t.cpp index ee29b6ad5..1d45acc92 100644 --- a/test/tap/tests/test_noise_injection-t.cpp +++ b/test/tap/tests/test_noise_injection-t.cpp @@ -1,66 +1,47 @@ -#include +/** + * @file test_noise_injection-t.cpp + * @brief This tests the noise injection framework by spawning all available routines. + */ + +#include #include #include #include -#include -#include + #include "tap.h" #include "command_line.h" -#include "utils.h" #include "noise_utils.h" +#include "utils.h" int main(int argc, char** argv) { - CommandLine cl; - if (cl.getEnv()) { - diag("Failed to get environment variables"); - return 1; - } - - if (!cl.use_noise) { - skip_all("TAP_USE_NOISE is not enabled. Skip noise injection test."); - } - - plan(5); - - // --- External Noise Test --- - std::string pid_file = "/tmp/proxysql_noise_test.pid"; - std::string cmd = "echo $$ > " + pid_file + " && exec sleep 100"; - spawn_noise(cl, "/bin/bash", {"-c", cmd}); + CommandLine cl; - sleep(1); // Give it time to start + if (cl.getEnv()) { + diag("Failed to get the required environmental variables."); + return -1; + } - ok(access(pid_file.c_str(), F_OK) == 0, "External noise process started and created PID file"); + // Force noise to be enabled for this test + cl.use_noise = true; - FILE* f = fopen(pid_file.c_str(), "r"); - pid_t pid = 0; - if (f) { - if (fscanf(f, "%d", &pid) != 1) pid = 0; - fclose(f); - } - diag("External noise process PID: %d", pid); + // We have 7 internal noise tools + const int noise_tools_count = 7; + plan(noise_tools_count); - ok(pid > 0 && kill(pid, 0) == 0, "External noise process is alive"); + diag("Spawning all available noise tools..."); - // --- Internal Noise Test --- - NoiseOptions nopt; - nopt["interval_ms"] = "50"; // High intensity for testing - spawn_internal_noise(cl, internal_noise_admin_pinger, nopt); - spawn_internal_noise(cl, internal_noise_prometheus_poller); - spawn_internal_noise(cl, internal_noise_mysql_traffic); - spawn_internal_noise(cl, internal_noise_pgsql_traffic); - - ok(1, "Internal noise threads spawned without crash"); + spawn_internal_noise(cl, internal_noise_admin_pinger); + spawn_internal_noise(cl, internal_noise_stats_poller); + spawn_internal_noise(cl, internal_noise_prometheus_poller); + spawn_internal_noise(cl, internal_noise_random_stats_poller); + spawn_internal_noise(cl, internal_noise_mysql_traffic); + spawn_internal_noise(cl, internal_noise_pgsql_traffic); + spawn_internal_noise(cl, internal_noise_rest_prometheus_poller); - // --- Cleanup Verification --- - stop_noise_tools(); - sleep(1); // Give it time to be killed - - ok(pid > 0 && kill(pid, 0) != 0, "External noise process was killed"); - ok(1, "Internal noise tools stopped (implied by join finishing)"); + diag("Sleeping for 10 seconds to let noises work..."); + sleep(10); - if (access(pid_file.c_str(), F_OK) == 0) { - unlink(pid_file.c_str()); - } + diag("Exiting test, noise reports should follow..."); - return exit_status(); + return exit_status(); }