From 25c8fd160992ccab240783d201f5f7e66a0247ef Mon Sep 17 00:00:00 2001 From: Rene Cannao Date: Sat, 18 Apr 2026 10:59:45 +0000 Subject: [PATCH] test/tap/tests: drain in-flight monitor cycle in pgsql-servers_ssl_params-t The test samples PgSQL_Monitor_ssl_connections_OK immediately after LOAD PGSQL SERVERS TO RUNTIME, then sleeps 5s and checks the counter did not advance (TLSv1 pin should have broken SSL). A monitor connect cycle scheduled with the OLD params can land AFTER ok_before is taken but BEFORE the sleep, succeeding and falsely bumping the counter. Poll for two consecutive equal 1s samples so ok_before is recorded after the new config has taken effect and the counter has plateaued. --- test/tap/tests/pgsql-servers_ssl_params-t.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/tap/tests/pgsql-servers_ssl_params-t.cpp b/test/tap/tests/pgsql-servers_ssl_params-t.cpp index 13f6627a6..b376f5852 100644 --- a/test/tap/tests/pgsql-servers_ssl_params-t.cpp +++ b/test/tap/tests/pgsql-servers_ssl_params-t.cpp @@ -499,8 +499,20 @@ static void test_monitor_uses_per_server_row(PGconn* admin) { exec_ok(admin, q.str().c_str()); exec_ok(admin, "LOAD PGSQL SERVERS TO RUNTIME"); + // Drain any monitor connect cycle scheduled with the pre-LOAD config. + // Why: the monitor thread may already be mid-cycle when LOAD runs; that + // in-flight connect was scheduled with the OLD SSL params (no TLSv1 pin) + // and will succeed and bump the counter AFTER we sample ok_before. Wait + // until two consecutive 1s samples are equal — meaning the new config + // is in effect and the counter has plateaued. long ok_before = getMonitorValue(admin, "PgSQL_Monitor_ssl_connections_OK"); - diag("With TLSv1 per-server pin, ssl OK before wait: %ld", ok_before); + for (int i = 0; i < 10; i++) { + usleep(1000000); // 1s — longer than the test's monitor connect interval + long sample = getMonitorValue(admin, "PgSQL_Monitor_ssl_connections_OK"); + if (sample == ok_before) break; + ok_before = sample; + } + diag("With TLSv1 per-server pin, ssl OK before wait (post-drain): %ld", ok_before); usleep(5000000); // 5 seconds — multiple monitor cycles