Skip to content

Commit 6eec809

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 3204b8a commit 6eec809

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
@@ -783,6 +783,11 @@ sub start
783783
{
784784
print "# pg_ctl start failed; logfile:\n";
785785
print TestLib::slurp_file($self->logfile);
786+
787+
# pg_ctl could have timed out, so check to see if there's a pid file;
788+
# otherwise our END block will fail to shut down the new postmaster.
789+
$self->_update_pid(-1);
790+
786791
BAIL_OUT("pg_ctl start failed") unless $params{fail_ok};
787792
return 0;
788793
}
@@ -1047,7 +1052,10 @@ archive_command = '$copy_command'
10471052
return;
10481053
}
10491054

1050-
# Internal method
1055+
# Internal method to update $self->{_pid}
1056+
# $is_running = 1: pid file should be there
1057+
# $is_running = 0: pid file should NOT be there
1058+
# $is_running = -1: we aren't sure
10511059
sub _update_pid
10521060
{
10531061
my ($self, $is_running) = @_;
@@ -1062,15 +1070,15 @@ sub _update_pid
10621070
close $pidfile;
10631071

10641072
# If we found a pidfile when there shouldn't be one, complain.
1065-
BAIL_OUT("postmaster.pid unexpectedly present") unless $is_running;
1073+
BAIL_OUT("postmaster.pid unexpectedly present") if $is_running == 0;
10661074
return;
10671075
}
10681076

10691077
$self->{_pid} = undef;
10701078
print "# No postmaster PID for node \"$name\"\n";
10711079

10721080
# Complain if we expected to find a pidfile.
1073-
BAIL_OUT("postmaster.pid unexpectedly not present") if $is_running;
1081+
BAIL_OUT("postmaster.pid unexpectedly not present") if $is_running == 1;
10741082
return;
10751083
}
10761084

0 commit comments

Comments
 (0)