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

Commit 334f512

Browse files
Add option to specify timeout seconds to BackgroundPsql.pm.
Previously, a background psql session uses the default timeout and it cannot be overridden. This change adds a new option to set the timeout during start. There are no users of this new option. It is needed for an upcoming patch adding tests for XID wraparound. Reviewed-by: Daniel Gustafsson, Noah Misch Discussion: https://postgr.es/m/C9CF2F76-0D81-4C9D-9832-202BE8517056%40yesql.se
1 parent a182756 commit 334f512

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use Test::More;
6868
6969
=over
7070
71-
=item PostgreSQL::Test::BackgroundPsql->new(interactive, @params)
71+
=item PostgreSQL::Test::BackgroundPsql->new(interactive, @psql_params, timeout)
7272
7373
Builds a new object of class C<PostgreSQL::Test::BackgroundPsql> for either
7474
an interactive or background session and starts it. If C<interactive> is
@@ -81,7 +81,7 @@ string. For C<interactive> sessions, IO::Pty is required.
8181
sub new
8282
{
8383
my $class = shift;
84-
my ($interactive, $psql_params) = @_;
84+
my ($interactive, $psql_params, $timeout) = @_;
8585
my $psql = {
8686
'stdin' => '',
8787
'stdout' => '',
@@ -96,8 +96,10 @@ sub new
9696
"Forbidden caller of constructor: package: $package, file: $file:$line"
9797
unless $package->isa('PostgreSQL::Test::Cluster');
9898

99-
$psql->{timeout} =
100-
IPC::Run::timeout($PostgreSQL::Test::Utils::timeout_default);
99+
$psql->{timeout} = IPC::Run::timeout(
100+
defined($timeout)
101+
? $timeout
102+
: $PostgreSQL::Test::Utils::timeout_default);
101103

102104
if ($interactive)
103105
{

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -2028,8 +2028,6 @@ sub psql
20282028
20292029
Invoke B<psql> on B<$dbname> and return a BackgroundPsql object.
20302030
2031-
A timeout of $PostgreSQL::Test::Utils::timeout_default is set up.
2032-
20332031
psql is invoked in tuples-only unaligned mode with reading of B<.psqlrc>
20342032
disabled. That may be overridden by passing extra psql parameters.
20352033
@@ -2047,6 +2045,11 @@ By default, the B<psql> method invokes the B<psql> program with ON_ERROR_STOP=1
20472045
set, so SQL execution is stopped at the first error and exit code 3 is
20482046
returned. Set B<on_error_stop> to 0 to ignore errors instead.
20492047
2048+
=item timeout => 'interval'
2049+
2050+
Set a timeout for a background psql session. By default, timeout of
2051+
$PostgreSQL::Test::Utils::timeout_default is set up.
2052+
20502053
=item replication => B<value>
20512054
20522055
If set, add B<replication=value> to the conninfo string.
@@ -2068,6 +2071,7 @@ sub background_psql
20682071
local %ENV = $self->_get_env();
20692072

20702073
my $replication = $params{replication};
2074+
my $timeout = undef;
20712075

20722076
my @psql_params = (
20732077
$self->installed_command('psql'),
@@ -2079,12 +2083,13 @@ sub background_psql
20792083
'-');
20802084

20812085
$params{on_error_stop} = 1 unless defined $params{on_error_stop};
2086+
$timeout = $params{timeout} if defined $params{timeout};
20822087

20832088
push @psql_params, '-v', 'ON_ERROR_STOP=1' if $params{on_error_stop};
20842089
push @psql_params, @{ $params{extra_params} }
20852090
if defined $params{extra_params};
20862091

2087-
return PostgreSQL::Test::BackgroundPsql->new(0, \@psql_params);
2092+
return PostgreSQL::Test::BackgroundPsql->new(0, \@psql_params, $timeout);
20882093
}
20892094

20902095
=pod

0 commit comments

Comments
 (0)