Merge pull request #3490 from ghost/integration_test_setup_cleanup_timeouts

added timeout of async operations to integration test setup/teardown
This commit is contained in:
Lex Berezhny 2021-12-02 19:52:44 -05:00 committed by GitHub
commit 63437712cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -132,17 +132,18 @@ class AsyncioTestCase(unittest.TestCase):
with outcome.testPartExecutor(self):
self.setUp()
self.add_timeout()
self.loop.run_until_complete(self.asyncSetUp())
if outcome.success:
outcome.expecting_failure = expecting_failure
with outcome.testPartExecutor(self, isTest=True):
maybe_coroutine = testMethod()
if asyncio.iscoroutine(maybe_coroutine):
if self.TIMEOUT:
self.loop.call_later(self.TIMEOUT, self.cancel)
self.add_timeout()
self.loop.run_until_complete(maybe_coroutine)
outcome.expecting_failure = False
with outcome.testPartExecutor(self):
self.add_timeout()
self.loop.run_until_complete(self.asyncTearDown())
self.tearDown()
@ -190,6 +191,7 @@ class AsyncioTestCase(unittest.TestCase):
with outcome.testPartExecutor(self):
maybe_coroutine = function(*args, **kwargs)
if asyncio.iscoroutine(maybe_coroutine):
self.add_timeout()
self.loop.run_until_complete(maybe_coroutine)
def cancel(self):
@ -198,6 +200,10 @@ class AsyncioTestCase(unittest.TestCase):
task.print_stack()
task.cancel()
def add_timeout(self):
if self.TIMEOUT:
self.loop.call_later(self.TIMEOUT, self.cancel)
class AdvanceTimeTestCase(AsyncioTestCase):