Visitar URL original
test: fix flaky LogicalReplicationStatusTest by polling pg_stat_replication by vlsi · Pull Request #3974 · pgjdbc/pgjdbc · GitHub
Skip to content

test: fix flaky LogicalReplicationStatusTest by polling pg_stat_replication - #3974

Merged
vlsi merged 1 commit into
pgjdbc:masterfrom
vlsi:logrep_test
Mar 19, 2026
Merged

vlsi merged 1 commit into
pgjdbc:masterfrom
vlsi:logrep_test

Conversation

@vlsi

@vlsi vlsi commented Mar 17, 2026 •

Copy link
Copy Markdown
Member

The tests were flaky because they assumed forceUpdateStatus() is synchronous — that pg_stat_replication immediately reflects the sent values. In reality forceUpdateStatus() only flushes data to the TCP socket; the server needs time to process the standby status update.

The fix is to add retry loop so the test picks up the new value if so.

@vlsi vlsi added the bug label Mar 17, 2026
@vlsi
vlsi marked this pull request as draft March 18, 2026 15:56
@vlsi vlsi changed the title fix: prevent lastReceiveLSN from going backwards in replication stream test: fix flaky LogicalReplicationStatusTest by polling pg_stat_replication Mar 18, 2026
@vlsi
vlsi marked this pull request as ready for review March 18, 2026 18:20
…cation

The tests were flaky because they assumed forceUpdateStatus() is
synchronous — that pg_stat_replication immediately reflects the sent
values. In reality forceUpdateStatus() only flushes data to the TCP
socket; the server needs time to process the standby status update.

During receiveMessageWithoutBlock(), readInternal() may trigger an
automatic timeUpdateStatus(). The server processes it and shows that
value in pg_stat_replication. When forceUpdateStatus() sends a newer
value moments later, the test queries the view before the server has
processed the second update, seeing the stale value.

Fix: add an optional expected parameter to getLSNFromView(). When
non-null, it polls until pg_stat_replication matches the expected
value (with a 2-second timeout). All tests that call
forceUpdateStatus() followed by a view query now pass the expected
LSN, eliminating the timing race.

Also replace getBackendPID() + string-concatenated pid filter with
a PreparedStatement that joins pg_replication_slots on slot_name,
keeping the PID lookup entirely on the server side.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vlsi
vlsi merged commit 8133a98 into pgjdbc:master Mar 19, 2026
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant