diff --git a/lbry/testcase.py b/lbry/testcase.py index 68c07f2df..ae983e0c1 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 @@ class AsyncioTestCase(unittest.TestCase): 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 @@ class AsyncioTestCase(unittest.TestCase): 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 4ce7e7e59..a5e599f9b 100644 --- a/tests/unit/dht/test_node.py +++ b/tests/unit/dht/test_node.py @@ -11,6 +11,7 @@ from lbry.extras.daemon.storage import SQLiteStorage 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)