Add option to specify timeout seconds to BackgroundPsql.pm.
authorMasahiko Sawada
Thu, 30 Nov 2023 05:08:34 +0000 (14:08 +0900)
committerMasahiko Sawada
Thu, 30 Nov 2023 05:08:34 +0000 (14:08 +0900)
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

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

index 764f0a538017d13b7fccad105210635d9ebf35de..bae452ac9c1d62ca9cd708d28e2229603837e4da 100644 (file)
@@ -68,7 +68,7 @@ use Test::More;
 
 =over
 
-=item PostgreSQL::Test::BackgroundPsql->new(interactive, @params)
+=item PostgreSQL::Test::BackgroundPsql->new(interactive, @psql_params, timeout)
 
 Builds a new object of class C for either
 an interactive or background session and starts it. If C is
@@ -81,7 +81,7 @@ string. For C sessions, IO::Pty is required.
 sub new
 {
    my $class = shift;
-   my ($interactive, $psql_params) = @_;
+   my ($interactive, $psql_params, $timeout) = @_;
    my $psql = {
        'stdin' => '',
        'stdout' => '',
@@ -96,8 +96,10 @@ sub new
      "Forbidden caller of constructor: package: $package, file: $file:$line"
      unless $package->isa('PostgreSQL::Test::Cluster');
 
-   $psql->{timeout} =
-     IPC::Run::timeout($PostgreSQL::Test::Utils::timeout_default);
+   $psql->{timeout} = IPC::Run::timeout(
+       defined($timeout)
+       ? $timeout
+       : $PostgreSQL::Test::Utils::timeout_default);
 
    if ($interactive)
    {
index 321b77d7ed2ed8c3299c34ed3374bfb6d5447eab..a020377761dff1fa9aa987f75b1b45ffe5d8e335 100644 (file)
@@ -2028,8 +2028,6 @@ sub psql
 
 Invoke B on B<$dbname> and return a BackgroundPsql object.
 
-A timeout of $PostgreSQL::Test::Utils::timeout_default is set up.
-
 psql is invoked in tuples-only unaligned mode with reading of B<.psqlrc>
 disabled.  That may be overridden by passing extra psql parameters.
 
@@ -2047,6 +2045,11 @@ By default, the B method invokes the B program with ON_ERROR_STOP=1
 set, so SQL execution is stopped at the first error and exit code 3 is
 returned.  Set B to 0 to ignore errors instead.
 
+=item timeout => 'interval'
+
+Set a timeout for a background psql session. By default, timeout of
+$PostgreSQL::Test::Utils::timeout_default is set up.
+
 =item replication => B
 
 If set, add B to the conninfo string.
@@ -2068,6 +2071,7 @@ sub background_psql
    local %ENV = $self->_get_env();
 
    my $replication = $params{replication};
+   my $timeout = undef;
 
    my @psql_params = (
        $self->installed_command('psql'),
@@ -2079,12 +2083,13 @@ sub background_psql
        '-');
 
    $params{on_error_stop} = 1 unless defined $params{on_error_stop};
+   $timeout = $params{timeout} if defined $params{timeout};
 
    push @psql_params, '-v', 'ON_ERROR_STOP=1' if $params{on_error_stop};
    push @psql_params, @{ $params{extra_params} }
      if defined $params{extra_params};
 
-   return PostgreSQL::Test::BackgroundPsql->new(0, \@psql_params);
+   return PostgreSQL::Test::BackgroundPsql->new(0, \@psql_params, $timeout);
 }
 
 =pod