Custom connstr in background_psql()

Started by Nonameover 1 year ago4 messages
#1Noname
a.imamov@postgrespro.ru
1 attachment(s)

Hi, hackers!

I've noticed that there is no way to specify a custom connection string
when
calling the PostgreSQL::Test::Cluster->background_psql() method compared
to the
PostgreSQL::Test:Cluster->psql(). It seems useful to have this feature
while
testing with BackgroundPsql, for example, when the default host value
needs to
be overridden to establish different types of connections.

What do you think?

Attachments:

background_psql.patchtext/x-diff; name=background_psql.patchDownload
diff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm b/src/test/perl/PostgreSQL/Test/Cluster.pm
index 143dc8c101..ff0bda0c8d 100644
--- a/src/test/perl/PostgreSQL/Test/Cluster.pm
+++ b/src/test/perl/PostgreSQL/Test/Cluster.pm
@@ -2181,6 +2181,11 @@ returned.  Set B<on_error_stop> to 0 to ignore errors instead.
 Set a timeout for a background psql session. By default, timeout of
 $PostgreSQL::Test::Utils::timeout_default is set up.
 
+=item connstr => B<value>
+
+If set, use this as the connection string for the connection to the
+backend.
+
 =item replication => B<value>
 
 If set, add B<replication=value> to the conninfo string.
@@ -2204,12 +2209,23 @@ sub background_psql
 	my $replication = $params{replication};
 	my $timeout = undef;
 
+	# Build the connection string.
+	my $psql_connstr;
+	if (defined $params{connstr})
+	{
+		$psql_connstr = $params{connstr};
+	}
+	else
+	{
+		$psql_connstr = $self->connstr($dbname);
+	}
+	$psql_connstr .= defined $replication ? " replication=$replication" : "";
+
 	my @psql_params = (
 		$self->installed_command('psql'),
 		'-XAtq',
 		'-d',
-		$self->connstr($dbname)
-		  . (defined $replication ? " replication=$replication" : ""),
+		$psql_connstr,
 		'-f',
 		'-');
 
#2Michael Paquier
michael@paquier.xyz
In reply to: Noname (#1)
Re: Custom connstr in background_psql()

On Wed, Sep 18, 2024 at 01:08:26AM +0300, a.imamov@postgrespro.ru wrote:

I've noticed that there is no way to specify a custom connection string when
calling the PostgreSQL::Test::Cluster->background_psql() method compared to the
PostgreSQL::Test:Cluster->psql(). It seems useful to have this feature while
testing with BackgroundPsql, for example, when the default host value needs
to be overridden to establish different types of connections.

What do you think?

I think that it makes sense to extend the routine as you are
suggesting. At least I can see myself using it depending on the test
suite I am dealing with. So count me in.
--
Michael

#3Noname
a.imamov@postgrespro.ru
In reply to: Michael Paquier (#2)
Re: Custom connstr in background_psql()

Michael Paquier писал(а) 2024-09-18 01:57:

On Wed, Sep 18, 2024 at 01:08:26AM +0300, a.imamov@postgrespro.ru
wrote:

I've noticed that there is no way to specify a custom connection
string when
calling the PostgreSQL::Test::Cluster->background_psql() method
compared to the
PostgreSQL::Test:Cluster->psql(). It seems useful to have this feature
while
testing with BackgroundPsql, for example, when the default host value
needs
to be overridden to establish different types of connections.

What do you think?

I think that it makes sense to extend the routine as you are
suggesting. At least I can see myself using it depending on the test
suite I am dealing with. So count me in.
--
Michael

Should I register the proposal in CF?
Which one to choose if so?

--
regards,
Aidar Imamov

#4Michael Paquier
michael@paquier.xyz
In reply to: Noname (#3)
Re: Custom connstr in background_psql()

On Thu, Sep 19, 2024 at 04:00:30PM +0300, a.imamov@postgrespro.ru wrote:

Should I register the proposal in CF?
Which one to choose if so?

I think that's useful, so I'll just go apply it.
--
Michael