]> granicus.if.org Git - python/commitdiff
bpo-30280: Cleanup threads in ayncio tests (#2501)
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 30 Jun 2017 09:12:33 +0000 (11:12 +0200)
committerGitHub <noreply@github.com>
Fri, 30 Jun 2017 09:12:33 +0000 (11:12 +0200)
* bpo-30280: asyncio now cleans up threads

asyncio base TestCase now uses threading_setup() and
threading_cleanup() of test.support to cleanup threads.

* asyncio: Fix TestBaseSelectorEventLoop cleanup

bpo-30280: TestBaseSelectorEventLoop of
test.test_asyncio.test_selector_events now correctly closes the event
loop: cleanup its executor to not leak threads.

Don't override the close() method of the event loop, only override
the_close_self_pipe() method.

Lib/asyncio/test_utils.py
Lib/test/test_asyncio/test_selector_events.py

index d273b08e8fac597558ca03fcf6f879687960ffbe..15059501070c70810f3cf2e65d440b41d52ad9d1 100644 (file)
@@ -32,6 +32,7 @@ from . import selectors
 from . import tasks
 from .coroutines import coroutine
 from .log import logger
+from test import support
 
 
 if sys.platform == 'win32':  # pragma: no cover
@@ -454,6 +455,7 @@ class TestCase(unittest.TestCase):
     def setUp(self):
         self._get_running_loop = events._get_running_loop
         events._get_running_loop = lambda: None
+        self._thread_cleanup = support.threading_setup()
 
     def tearDown(self):
         self.unpatch_get_running_loop()
@@ -464,6 +466,10 @@ class TestCase(unittest.TestCase):
         # in an except block of a generator
         self.assertEqual(sys.exc_info(), (None, None, None))
 
+        self.doCleanups()
+        support.threading_cleanup(*self._thread_cleanup)
+        support.reap_children()
+
 
 @contextlib.contextmanager
 def disable_logger():
index 6bf7862ecf9c0a0cdece16646812e42a3d7bd10a..c50b3e49565c92df33c64e5bc0438a273b498e7f 100644 (file)
@@ -24,16 +24,14 @@ MOCK_ANY = mock.ANY
 
 class TestBaseSelectorEventLoop(BaseSelectorEventLoop):
 
-    def close(self):
-        # Don't call the close() method of the parent class, because the
-        # selector is mocked
-        self._closed = True
-
     def _make_self_pipe(self):
         self._ssock = mock.Mock()
         self._csock = mock.Mock()
         self._internal_fds += 1
 
+    def _close_self_pipe(self):
+        pass
+
 
 def list_to_buffer(l=()):
     return bytearray().join(l)