Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c53e288

Browse filesBrowse files
committed
Skip psql's TAP test for query cancellation entirely on Windows
This changes 020_cancel.pl so as the test is entirely skipped on Windows. This test was already doing nothing under WIN32, except initializing and starting a node without using it so this shaves a few test cycles. Author: Yugo NAGATA Reviewed-by: Fabien Coelho Discussion: https://postgr.es/m/20230810125935.22c2922ea5250ba79358965b@sraoss.co.jp Backpatch-through: 15
1 parent e434e21 commit c53e288
Copy full SHA for c53e288

File tree

Expand file treeCollapse file tree

1 file changed

+59
-59
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+59
-59
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: src/bin/psql/t/020_cancel.pl
+59-59Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9,72 +9,72 @@
99
use Test::More;
1010
use Time::HiRes qw(usleep);
1111

12-
my $tempdir = PostgreSQL::Test::Utils::tempdir;
13-
14-
my $node = PostgreSQL::Test::Cluster->new('main');
15-
$node->init;
16-
$node->start;
17-
1812
# Test query canceling by sending SIGINT to a running psql
1913
#
2014
# There is, as of this writing, no documented way to get the PID of
2115
# the process from IPC::Run. As a workaround, we have psql print its
2216
# own PID (which is the parent of the shell launched by psql) to a
2317
# file.
24-
SKIP:
18+
if ($windows_os)
2519
{
26-
skip "cancel test requires a Unix shell", 2 if $windows_os;
27-
28-
local %ENV = $node->_get_env();
29-
30-
my ($stdin, $stdout, $stderr);
31-
32-
# Test whether shell supports $PPID. It's part of POSIX, but some
33-
# pre-/non-POSIX shells don't support it (e.g., NetBSD).
34-
$stdin = "\\! echo \$PPID";
35-
IPC::Run::run([ 'psql', '-X', '-v', 'ON_ERROR_STOP=1' ],
36-
'<', \$stdin, '>', \$stdout, '2>', \$stderr);
37-
$stdout =~ /^\d+$/ or skip "shell apparently does not support \$PPID", 2;
38-
39-
# Now start the real test
40-
my $h = IPC::Run::start([ 'psql', '-X', '-v', 'ON_ERROR_STOP=1' ],
41-
\$stdin, \$stdout, \$stderr);
42-
43-
# Get the PID
44-
$stdout = '';
45-
$stderr = '';
46-
$stdin = "\\! echo \$PPID >$tempdir/psql.pid\n";
47-
pump $h while length $stdin;
48-
my $count;
49-
my $psql_pid;
50-
until (
51-
-s "$tempdir/psql.pid"
52-
and ($psql_pid =
53-
PostgreSQL::Test::Utils::slurp_file("$tempdir/psql.pid")) =~
54-
/^\d+\n/s)
55-
{
56-
($count++ < 100 * $PostgreSQL::Test::Utils::timeout_default)
57-
or die "pid file did not appear";
58-
usleep(10_000);
59-
}
60-
61-
# Send sleep command and wait until the server has registered it
62-
$stdin = "select pg_sleep($PostgreSQL::Test::Utils::timeout_default);\n";
63-
pump $h while length $stdin;
64-
$node->poll_query_until('postgres',
65-
q{SELECT (SELECT count(*) FROM pg_stat_activity WHERE query ~ '^select pg_sleep') > 0;}
66-
) or die "timed out";
67-
68-
# Send cancel request
69-
kill 'INT', $psql_pid;
70-
71-
my $result = finish $h;
72-
73-
ok(!$result, 'query failed as expected');
74-
like(
75-
$stderr,
76-
qr/canceling statement due to user request/,
77-
'query was canceled');
20+
plan skip_all => "cancel test requires a Unix shell";
7821
}
7922

23+
my $tempdir = PostgreSQL::Test::Utils::tempdir;
24+
25+
my $node = PostgreSQL::Test::Cluster->new('main');
26+
$node->init;
27+
$node->start;
28+
29+
local %ENV = $node->_get_env();
30+
31+
my ($stdin, $stdout, $stderr);
32+
33+
# Test whether shell supports $PPID. It's part of POSIX, but some
34+
# pre-/non-POSIX shells don't support it (e.g., NetBSD).
35+
$stdin = "\\! echo \$PPID";
36+
IPC::Run::run([ 'psql', '-X', '-v', 'ON_ERROR_STOP=1' ],
37+
'<', \$stdin, '>', \$stdout, '2>', \$stderr);
38+
$stdout =~ /^\d+$/ or skip "shell apparently does not support \$PPID", 2;
39+
40+
# Now start the real test
41+
my $h = IPC::Run::start([ 'psql', '-X', '-v', 'ON_ERROR_STOP=1' ],
42+
\$stdin, \$stdout, \$stderr);
43+
44+
# Get the PID
45+
$stdout = '';
46+
$stderr = '';
47+
$stdin = "\\! echo \$PPID >$tempdir/psql.pid\n";
48+
pump $h while length $stdin;
49+
my $count;
50+
my $psql_pid;
51+
until (
52+
-s "$tempdir/psql.pid"
53+
and
54+
($psql_pid = PostgreSQL::Test::Utils::slurp_file("$tempdir/psql.pid"))
55+
=~ /^\d+\n/s)
56+
{
57+
($count++ < 100 * $PostgreSQL::Test::Utils::timeout_default)
58+
or die "pid file did not appear";
59+
usleep(10_000);
60+
}
61+
62+
# Send sleep command and wait until the server has registered it
63+
$stdin = "select pg_sleep($PostgreSQL::Test::Utils::timeout_default);\n";
64+
pump $h while length $stdin;
65+
$node->poll_query_until('postgres',
66+
q{SELECT (SELECT count(*) FROM pg_stat_activity WHERE query ~ '^select pg_sleep') > 0;}
67+
) or die "timed out";
68+
69+
# Send cancel request
70+
kill 'INT', $psql_pid;
71+
72+
my $result = finish $h;
73+
74+
ok(!$result, 'query failed as expected');
75+
like(
76+
$stderr,
77+
qr/canceling statement due to user request/,
78+
'query was canceled');
79+
8080
done_testing();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.