summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2016-10-05 20:57:12 (GMT)
committerYury Selivanov <yury@magic.io>2016-10-05 20:57:12 (GMT)
commit9eb6c677763c1eaf0646170ccff110c89828a06e (patch)
tree546b340fc4aad4f9b24e0bb646242ebc744c6155 /Lib/test
parentb5bb404ccaa9a3dd81e220fb4ca40253be778831 (diff)
downloadcpython-9eb6c677763c1eaf0646170ccff110c89828a06e.zip
cpython-9eb6c677763c1eaf0646170ccff110c89828a06e.tar.gz
cpython-9eb6c677763c1eaf0646170ccff110c89828a06e.tar.bz2
Issue #28368: Refuse monitoring processes if the child watcher has no loop attached.
Patch by Vincent Michel.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_asyncio/test_subprocess.py7
-rw-r--r--Lib/test/test_asyncio/test_unix_events.py14
2 files changed, 20 insertions, 1 deletions
diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py
index 58f7253..1531023 100644
--- a/Lib/test/test_asyncio/test_subprocess.py
+++ b/Lib/test/test_asyncio/test_subprocess.py
@@ -433,6 +433,13 @@ class SubprocessMixin:
# the transport was not notified yet
self.assertFalse(killed)
+ # Unlike SafeChildWatcher, FastChildWatcher does not pop the
+ # callbacks if waitpid() is called elsewhere. Let's clear them
+ # manually to avoid a warning when the watcher is detached.
+ if sys.platform != 'win32' and \
+ isinstance(self, SubprocessFastWatcherTests):
+ asyncio.get_child_watcher()._callbacks.clear()
+
def test_popen_error(self):
# Issue #24763: check that the subprocess transport is closed
# when BaseSubprocessTransport fails
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index 570022f..088ef40 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -11,6 +11,7 @@ import sys
import tempfile
import threading
import unittest
+import warnings
from unittest import mock
if sys.platform == 'win32':
@@ -1391,7 +1392,9 @@ class ChildWatcherTestsMixin:
with mock.patch.object(
old_loop, "remove_signal_handler") as m_remove_signal_handler:
- self.watcher.attach_loop(None)
+ with self.assertWarnsRegex(
+ RuntimeWarning, 'A loop is being detached'):
+ self.watcher.attach_loop(None)
m_remove_signal_handler.assert_called_once_with(
signal.SIGCHLD)
@@ -1463,6 +1466,15 @@ class ChildWatcherTestsMixin:
if isinstance(self.watcher, asyncio.FastChildWatcher):
self.assertFalse(self.watcher._zombies)
+ @waitpid_mocks
+ def test_add_child_handler_with_no_loop_attached(self, m):
+ callback = mock.Mock()
+ with self.create_watcher() as watcher:
+ with self.assertRaisesRegex(
+ RuntimeError,
+ 'the child watcher does not have a loop attached'):
+ watcher.add_child_handler(100, callback)
+
class SafeChildWatcherTests (ChildWatcherTestsMixin, test_utils.TestCase):
def create_watcher(self):