Skip to content

Commit

Permalink
limit test time to 2 minutes, then consider it a failure and log what…
Browse files Browse the repository at this point in the history
… was running
  • Loading branch information
shyba committed Mar 17, 2021
1 parent 7371c30 commit ff5d5f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lbry/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class AsyncioTestCase(unittest.TestCase):
# https://bugs.python.org/issue32972

LOOP_SLOW_CALLBACK_DURATION = 0.2
TIMEOUT = 120.0

maxDiff = None

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):

Expand Down
1 change: 1 addition & 0 deletions tests/unit/dht/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ff5d5f2

Please sign in to comment.