Skip to content

Commit 95c3a19

Browse files
committed
Avoid unfortunate IPC::Run path caching in PostgresNode
Commit b34ca59 provided for installation-aware instances of PostgresNode. However, it turns out that IPC::Run works against this by caching the path to a binary and not consulting the path again, even if it has changed. We work around this by calling Postgres binaries with the installed path rather than just a bare name to be looked up in the environment path, if there is an installed path. For the common case where there is no installed path we continue to use the bare command name. Diagnosis and solution from Mark Dilger Discussion: https://postgr.es/m/E8F512F8-B4D6-4514-BA8D-2E671439DA92@enterprisedb.com
1 parent 8b4b566 commit 95c3a19

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

src/test/perl/PostgresNode.pm

+31-5
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,28 @@ sub _get_env
12711271
return (%inst_env);
12721272
}
12731273

1274+
# Private routine to get an installation path qualified command.
1275+
#
1276+
# IPC::Run maintains a cache, %cmd_cache, mapping commands to paths. Tests
1277+
# which use nodes spanning more than one postgres installation path need to
1278+
# avoid confusing which installation's binaries get run. Setting $ENV{PATH} is
1279+
# insufficient, as IPC::Run does not check to see if the path has changed since
1280+
# caching a command.
1281+
sub installed_command
1282+
{
1283+
my ($self, $cmd) = @_;
1284+
1285+
# Nodes using alternate installation locations use their installation's
1286+
# bin/ directory explicitly
1287+
return join('/', $self->{_install_path}, 'bin', $cmd)
1288+
if defined $self->{_install_path};
1289+
1290+
# Nodes implicitly using the default installation location rely on IPC::Run
1291+
# to find the right binary, which should not cause %cmd_cache confusion,
1292+
# because no nodes with other installation paths do it that way.
1293+
return $cmd;
1294+
}
1295+
12741296
=pod
12751297
12761298
=item get_free_port()
@@ -1568,7 +1590,8 @@ sub psql
15681590
}
15691591
$psql_connstr .= defined $replication ? " replication=$replication" : "";
15701592

1571-
my @psql_params = ('psql', '-XAtq', '-d', $psql_connstr, '-f', '-');
1593+
my @psql_params = ($self->installed_command('psql'),
1594+
'-XAtq', '-d', $psql_connstr, '-f', '-');
15721595

15731596
# If the caller wants an array and hasn't passed stdout/stderr
15741597
# references, allocate temporary ones to capture them so we
@@ -1754,7 +1777,7 @@ sub background_psql
17541777
my $replication = $params{replication};
17551778

17561779
my @psql_params = (
1757-
'psql',
1780+
$self->installed_command('psql'),
17581781
'-XAtq',
17591782
'-d',
17601783
$self->connstr($dbname)
@@ -1831,7 +1854,8 @@ sub interactive_psql
18311854

18321855
local %ENV = $self->_get_env();
18331856

1834-
my @psql_params = ('psql', '-XAt', '-d', $self->connstr($dbname));
1857+
my @psql_params = ($self->installed_command('psql'),
1858+
'-XAt', '-d', $self->connstr($dbname));
18351859

18361860
push @psql_params, @{ $params{extra_params} }
18371861
if defined $params{extra_params};
@@ -2041,7 +2065,8 @@ sub poll_query_until
20412065

20422066
$expected = 't' unless defined($expected); # default value
20432067

2044-
my $cmd = [ 'psql', '-XAt', '-c', $query, '-d', $self->connstr($dbname) ];
2068+
my $cmd = [ $self->installed_command('psql'),
2069+
'-XAt', '-c', $query, '-d', $self->connstr($dbname) ];
20452070
my ($stdout, $stderr);
20462071
my $max_attempts = 180 * 10;
20472072
my $attempts = 0;
@@ -2461,7 +2486,8 @@ sub pg_recvlogical_upto
24612486
croak 'endpos must be specified' unless defined($endpos);
24622487

24632488
my @cmd = (
2464-
'pg_recvlogical', '-S', $slot_name, '--dbname',
2489+
$self->installed_command('pg_recvlogical'),
2490+
'-S', $slot_name, '--dbname',
24652491
$self->connstr($dbname));
24662492
push @cmd, '--endpos', $endpos;
24672493
push @cmd, '-f', '-', '--no-loop', '--start';

0 commit comments

Comments
 (0)