Skip to content

Commit a4fd971

Browse files
michaelpqXuneng Zhou
andcommitted
Fix timing-dependent failure in recovery test 004_timeline_switch
The test introduced by 17b2d5e verifies that a WAL receiver survives across a timeline jump by searching the server logs for termination messages. However, it called restart() before the timeline switch, which kills the WAL receiver and may log the exact message being checked, hence failing the test. As TAP tests reuse the same log file across restarts, a rotate_logfile() is used before the restart so as the log matching check is not impacted by log entries generated by a previous shutdown. Recent changes to file handle inheritance altered I/O timing enough to make this fail consistently while testing another patch. While on it, this adds an extra check based on a PID comparison. This test may lead to false positives as it could be possible that the WAL receiver has processed a timeline jump before the initial PID is grabbed, but it should be good enough in most cases. Like 17b2d5e, backpatch down to v13. Author: Bryan Green <[email protected]> Co-authored-by: Xuneng Zhou <[email protected]> Discussion: https://postgr.es/m/[email protected] Backpatch-through: 13
1 parent 5509055 commit a4fd971

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/test/recovery/t/004_timeline_switch.pl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,19 @@
5454
'postgresql.conf', qq(
5555
primary_conninfo='$connstr_1'
5656
));
57+
58+
# Rotate logfile before restarting, for the log checks done below.
59+
$node_standby_2->rotate_logfile;
5760
$node_standby_2->restart;
5861

62+
# Wait for walreceiver to reconnect after the restart. We want to
63+
# verify that after reconnection, the walreceiver stays alive during
64+
# the timeline switch.
65+
$node_standby_2->poll_query_until('postgres',
66+
"SELECT EXISTS(SELECT 1 FROM pg_stat_wal_receiver)");
67+
my $wr_pid_before_switch = $node_standby_2->safe_psql('postgres',
68+
"SELECT pid FROM pg_stat_wal_receiver");
69+
5970
# Insert some data in standby 1 and check its presence in standby 2
6071
# to ensure that the timeline switch has been done.
6172
$node_standby_1->safe_psql('postgres',
@@ -75,6 +86,14 @@
7586
),
7687
'WAL receiver should not be stopped across timeline jumps');
7788

89+
# Verify that the walreceiver process stayed alive across the timeline
90+
# switch, check its PID.
91+
my $wr_pid_after_switch = $node_standby_2->safe_psql('postgres',
92+
"SELECT pid FROM pg_stat_wal_receiver");
93+
94+
is($wr_pid_before_switch, $wr_pid_after_switch,
95+
'WAL receiver PID matches across timeline jumps');
96+
7897
# Ensure that a standby is able to follow a primary on a newer timeline
7998
# when WAL archiving is enabled.
8099

0 commit comments

Comments
 (0)