mirror of
https://github.com/django/django.git
synced 2025-09-12 13:36:31 +00:00
Fixed #27954 -- Allowed keyboard interrupt to abort queries in PostgreSQL dbshell.
Thanks Tim Martin for review.
This commit is contained in:
parent
7bbb5161ea
commit
66150f7cf6
2 changed files with 21 additions and 0 deletions
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue