From ef1c2cdab0fbc2d71177d33281539dd88cea1904 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 20 Apr 2022 17:11:55 +1000 Subject: [PATCH] tests/extmod/uasyncio_gather: Make double-raise gather test reliable. This double-raise test could fail when task[0] raises and stops the gather before task[1] raises, then task[1] is left to raise later on and spoil the test. Signed-off-by: Damien George --- tests/extmod/uasyncio_gather.py | 8 +++++--- tests/extmod/uasyncio_gather.py.exp | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/extmod/uasyncio_gather.py b/tests/extmod/uasyncio_gather.py index 718e702be6..366c113a26 100644 --- a/tests/extmod/uasyncio_gather.py +++ b/tests/extmod/uasyncio_gather.py @@ -34,9 +34,10 @@ async def task_loop(id): print("task_loop loop", id) -async def task_raise(id): +async def task_raise(id, t=0.02): print("task_raise start", id) - await asyncio.sleep(0.02) + await asyncio.sleep(t) + print("task_raise raise", id) raise ValueError(id) @@ -79,7 +80,8 @@ async def main(): print("====") # Test case where both tasks raise an exception. - tasks = [asyncio.create_task(task_raise(1)), asyncio.create_task(task_raise(2))] + # Use t=0 so they raise one after the other, between the gather starting and finishing. + tasks = [asyncio.create_task(task_raise(1, t=0)), asyncio.create_task(task_raise(2, t=0))] try: await asyncio.gather(*tasks) except ValueError as er: diff --git a/tests/extmod/uasyncio_gather.py.exp b/tests/extmod/uasyncio_gather.py.exp index 9b30c36b67..74a2ecf751 100644 --- a/tests/extmod/uasyncio_gather.py.exp +++ b/tests/extmod/uasyncio_gather.py.exp @@ -16,16 +16,20 @@ end 2 start 1 task_raise start 2 end 1 +task_raise raise 2 [1, ValueError(2,)] ==== task_loop start 1 task_raise start 2 task_loop loop 1 +task_raise raise 2 ValueError(2,) False True ==== task_raise start 1 task_raise start 2 +task_raise raise 1 +task_raise raise 2 ValueError(1,) True True ====