Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6c4a890

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 f201da3 commit 6c4a890

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/test/perl/PostgreSQL/Test/Cluster.pm

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,11 @@ sub start
845845
{
846846
print "# pg_ctl start failed; logfile:\n";
847847
print PostgreSQL::Test::Utils::slurp_file($self->logfile);
848+
849+
# pg_ctl could have timed out, so check to see if there's a pid file;
850+
# otherwise our END block will fail to shut down the new postmaster.
851+
$self->_update_pid(-1);
852+
848853
BAIL_OUT("pg_ctl start failed") unless $params{fail_ok};
849854
return 0;
850855
}
@@ -1123,7 +1128,10 @@ archive_command = '$copy_command'
11231128
return;
11241129
}
11251130

1126-
# Internal method
1131+
# Internal method to update $self->{_pid}
1132+
# $is_running = 1: pid file should be there
1133+
# $is_running = 0: pid file should NOT be there
1134+
# $is_running = -1: we aren't sure
11271135
sub _update_pid
11281136
{
11291137
my ($self, $is_running) = @_;
@@ -1138,15 +1146,15 @@ sub _update_pid
11381146
close $pidfile;
11391147

11401148
# If we found a pidfile when there shouldn't be one, complain.
1141-
BAIL_OUT("postmaster.pid unexpectedly present") unless $is_running;
1149+
BAIL_OUT("postmaster.pid unexpectedly present") if $is_running == 0;
11421150
return;
11431151
}
11441152

11451153
$self->{_pid} = undef;
11461154
print "# No postmaster PID for node \"$name\"\n";
11471155

11481156
# Complain if we expected to find a pidfile.
1149-
BAIL_OUT("postmaster.pid unexpectedly not present") if $is_running;
1157+
BAIL_OUT("postmaster.pid unexpectedly not present") if $is_running == 1;
11501158
return;
11511159
}
11521160

0 commit comments

Comments
 (0)