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
This commit is contained in:
parent
c53e288dba
commit
522a31ac87
@ -10,18 +10,11 @@ use Test::More;
|
||||
use Time::HiRes qw(usleep);
|
||||
|
||||
# Test query canceling by sending SIGINT to a running psql
|
||||
#
|
||||
# There is, as of this writing, no documented way to get the PID of
|
||||
# the process from IPC::Run. As a workaround, we have psql print its
|
||||
# own PID (which is the parent of the shell launched by psql) to a
|
||||
# file.
|
||||
if ($windows_os)
|
||||
{
|
||||
plan skip_all => "cancel test requires a Unix shell";
|
||||
plan skip_all => 'sending SIGINT on Windows terminates the test itself';
|
||||
}
|
||||
|
||||
my $tempdir = PostgreSQL::Test::Utils::tempdir;
|
||||
|
||||
my $node = PostgreSQL::Test::Cluster->new('main');
|
||||
$node->init;
|
||||
$node->start;
|
||||
@ -29,36 +22,9 @@ $node->start;
|
||||
local %ENV = $node->_get_env();
|
||||
|
||||
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;
|
||||
@ -67,7 +33,7 @@ $node->poll_query_until('postgres',
|
||||
) or die "timed out";
|
||||
|
||||
# Send cancel request
|
||||
kill 'INT', $psql_pid;
|
||||
$h->signal('INT');
|
||||
|
||||
my $result = finish $h;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user