Skip to content

Commit b062362

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 0f1367c commit b062362

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
@@ -812,6 +812,11 @@ sub start
812812
{
813813
print "# pg_ctl start failed; logfile:\n";
814814
print TestLib::slurp_file($self->logfile);
815+
816+
# pg_ctl could have timed out, so check to see if there's a pid file;
817+
# otherwise our END block will fail to shut down the new postmaster.
818+
$self->_update_pid(-1);
819+
815820
BAIL_OUT("pg_ctl start failed") unless $params{fail_ok};
816821
return 0;
817822
}
@@ -1088,7 +1093,10 @@ archive_command = '$copy_command'
10881093
return;
10891094
}
10901095

1091-
# Internal method
1096+
# Internal method to update $self->{_pid}
1097+
# $is_running = 1: pid file should be there
1098+
# $is_running = 0: pid file should NOT be there
1099+
# $is_running = -1: we aren't sure
10921100
sub _update_pid
10931101
{
10941102
my ($self, $is_running) = @_;
@@ -1103,15 +1111,15 @@ sub _update_pid
11031111
close $pidfile;
11041112

11051113
# If we found a pidfile when there shouldn't be one, complain.
1106-
BAIL_OUT("postmaster.pid unexpectedly present") unless $is_running;
1114+
BAIL_OUT("postmaster.pid unexpectedly present") if $is_running == 0;
11071115
return;
11081116
}
11091117

11101118
$self->{_pid} = undef;
11111119
print "# No postmaster PID for node \"$name\"\n";
11121120

11131121
# Complain if we expected to find a pidfile.
1114-
BAIL_OUT("postmaster.pid unexpectedly not present") if $is_running;
1122+
BAIL_OUT("postmaster.pid unexpectedly not present") if $is_running == 1;
11151123
return;
11161124
}
11171125

0 commit comments

Comments
 (0)