|
10 | 10 | use Time::HiRes qw(usleep); |
11 | 11 |
|
12 | 12 | # 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. |
18 | 13 | if ($windows_os) |
19 | 14 | { |
20 | | - plan skip_all => "cancel test requires a Unix shell"; |
| 15 | + plan skip_all => 'sending SIGINT on Windows terminates the test itself'; |
21 | 16 | } |
22 | 17 |
|
23 | | -my $tempdir = PostgreSQL::Test::Utils::tempdir; |
24 | | - |
25 | 18 | my $node = PostgreSQL::Test::Cluster->new('main'); |
26 | 19 | $node->init; |
27 | 20 | $node->start; |
28 | 21 |
|
29 | 22 | local %ENV = $node->_get_env(); |
30 | 23 |
|
31 | 24 | 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 | 25 | my $h = IPC::Run::start([ 'psql', '-X', '-v', 'ON_ERROR_STOP=1' ], |
42 | 26 | \$stdin, \$stdout, \$stderr); |
43 | 27 |
|
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 | 28 | # Send sleep command and wait until the server has registered it |
63 | 29 | $stdin = "select pg_sleep($PostgreSQL::Test::Utils::timeout_default);\n"; |
64 | 30 | pump $h while length $stdin; |
|
67 | 33 | ) or die "timed out"; |
68 | 34 |
|
69 | 35 | # Send cancel request |
70 | | -kill 'INT', $psql_pid; |
| 36 | +$h->signal('INT'); |
71 | 37 |
|
72 | 38 | my $result = finish $h; |
73 | 39 |
|
|
0 commit comments