mirror of https://github.com/sysown/proxysql
- 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.pull/5408/head
parent
43d535465e
commit
925cc1a90a
@ -1,66 +1,47 @@
|
||||
#include <stdlib.h>
|
||||
/**
|
||||
* @file test_noise_injection-t.cpp
|
||||
* @brief This tests the noise injection framework by spawning all available routines.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
Loading…
Reference in new issue