Skip to content

Commit 5b3f471

Browse files
committed
psql: Add test for query canceling
Query canceling in psql was accidentally broken by 3a51306 (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
1 parent 9a6345e commit 5b3f471

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/bin/psql/t/020_cancel.pl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
# Copyright (c) 2021, PostgreSQL Global Development Group
3+
4+
use strict;
5+
use warnings;
6+
7+
use PostgresNode;
8+
use TestLib;
9+
use Test::More tests => 2;
10+
11+
my $tempdir = TestLib::tempdir;
12+
13+
my $node = PostgresNode->new('main');
14+
$node->init;
15+
$node->start;
16+
17+
# Test query canceling by sending SIGINT to a running psql
18+
#
19+
# There is, as of this writing, no documented way to get the PID of
20+
# the process from IPC::Run. As a workaround, we have psql print its
21+
# own PID (which is the parent of the shell launched by psql) to a
22+
# file.
23+
SKIP: {
24+
skip "cancel test requires a Unix shell", 2 if $windows_os;
25+
26+
local %ENV = $node->_get_env();
27+
28+
local $SIG{ALRM} = sub {
29+
my $psql_pid = TestLib::slurp_file("$tempdir/psql.pid");
30+
kill 'INT', $psql_pid;
31+
};
32+
alarm 1;
33+
34+
my $stdin = "\\! echo \$PPID >$tempdir/psql.pid\nselect pg_sleep(3);";
35+
my ($stdout, $stderr);
36+
my $result = IPC::Run::run(['psql', '-X', '-v', 'ON_ERROR_STOP=1'], '<', \$stdin, '>', \$stdout, '2>', \$stderr);
37+
38+
ok(!$result, 'query failed as expected');
39+
like($stderr, qr/canceling statement due to user request/, 'query was canceled');
40+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy