aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_asyncio/test_unix_events.py
diff options
context:
space:
mode:
authorMichel Hidalgo <michel@ekumenlabs.com>2022-09-17 12:07:54 -0300
committerGitHub <noreply@github.com>2022-09-17 08:07:54 -0700
commit05878106989c6f5b9dd35a6c15a21bee59312827 (patch)
tree8d58f02a0cc3e14d4983106033a5d97e4cd49bf1 /Lib/test/test_asyncio/test_unix_events.py
parent2cd70ffb3fe22d778d0bb6ec220fdf67dccc1be6 (diff)
downloadcpython-05878106989c6f5b9dd35a6c15a21bee59312827.tar.gz
cpython-05878106989c6f5b9dd35a6c15a21bee59312827.zip
gh-87079: Warn on unintended signal wakeup fd override in `asyncio` (#96807)
Warn on loop initialization, when setting the wakeup fd disturbs a previously set wakeup fd, and on loop closing, when upon resetting the wakeup fd, we find it has been changed by someone else.
Diffstat (limited to 'Lib/test/test_asyncio/test_unix_events.py')
-rw-r--r--Lib/test/test_asyncio/test_unix_events.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index 5bad21ecbae..1ec627f63ee 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -89,6 +89,17 @@ class SelectorEventLoopSignalTests(test_utils.TestCase):
signal.SIGINT, lambda: True)
@mock.patch('asyncio.unix_events.signal')
+ def test_add_signal_handler_setup_warn(self, m_signal):
+ m_signal.NSIG = signal.NSIG
+ m_signal.valid_signals = signal.valid_signals
+ m_signal.set_wakeup_fd.return_value = -1000
+
+ with self.assertWarnsRegex(
+ ResourceWarning, 'Signal wakeup fd was already set'
+ ):
+ self.loop.add_signal_handler(signal.SIGINT, lambda: True)
+
+ @mock.patch('asyncio.unix_events.signal')
def test_add_signal_handler_coroutine_error(self, m_signal):
m_signal.NSIG = signal.NSIG
@@ -214,6 +225,19 @@ class SelectorEventLoopSignalTests(test_utils.TestCase):
self.assertTrue(m_logging.info)
@mock.patch('asyncio.unix_events.signal')
+ def test_remove_signal_handler_cleanup_warn(self, m_signal):
+ m_signal.NSIG = signal.NSIG
+ m_signal.valid_signals = signal.valid_signals
+ self.loop.add_signal_handler(signal.SIGHUP, lambda: True)
+
+ m_signal.set_wakeup_fd.return_value = -1000
+
+ with self.assertWarnsRegex(
+ ResourceWarning, 'Got unexpected signal wakeup fd'
+ ):
+ self.loop.remove_signal_handler(signal.SIGHUP)
+
+ @mock.patch('asyncio.unix_events.signal')
def test_remove_signal_handler_error(self, m_signal):
m_signal.NSIG = signal.NSIG
m_signal.valid_signals = signal.valid_signals