diff options
| author | Chris Sinchok <chris@sinchok.com> | 2017-04-01 20:01:08 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-04-01 21:01:08 -0400 |
| commit | 66150f7cf61bc09547fa98586790df596eff6d77 (patch) | |
| tree | 231233c290ab6d51ef123a1f9dc2033be24fe5d8 /tests/dbshell | |
| parent | 7bbb5161eaad6771676281c5c544030cf9ff1312 (diff) | |
Fixed #27954 -- Allowed keyboard interrupt to abort queries in PostgreSQL dbshell.
Thanks Tim Martin for review.
Diffstat (limited to 'tests/dbshell')
| -rw-r--r-- | tests/dbshell/test_postgresql_psycopg2.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/dbshell/test_postgresql_psycopg2.py b/tests/dbshell/test_postgresql_psycopg2.py index 26090fb7f1..a229e13a47 100644 --- a/tests/dbshell/test_postgresql_psycopg2.py +++ b/tests/dbshell/test_postgresql_psycopg2.py @@ -1,4 +1,5 @@ import os +import signal from unittest import mock from django.db.backends.postgresql.client import DatabaseClient @@ -99,3 +100,17 @@ class PostgreSqlDbshellCommandTestCase(SimpleTestCase): pgpass_string, ) ) + + def test_sigint_handler(self): + """SIGINT is ignored in Python and passed to psql to abort quries.""" + def _mock_subprocess_call(*args): + handler = signal.getsignal(signal.SIGINT) + self.assertEqual(handler, signal.SIG_IGN) + + sigint_handler = signal.getsignal(signal.SIGINT) + # The default handler isn't SIG_IGN. + self.assertNotEqual(sigint_handler, signal.SIG_IGN) + with mock.patch('subprocess.check_call', new=_mock_subprocess_call): + DatabaseClient.runshell_db({}) + # dbshell restores the orignal handler. + self.assertEqual(sigint_handler, signal.getsignal(signal.SIGINT)) |
