1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-26 12:21:12 +03:00

psql: Improve portability of query cancel test

Some shells apparently don't support $PPID, so skip the test in that
case.
This commit is contained in:
Peter Eisentraut
2021-08-22 18:41:31 +02:00
parent 945f395aeb
commit c818c25f44

View File

@ -25,14 +25,21 @@ SKIP: {
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, Solaris).
$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;
local $SIG{ALRM} = sub {
my $psql_pid = TestLib::slurp_file("$tempdir/psql.pid");
kill 'INT', $psql_pid;
};
alarm 1;
my $stdin = "\\! echo \$PPID >$tempdir/psql.pid\nselect pg_sleep(3);";
my ($stdout, $stderr);
$stdin = "\\! echo \$PPID >$tempdir/psql.pid\nselect pg_sleep(3);";
my $result = IPC::Run::run(['psql', '-X', '-v', 'ON_ERROR_STOP=1'], '<', \$stdin, '>', \$stdout, '2>', \$stderr);
ok(!$result, 'query failed as expected');