Skip to content

Commit 25c8fd1

Browse files
committed
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.
1 parent 96c686d commit 25c8fd1

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

test/tap/tests/pgsql-servers_ssl_params-t.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,20 @@ static void test_monitor_uses_per_server_row(PGconn* admin) {
499499
exec_ok(admin, q.str().c_str());
500500
exec_ok(admin, "LOAD PGSQL SERVERS TO RUNTIME");
501501

502+
// Drain any monitor connect cycle scheduled with the pre-LOAD config.
503+
// Why: the monitor thread may already be mid-cycle when LOAD runs; that
504+
// in-flight connect was scheduled with the OLD SSL params (no TLSv1 pin)
505+
// and will succeed and bump the counter AFTER we sample ok_before. Wait
506+
// until two consecutive 1s samples are equal — meaning the new config
507+
// is in effect and the counter has plateaued.
502508
long ok_before = getMonitorValue(admin, "PgSQL_Monitor_ssl_connections_OK");
503-
diag("With TLSv1 per-server pin, ssl OK before wait: %ld", ok_before);
509+
for (int i = 0; i < 10; i++) {
510+
usleep(1000000); // 1s — longer than the test's monitor connect interval
511+
long sample = getMonitorValue(admin, "PgSQL_Monitor_ssl_connections_OK");
512+
if (sample == ok_before) break;
513+
ok_before = sample;
514+
}
515+
diag("With TLSv1 per-server pin, ssl OK before wait (post-drain): %ld", ok_before);
504516

505517
usleep(5000000); // 5 seconds — multiple monitor cycles
506518

0 commit comments

Comments
 (0)