summaryrefslogtreecommitdiff
path: root/tests/dbshell
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2022-05-20 07:11:51 +0200
committerGitHub <noreply@github.com>2022-05-20 07:11:51 +0200
commit1a78ef2b85467a18ea6d7eaa4b27f67d11c87b9e (patch)
treea09504d830f8102004e3ab6828efd5892f160429 /tests/dbshell
parente89f9571352f42c7752b351ba1e651485e5e7c51 (diff)
Fixed #33715 -- Allowed keyboard interrupt to abort queries in MySQL dbshell.
Diffstat (limited to 'tests/dbshell')
-rw-r--r--tests/dbshell/test_mysql.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/dbshell/test_mysql.py b/tests/dbshell/test_mysql.py
index 28410b05e1..13007ec037 100644
--- a/tests/dbshell/test_mysql.py
+++ b/tests/dbshell/test_mysql.py
@@ -1,8 +1,11 @@
import os
+import signal
import subprocess
import sys
from pathlib import Path
+from unittest import mock, skipUnless
+from django.db import connection
from django.db.backends.mysql.client import DatabaseClient
from django.test import SimpleTestCase
@@ -218,3 +221,19 @@ class MySqlDbshellCommandTestCase(SimpleTestCase):
with self.assertRaises(subprocess.CalledProcessError) as ctx:
subprocess.run(args, check=True, env=env)
self.assertNotIn("somepassword", str(ctx.exception))
+
+ @skipUnless(connection.vendor == "mysql", "Requires a MySQL connection")
+ def test_sigint_handler(self):
+ """SIGINT is ignored in Python and passed to mysql to abort queries."""
+
+ def _mock_subprocess_run(*args, **kwargs):
+ 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.run", new=_mock_subprocess_run):
+ connection.client.runshell([])
+ # dbshell restores the original handler.
+ self.assertEqual(sigint_handler, signal.getsignal(signal.SIGINT))