Add error pattern checks for some TAP tests for non-existing objects
[pgsql.git] / src / bin / psql / t / 020_cancel.pl
bloba40f86293f2f382e41bbd5ad22bdf7e43fb7eb9c
2 # Copyright (c) 2021-2025, PostgreSQL Global Development Group
4 use strict;
5 use warnings FATAL => 'all';
7 use PostgreSQL::Test::Cluster;
8 use PostgreSQL::Test::Utils;
9 use Test::More;
10 use Time::HiRes qw(usleep);
12 # Test query canceling by sending SIGINT to a running psql
13 if ($windows_os)
15 plan skip_all => 'sending SIGINT on Windows terminates the test itself';
18 my $node = PostgreSQL::Test::Cluster->new('main');
19 $node->init;
20 $node->start;
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;}
33 ) or die "timed out";
35 # Send cancel request
36 $h->signal('INT');
38 my $result = finish $h;
40 ok(!$result, 'query failed as expected');
41 like(
42 $stderr,
43 qr/canceling statement due to user request/,
44 'query was canceled');
46 done_testing();