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

Поиск
Список
Период
Сортировка
От aitsygunka@yandex.ru
Тема tests: fix an unexpected termination of the test script when calling 'query()'
Дата
Msg-id 179631761404785@c6b95e96-2317-42aa-a91c-dc436d043ee7
обсуждение исходный текст
Список 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
Вложения

В списке pgsql-hackers по дате отправления: