tests: fix an unexpected termination of the test script when calling 'query()'

From: aitsygunka(at)yandex(dot)ru
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: tests: fix an unexpected termination of the test script when calling 'query()'
Date: 2025-10-25 15:06:25
Message-ID: 179631761404785@c6b95e96-2317-42aa-a91c-dc436d043ee7
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi

When writing my own test, I discovered that when calling the query() method
after the psql session was terminated for some reason, the test script also
terminates prematurely without returning an error. This occurs when calling
pump_until() to get the stderr stream in query()
(detected on Linux, PostgreSQL 16.9).

Here is a simple reproducer:

use strict;
use warnings;
use Carp;
use PostgreSQL::Test::Cluster;
use PostgreSQL::Test::Utils;
use Test::More;
use Config;

my $node = PostgreSQL::Test::Cluster->new('node');
$node->init();
$node->append_conf( 'postgresql.conf', "idle_session_timeout = '0s'" );
$node->append_conf( 'postgresql.conf', "idle_in_transaction_session_timeout = '1s'" );
$node->start();
my $test->{psql} = $node->background_psql( 'postgres', on_error_stop => 0);
$test->{psql}->query_until(qr//, "begin; select pg_sleep( 3 ); select 'end_of_test';\n");
# Do something
for ( my $i = 0; $i < 3; $i++ ) {
sleep( 1 );
note "Sleep 1 seconds\n";
}
my ($output, $res) = $test->{psql}->query(qq(SELECT 'Is my connection alive?'));
if ($res != 0) {
# Do somthing else
note "Do somthing else\n";
}
$test->{psql}->quit();
$node->stop();

Backtrace:

DB<12> T
@ = DB::DB called from file '/usr/share/perl5/IPC/Run.pm' line 3299
. = IPC::Run::pump_nb(ref(IPC::Run)) called from file '/src/test/perl/PostgreSQL/Test/Utils.pm' line 432
. = PostgreSQL::Test::Utils::pump_until(ref(IPC::Run), ref(IPC::Run::Timer), ref(SCALAR), ref(Regexp)) called from file '/src/test/perl/PostgreSQL/Test/BackgroundPsql.pm' line 272
$ = PostgreSQL::Test::BackgroundPsql::query(ref(PostgreSQL::Test::BackgroundPsql), 'SELECT \'Is my connection alive?\'') called from file './test.pl' line 24
DB<12> p $@
process ended prematurely at /src/test/perl/PostgreSQL/Test/Utils.pm line 432.

To fix this, it is suggested to add a check for the presence of pumped data before
the second call to pump_until() in query() to ensure that the psql process is active.

Thanks for looking.

--
Andrey

Attachment Content-Type Size
0001-tests-fix-an-unexpected-termination-of-the-test-scri.patch text/x-diff 1.3 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Álvaro Herrera 2025-10-25 15:29:25 Re: contrib/sepgsql regression tests have been broken for months
Previous Message Mihail Nikalayeu 2025-10-25 14:55:52 Re: [BUG?] check_exclusion_or_unique_constraint false negative