diff --git a/src/test/recovery/t/004_timeline_switch.pl b/src/test/recovery/t/004_timeline_switch.pl index a777d8e6a3d..6d7b21ba73d 100644 --- a/src/test/recovery/t/004_timeline_switch.pl +++ b/src/test/recovery/t/004_timeline_switch.pl @@ -7,7 +7,7 @@ use warnings; use File::Path qw(rmtree); use PostgresNode; use TestLib; -use Test::More tests => 4; +use Test::More tests => 5; $ENV{PGDATABASE} = 'postgres'; @@ -58,8 +58,19 @@ $node_standby_2->append_conf( 'postgresql.conf', qq( primary_conninfo='$connstr_1' )); + +# Rotate logfile before restarting, for the log checks done below. +$node_standby_2->rotate_logfile; $node_standby_2->restart; +# Wait for walreceiver to reconnect after the restart. We want to +# verify that after reconnection, the walreceiver stays alive during +# the timeline switch. +$node_standby_2->poll_query_until('postgres', + "SELECT EXISTS(SELECT 1 FROM pg_stat_wal_receiver)"); +my $wr_pid_before_switch = $node_standby_2->safe_psql('postgres', + "SELECT pid FROM pg_stat_wal_receiver"); + # Insert some data in standby 1 and check its presence in standby 2 # to ensure that the timeline switch has been done. $node_standby_1->safe_psql('postgres', @@ -80,6 +91,14 @@ ok( !$node_standby_2->log_contains( ), 'WAL receiver should not be stopped across timeline jumps'); +# Verify that the walreceiver process stayed alive across the timeline +# switch, check its PID. +my $wr_pid_after_switch = $node_standby_2->safe_psql('postgres', + "SELECT pid FROM pg_stat_wal_receiver"); + +is($wr_pid_before_switch, $wr_pid_after_switch, + 'WAL receiver PID matches across timeline jumps'); + # Ensure that a standby is able to follow a primary on a newer timeline # when WAL archiving is enabled.