Hello, Currently, the psql's test of query cancelling (src/bin/psql/t/020_cancel.pl) gets the PPID of a running psql by using "\!" meta command, and sends SIGINT to the process by using "kill". However, IPC::Run provides signal() routine that sends a signal to a running process, so I think we can rewrite the test using this routine to more simple fashion as attached patch.
What do you think about it? Use of signal() is suggested by Fabien COELHO during the discussion of query cancelling of pgbench [1]. [1] https://www.postgresql.org/message-id/7691ade8-78-dd4-e26-135ccfbf0e9%40mines-paristech.fr Regards, Yugo Nagata -- Yugo NAGATA <nag...@sraoss.co.jp>
diff --git a/src/bin/psql/t/020_cancel.pl b/src/bin/psql/t/020_cancel.pl index 0765d82b92..081a1468d9 100644 --- a/src/bin/psql/t/020_cancel.pl +++ b/src/bin/psql/t/020_cancel.pl @@ -29,35 +29,10 @@ SKIP: my ($stdin, $stdout, $stderr); - # Test whether shell supports $PPID. It's part of POSIX, but some - # pre-/non-POSIX shells don't support it (e.g., NetBSD). - $stdin = "\\! echo \$PPID"; - IPC::Run::run([ 'psql', '-X', '-v', 'ON_ERROR_STOP=1' ], - '<', \$stdin, '>', \$stdout, '2>', \$stderr); - $stdout =~ /^\d+$/ or skip "shell apparently does not support \$PPID", 2; - # Now start the real test my $h = IPC::Run::start([ 'psql', '-X', '-v', 'ON_ERROR_STOP=1' ], \$stdin, \$stdout, \$stderr); - # Get the PID - $stdout = ''; - $stderr = ''; - $stdin = "\\! echo \$PPID >$tempdir/psql.pid\n"; - pump $h while length $stdin; - my $count; - my $psql_pid; - until ( - -s "$tempdir/psql.pid" - and ($psql_pid = - PostgreSQL::Test::Utils::slurp_file("$tempdir/psql.pid")) =~ - /^\d+\n/s) - { - ($count++ < 100 * $PostgreSQL::Test::Utils::timeout_default) - or die "pid file did not appear"; - usleep(10_000); - } - # Send sleep command and wait until the server has registered it $stdin = "select pg_sleep($PostgreSQL::Test::Utils::timeout_default);\n"; pump $h while length $stdin; @@ -66,7 +41,7 @@ SKIP: ) or die "timed out"; # Send cancel request - kill 'INT', $psql_pid; + $h->signal('INT'); my $result = finish $h;