mirror of https://github.com/sysown/proxysql
- Add use_noise flag to CommandLine - Implement spawn_noise and stop_noise_tools in utils - Integrate cleanup in exit_status - Add initial noise tools in test/tap/noise/ - Add verification test test_noise_injection-t.cpppull/5408/head
parent
932e074649
commit
3018a3e0e8
@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
HOST=$1
|
||||
PORT=$2
|
||||
USER=$3
|
||||
PASS=$4
|
||||
INTERVAL=${5:-1.0}
|
||||
|
||||
while true; do
|
||||
mysql -h $HOST -P $PORT -u $USER -p$PASS -e "SELECT 1;" > /dev/null 2>&1
|
||||
sleep $INTERVAL
|
||||
done
|
||||
@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
HOST=$1
|
||||
PORT=$2
|
||||
USER=$3
|
||||
PASS=$4
|
||||
INTERVAL=${5:-0.5}
|
||||
|
||||
export PGPASSWORD=$PASS
|
||||
|
||||
while true; do
|
||||
psql -h $HOST -p $PORT -U $USER -c "SELECT 1;" > /dev/null 2>&1
|
||||
sleep $INTERVAL
|
||||
done
|
||||
@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python3
|
||||
import mysql.connector
|
||||
import time
|
||||
import argparse
|
||||
import sys
|
||||
import signal
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Generate noise by polling stats tables")
|
||||
parser.add_argument("--host", default="127.0.0.1")
|
||||
parser.add_argument("--port", type=int, default=6032)
|
||||
parser.add_argument("--user", default="admin")
|
||||
parser.add_argument("--password", default="admin")
|
||||
parser.add_argument("--interval", type=float, default=0.5)
|
||||
args = parser.parse_args()
|
||||
|
||||
def signal_handler(sig, frame):
|
||||
sys.exit(0)
|
||||
|
||||
signal.signal(signal.SIGTERM, signal_handler)
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
|
||||
try:
|
||||
conn = mysql.connector.connect(
|
||||
host=args.host,
|
||||
port=args.port,
|
||||
user=args.user,
|
||||
password=args.password,
|
||||
autocommit=True
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
|
||||
while True:
|
||||
cursor.execute("SELECT * FROM stats_mysql_query_digest")
|
||||
cursor.fetchall()
|
||||
cursor.execute("SELECT * FROM stats_mysql_connection_pool")
|
||||
cursor.fetchall()
|
||||
time.sleep(args.interval)
|
||||
except Exception as e:
|
||||
print(f"Error in noise poller: {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@ -0,0 +1,68 @@
|
||||
#include <stdlib.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"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
CommandLine cl;
|
||||
if (cl.getEnv()) {
|
||||
diag("Failed to get environment variables");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Force noise enabled for this test if environment variable is not set
|
||||
// but CommandLine::getEnv() already read it.
|
||||
// To properly test, we should run this with TAP_USE_NOISE=1
|
||||
|
||||
if (!cl.use_noise) {
|
||||
skip_all("TAP_USE_NOISE is not enabled. Skip noise injection test.");
|
||||
}
|
||||
|
||||
plan(3);
|
||||
|
||||
// Use a simple script that just sleeps or a standard one
|
||||
// We'll use our new stats poller but with a long interval or just 'sleep 100'
|
||||
spawn_noise(cl, "/bin/sleep", {"100"});
|
||||
|
||||
// We can't easily get the PID from here as it's hidden in utils.cpp
|
||||
// but we can check if a sleep 100 process exists.
|
||||
// However, multiple might exist.
|
||||
|
||||
// Better way: use a specific noise tool that writes its PID to a file
|
||||
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});
|
||||
|
||||
sleep(1); // Give it time to start
|
||||
|
||||
ok(access(pid_file.c_str(), F_OK) == 0, "Noise process started and created PID file");
|
||||
|
||||
// Read PID from file
|
||||
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("Noise process PID: %d", pid);
|
||||
|
||||
// Verify it is alive
|
||||
ok(pid > 0 && kill(pid, 0) == 0, "Noise process is alive");
|
||||
|
||||
// We can manually call stop_noise_tools() to verify it works
|
||||
stop_noise_tools();
|
||||
sleep(1); // Give it time to be killed
|
||||
|
||||
ok(pid > 0 && kill(pid, 0) != 0, "Noise process was killed");
|
||||
|
||||
if (access(pid_file.c_str(), F_OK) == 0) {
|
||||
unlink(pid_file.c_str());
|
||||
}
|
||||
|
||||
return exit_status();
|
||||
}
|
||||
Loading…
Reference in new issue