aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2021-08-20 11:28:56 +0200
committerPeter Eisentraut <peter@eisentraut.org>2021-08-20 11:38:16 +0200
commit5b3f471ff23a2773e6c1ee1704377581c987107d (patch)
tree2bced886eb757f4ea551d0f1ec448ac0491d28b4 /src
parent9a6345ed741783e8770ef160e822d2257873adef (diff)
downloadpostgresql-5b3f471ff23a2773e6c1ee1704377581c987107d.tar.gz
postgresql-5b3f471ff23a2773e6c1ee1704377581c987107d.zip
psql: Add test for query canceling
Query canceling in psql was accidentally broken by 3a5130672296ed4e682403a77a9a3ad3d21cef75 (since reverted), so having some test coverage for that seems useful. Reviewed-by: Fabien COELHO <coelho@cri.ensmp.fr> Discussion: https://www.postgresql.org/message-id/18c78a01-4a34-9dd4-f78b-6860f1420c8e@enterprisedb.com
Diffstat (limited to 'src')
-rw-r--r--src/bin/psql/t/020_cancel.pl40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/bin/psql/t/020_cancel.pl b/src/bin/psql/t/020_cancel.pl
new file mode 100644
index 00000000000..60b6d1f5445
--- /dev/null
+++ b/src/bin/psql/t/020_cancel.pl
@@ -0,0 +1,40 @@
+
+# Copyright (c) 2021, PostgreSQL Global Development Group
+
+use strict;
+use warnings;
+
+use PostgresNode;
+use TestLib;
+use Test::More tests => 2;
+
+my $tempdir = TestLib::tempdir;
+
+my $node = PostgresNode->new('main');
+$node->init;
+$node->start;
+
+# 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.
+SKIP: {
+ skip "cancel test requires a Unix shell", 2 if $windows_os;
+
+ local %ENV = $node->_get_env();
+
+ 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);
+ my $result = IPC::Run::run(['psql', '-X', '-v', 'ON_ERROR_STOP=1'], '<', \$stdin, '>', \$stdout, '2>', \$stderr);
+
+ ok(!$result, 'query failed as expected');
+ like($stderr, qr/canceling statement due to user request/, 'query was canceled');
+}