mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
psql: Add test for query canceling
Query canceling in psql was accidentally broken by
3a51306722
(since reverted), so having
some test coverage for that seems useful.
Reviewed-by: Fabien COELHO <coelho@cri.ensmp.fr>
Discussion: https://www.postgresql.org/message-id/18c78a01-4a34-9dd4-f78b-6860f1420c8e@enterprisedb.com
This commit is contained in:
40
src/bin/psql/t/020_cancel.pl
Normal file
40
src/bin/psql/t/020_cancel.pl
Normal file
@ -0,0 +1,40 @@
|
||||
|
||||
# Copyright (c) 2021, PostgreSQL Global Development Group
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use PostgresNode;
|
||||
use TestLib;
|
||||
use Test::More tests => 2;
|
||||
|
||||
my $tempdir = TestLib::tempdir;
|
||||
|
||||
my $node = PostgresNode->new('main');
|
||||
$node->init;
|
||||
$node->start;
|
||||
|
||||
# Test query canceling by sending SIGINT to a running psql
|
||||
#
|
||||
# There is, as of this writing, no documented way to get the PID of
|
||||
# the process from IPC::Run. As a workaround, we have psql print its
|
||||
# own PID (which is the parent of the shell launched by psql) to a
|
||||
# file.
|
||||
SKIP: {
|
||||
skip "cancel test requires a Unix shell", 2 if $windows_os;
|
||||
|
||||
local %ENV = $node->_get_env();
|
||||
|
||||
local $SIG{ALRM} = sub {
|
||||
my $psql_pid = TestLib::slurp_file("$tempdir/psql.pid");
|
||||
kill 'INT', $psql_pid;
|
||||
};
|
||||
alarm 1;
|
||||
|
||||
my $stdin = "\\! echo \$PPID >$tempdir/psql.pid\nselect pg_sleep(3);";
|
||||
my ($stdout, $stderr);
|
||||
my $result = IPC::Run::run(['psql', '-X', '-v', 'ON_ERROR_STOP=1'], '<', \$stdin, '>', \$stdout, '2>', \$stderr);
|
||||
|
||||
ok(!$result, 'query failed as expected');
|
||||
like($stderr, qr/canceling statement due to user request/, 'query was canceled');
|
||||
}
|
Reference in New Issue
Block a user