Skip to content

Commit 99aa0ff

Browse files
committed
TAP tests: check for postmaster.pid anyway when "pg_ctl start" fails.
"pg_ctl start" might start a new postmaster and then return failure anyway, for example if PGCTLTIMEOUT is exceeded. If there is a postmaster there, it's still incumbent on us to shut it down at script end, so check for the PID file even though we are about to fail. This has been broken all along, so back-patch to all supported branches. Discussion: https://postgr.es/m/647439.1642622744@sss.pgh.pa.us
1 parent d696e63 commit 99aa0ff

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/test/perl/PostgresNode.pm

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,11 @@ sub start
774774
{
775775
print "# pg_ctl start failed; logfile:\n";
776776
print TestLib::slurp_file($self->logfile);
777+
778+
# pg_ctl could have timed out, so check to see if there's a pid file;
779+
# otherwise our END block will fail to shut down the new postmaster.
780+
$self->_update_pid(-1);
781+
777782
BAIL_OUT("pg_ctl start failed") unless $params{fail_ok};
778783
return 0;
779784
}
@@ -970,7 +975,10 @@ archive_command = '$copy_command'
970975
return;
971976
}
972977

973-
# Internal method
978+
# Internal method to update $self->{_pid}
979+
# $is_running = 1: pid file should be there
980+
# $is_running = 0: pid file should NOT be there
981+
# $is_running = -1: we aren't sure
974982
sub _update_pid
975983
{
976984
my ($self, $is_running) = @_;
@@ -985,15 +993,15 @@ sub _update_pid
985993
close $pidfile;
986994

987995
# If we found a pidfile when there shouldn't be one, complain.
988-
BAIL_OUT("postmaster.pid unexpectedly present") unless $is_running;
996+
BAIL_OUT("postmaster.pid unexpectedly present") if $is_running == 0;
989997
return;
990998
}
991999

9921000
$self->{_pid} = undef;
9931001
print "# No postmaster PID for node \"$name\"\n";
9941002

9951003
# Complain if we expected to find a pidfile.
996-
BAIL_OUT("postmaster.pid unexpectedly not present") if $is_running;
1004+
BAIL_OUT("postmaster.pid unexpectedly not present") if $is_running == 1;
9971005
return;
9981006
}
9991007

0 commit comments

Comments
 (0)