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 522a31a

Browse filesBrowse files
committed
Switch psql's TAP test for query cancellation to use IPC::Run::signal()
Previously, the test relied on a trick with a shell to retrieve the PID of the psql session to be stopped with SIGINT, that was skipped on Windows. This commit changes the test to use IPC::Run::signal() instead, which still does not work on Windows, but for a different reason: SIGINT would stop the test before finishing. This should allow the test to run on non-Windows platforms where PPID is not supported (like NetBSD), spreading it a bit more across the buildfarm. And the logic of the test is simpler. It is the first time in the tree that IPC::Run::signal() is used, so, as a matter of safety (or just call that as me having cold feet), no backpatch is done, at least for now. Author: Yugo NAGATA Reviewed-by: Fabien Coelho Discussion: https://postgr.es/m/20230810125935.22c2922ea5250ba79358965b@sraoss.co.jp
1 parent c53e288 commit 522a31a
Copy full SHA for 522a31a

File tree

Expand file treeCollapse file tree

1 file changed

+2
-36
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+2
-36
lines changed

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

Copy file name to clipboardExpand all lines: src/bin/psql/t/020_cancel.pl
+2-36Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,55 +10,21 @@
1010
use Time::HiRes qw(usleep);
1111

1212
# Test query canceling by sending SIGINT to a running psql
13-
#
14-
# There is, as of this writing, no documented way to get the PID of
15-
# the process from IPC::Run. As a workaround, we have psql print its
16-
# own PID (which is the parent of the shell launched by psql) to a
17-
# file.
1813
if ($windows_os)
1914
{
20-
plan skip_all => "cancel test requires a Unix shell";
15+
plan skip_all => 'sending SIGINT on Windows terminates the test itself';
2116
}
2217

23-
my $tempdir = PostgreSQL::Test::Utils::tempdir;
24-
2518
my $node = PostgreSQL::Test::Cluster->new('main');
2619
$node->init;
2720
$node->start;
2821

2922
local %ENV = $node->_get_env();
3023

3124
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
4125
my $h = IPC::Run::start([ 'psql', '-X', '-v', 'ON_ERROR_STOP=1' ],
4226
\$stdin, \$stdout, \$stderr);
4327

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-
6228
# Send sleep command and wait until the server has registered it
6329
$stdin = "select pg_sleep($PostgreSQL::Test::Utils::timeout_default);\n";
6430
pump $h while length $stdin;
@@ -67,7 +33,7 @@
6733
) or die "timed out";
6834

6935
# Send cancel request
70-
kill 'INT', $psql_pid;
36+
$h->signal('INT');
7137

7238
my $result = finish $h;
7339

0 commit comments

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