Skip to content

Commit d35e293

Browse files
committed
Add parameter "connstr" to PostgreSQL::Test::Cluster::background_psql
Like for Cluster::psql, this can be handy to force the use of a connection string with some values overriden, like a "host". Author: Aidar Imamov Discussion: https://postgr.es/m/ecacb079efc533aed3c234cbcb5b07b6@postgrespro.ru
1 parent 126ec0b commit d35e293

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,6 +2181,11 @@ returned. Set B<on_error_stop> to 0 to ignore errors instead.
21812181
Set a timeout for a background psql session. By default, timeout of
21822182
$PostgreSQL::Test::Utils::timeout_default is set up.
21832183
2184+
=item connstr => B<value>
2185+
2186+
If set, use this as the connection string for the connection to the
2187+
backend.
2188+
21842189
=item replication => B<value>
21852190
21862191
If set, add B<replication=value> to the conninfo string.
@@ -2204,14 +2209,21 @@ sub background_psql
22042209
my $replication = $params{replication};
22052210
my $timeout = undef;
22062211

2212+
# Build the connection string.
2213+
my $psql_connstr;
2214+
if (defined $params{connstr})
2215+
{
2216+
$psql_connstr = $params{connstr};
2217+
}
2218+
else
2219+
{
2220+
$psql_connstr = $self->connstr($dbname);
2221+
}
2222+
$psql_connstr .= defined $replication ? " replication=$replication" : "";
2223+
22072224
my @psql_params = (
22082225
$self->installed_command('psql'),
2209-
'-XAtq',
2210-
'-d',
2211-
$self->connstr($dbname)
2212-
. (defined $replication ? " replication=$replication" : ""),
2213-
'-f',
2214-
'-');
2226+
'-XAtq', '-d', $psql_connstr, '-f', '-');
22152227

22162228
$params{on_error_stop} = 1 unless defined $params{on_error_stop};
22172229
$timeout = $params{timeout} if defined $params{timeout};

0 commit comments

Comments
 (0)