diff --git a/lbry/testcase.py b/lbry/testcase.py index 68c07f2df3..ae983e0c1c 100644 --- a/lbry/testcase.py +++ b/lbry/testcase.py @@ -84,6 +84,7 @@ class AsyncioTestCase(unittest.TestCase): # https://bugs.python.org/issue32972 LOOP_SLOW_CALLBACK_DURATION = 0.2 + TIMEOUT = 120.0 maxDiff = None @@ -137,6 +138,8 @@ def run(self, result=None): # pylint: disable=R0915 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.loop.run_until_complete(maybe_coroutine) outcome.expecting_failure = False with outcome.testPartExecutor(self): @@ -189,6 +192,12 @@ def doAsyncCleanups(self): # pylint: disable=C0103 if asyncio.iscoroutine(maybe_coroutine): self.loop.run_until_complete(maybe_coroutine) + def cancel(self): + for task in asyncio.all_tasks(self.loop): + if not task.done(): + task.print_stack() + task.cancel() + class AdvanceTimeTestCase(AsyncioTestCase): diff --git a/tests/unit/dht/test_node.py b/tests/unit/dht/test_node.py index 4ce7e7e592..a5e599f9b6 100644 --- a/tests/unit/dht/test_node.py +++ b/tests/unit/dht/test_node.py @@ -11,6 +11,7 @@ class TestNodePingQueueDiscover(AsyncioTestCase): + TIMEOUT = None # not supported as it advances time async def test_ping_queue_discover(self): loop = asyncio.get_event_loop() loop.set_debug(False)