diff --git a/test/tap/tap/noise_utils.cpp b/test/tap/tap/noise_utils.cpp index 8e499f982..7adb8c2c3 100644 --- a/test/tap/tap/noise_utils.cpp +++ b/test/tap/tap/noise_utils.cpp @@ -485,6 +485,7 @@ void internal_noise_pgsql_traffic_v2(const CommandLine& cl, const NoiseOptions& int num_connections = get_opt_int(opt, "num_connections", 20); int reconnect_interval = get_opt_int(opt, "reconnect_interval", 200); 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 std::string conninfo = "host=" + std::string(cl.host) + " port=" + std::to_string(cl.pgsql_port) + @@ -502,9 +503,17 @@ void internal_noise_pgsql_traffic_v2(const CommandLine& cl, const NoiseOptions& std::string check_table = "SELECT 1 FROM information_schema.tables WHERE table_name = '" + tablename + "'"; PGresult* res = PQexec(setup_conn, check_table.c_str()); - if (PQresultStatus(res) == PGRES_TUPLES_OK && PQntuples(res) == 0) { + if (PQresultStatus(res) != PGRES_TUPLES_OK) { + noise_log("[NOISE] PgSQL Traffic v2: Table verification query failed: " + std::string(PQresultErrorMessage(res)) + "\n"); PQclear(res); - noise_log("[NOISE] PgSQL Traffic v2: Creating table " + tablename + " in postgres database\n"); + PQfinish(setup_conn); + register_noise_failure("PgSQL Traffic v2 (Verification)"); + return; + } + + 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)"; res = PQexec(setup_conn, create_sql.c_str()); if (PQresultStatus(res) != PGRES_COMMAND_OK) { @@ -515,7 +524,7 @@ void internal_noise_pgsql_traffic_v2(const CommandLine& cl, const NoiseOptions& PQclear(res); std::this_thread::sleep_for(std::chrono::seconds(1)); } else { - noise_log("[NOISE] PgSQL Traffic v2: Table " + tablename + " already exists or verification failed\n"); + noise_log("[NOISE] PgSQL Traffic v2: Table " + tablename + " verified\n"); PQclear(res); } @@ -555,14 +564,20 @@ 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]() { + workers.emplace_back([&, conninfo, tablename, reconnect_interval, avg_delay_ms]() { PGconn* conn = nullptr; uint64_t worker_queries = 0; std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution<> op_dist(0, 3); std::uniform_int_distribution<> id_dist(1, 10000); - std::uniform_int_distribution<> delay_dist(50, 200); + + // Range is +/- 50% of average + int min_delay = avg_delay_ms / 2; + int max_delay = avg_delay_ms + (avg_delay_ms / 2); + if (min_delay < 1) min_delay = 1; + std::uniform_int_distribution<> delay_dist(min_delay, max_delay); + std::uniform_int_distribution<> start_dist(0, 500); // Staggered start @@ -610,11 +625,7 @@ void internal_noise_pgsql_traffic_v2(const CommandLine& cl, const NoiseOptions& if (r) PQclear(r); worker_queries++; - uint64_t current_total = ++total_queries; - - if (current_total % 1000 == 0) { - noise_log("[NOISE] PgSQL Traffic v2 progress: " + std::to_string(current_total) + " queries executed...\n"); - } + total_queries++; if (worker_queries % reconnect_interval == 0) { if (!connect()) break; diff --git a/test/tap/tests/test_noise_injection-t.cpp b/test/tap/tests/test_noise_injection-t.cpp index cf90fb664..1b831e56b 100644 --- a/test/tap/tests/test_noise_injection-t.cpp +++ b/test/tap/tests/test_noise_injection-t.cpp @@ -36,7 +36,7 @@ int main(int argc, char** argv) { 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_pgsql_traffic_v2, {{"num_connections", "100"}, {"reconnect_interval", "100"}}); + 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...");