diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-09-12 21:18:23 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-12 21:18:23 (GMT) |
commit | 5013a5ebc9978a58435036fa3860c465882c21da (patch) | |
tree | 17b3b2cbacb5195305891cf79b9adcbc8c9e0ca5 /Lib/asyncio | |
parent | 4d7807ab9ad9f990e948d250bbb390b23a790764 (diff) | |
download | cpython-5013a5ebc9978a58435036fa3860c465882c21da.zip cpython-5013a5ebc9978a58435036fa3860c465882c21da.tar.gz cpython-5013a5ebc9978a58435036fa3860c465882c21da.tar.bz2 |
[3.6] bpo-31250: test_asyncio: fix dangling threads (#3517)
* bpo-31250, test_asyncio: fix dangling threads (#3252)
* Explicitly call shutdown(wait=True) on executors to wait until all
threads complete to prevent side effects between tests.
* Fix test_loop_self_reading_exception(): don't mock loop.close().
Previously, the original close() method was called rather than the
mock, because how set_event_loop() registered loop.close().
(cherry picked from commit 16432beadb8eba079c9786cc0c0eaacfd9fd2f7b)
* bpo-31250, test_asyncio: fix EventLoopTestsMixin.tearDown() (#3264)
Call doCleanups() to close the loop after calling
executor.shutdown(wait=True): see TestCase.set_event_loop() of
asyncio.test_utils.
Replace also gc.collect() with support.gc_collect().
(cherry picked from commit e8a533fbc734af6eeb389202ba6c6e9c2548027f)
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/test_utils.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/asyncio/test_utils.py b/Lib/asyncio/test_utils.py index 94d48e1..8b8c22a 100644 --- a/Lib/asyncio/test_utils.py +++ b/Lib/asyncio/test_utils.py @@ -438,12 +438,19 @@ def get_function_source(func): class TestCase(unittest.TestCase): + @staticmethod + def close_loop(loop): + executor = loop._default_executor + if executor is not None: + executor.shutdown(wait=True) + loop.close() + def set_event_loop(self, loop, *, cleanup=True): assert loop is not None # ensure that the event loop is passed explicitly in asyncio events.set_event_loop(None) if cleanup: - self.addCleanup(loop.close) + self.addCleanup(self.close_loop, loop) def new_test_loop(self, gen=None): loop = TestLoop(gen) |