2 # Copyright (c) 2021-2025, PostgreSQL Global Development Group
5 use warnings FATAL
=> 'all';
7 use PostgreSQL
::Test
::Cluster
;
8 use PostgreSQL
::Test
::Utils
;
10 use Time
::HiRes
qw(usleep);
12 # Test query canceling by sending SIGINT to a running psql
15 plan skip_all
=> 'sending SIGINT on Windows terminates the test itself';
18 my $node = PostgreSQL
::Test
::Cluster
->new('main');
22 local %ENV = $node->_get_env();
24 my ($stdin, $stdout, $stderr);
25 my $h = IPC
::Run
::start
([ 'psql', '-X', '-v', 'ON_ERROR_STOP=1' ],
26 \
$stdin, \
$stdout, \
$stderr);
28 # Send sleep command and wait until the server has registered it
29 $stdin = "select pg_sleep($PostgreSQL::Test::Utils::timeout_default);\n";
30 pump
$h while length $stdin;
31 $node->poll_query_until('postgres',
32 q{SELECT (SELECT count(*) FROM pg_stat_activity WHERE query ~ '^select pg_sleep') > 0;}
38 my $result = finish
$h;
40 ok
(!$result, 'query failed as expected');
43 qr/canceling statement due to user request/,
44 'query was canceled');