bpo-34037: test_asyncio uses shutdown_default_executor() (GH-16284)

This commit is contained in:
Victor Stinner 2019-09-19 16:45:06 +02:00 committed by GitHub
parent b2dd2dd6e9
commit 079931d122
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

@ -216,6 +216,9 @@ class BaseEventLoopTests(test_utils.TestCase):
raise NotImplementedError( raise NotImplementedError(
'cannot submit into a dummy executor') 'cannot submit into a dummy executor')
self.loop._process_events = mock.Mock()
self.loop._write_to_self = mock.Mock()
executor = DummyExecutor() executor = DummyExecutor()
self.loop.set_default_executor(executor) self.loop.set_default_executor(executor)
self.assertIs(executor, self.loop._default_executor) self.assertIs(executor, self.loop._default_executor)
@ -226,6 +229,9 @@ class BaseEventLoopTests(test_utils.TestCase):
with self.assertWarns(DeprecationWarning): with self.assertWarns(DeprecationWarning):
self.loop.set_default_executor(executor) self.loop.set_default_executor(executor)
# Avoid cleaning up the executor mock
self.loop._default_executor = None
def test_call_soon(self): def test_call_soon(self):
def cb(): def cb():
pass pass

View File

@ -3232,6 +3232,8 @@ class RunCoroutineThreadsafeTests(test_utils.TestCase):
self.loop.set_exception_handler(callback) self.loop.set_exception_handler(callback)
# Set corrupted task factory # Set corrupted task factory
self.addCleanup(self.loop.set_task_factory,
self.loop.get_task_factory())
self.loop.set_task_factory(task_factory) self.loop.set_task_factory(task_factory)
# Run event loop # Run event loop

View File

@ -509,9 +509,11 @@ def get_function_source(func):
class TestCase(unittest.TestCase): class TestCase(unittest.TestCase):
@staticmethod @staticmethod
def close_loop(loop): def close_loop(loop):
executor = loop._default_executor if loop._default_executor is not None:
if executor is not None: if not loop.is_closed():
executor.shutdown(wait=True) loop.run_until_complete(loop.shutdown_default_executor())
else:
loop._default_executor.shutdown(wait=True)
loop.close() loop.close()
policy = support.maybe_get_event_loop_policy() policy = support.maybe_get_event_loop_policy()
if policy is not None: if policy is not None: