From c90f097519c7342a128848bf9dc5b38ba75d4222 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 3 May 2022 22:39:58 +1000 Subject: [PATCH] tests/extmod: Increase timing on uasyncio tests to make more reliable. Non-real-time systems like Windows, Linux and macOS do not have reliable timing, so increase the sleep intervals to make these tests more likely to pass. Signed-off-by: Damien George --- tests/extmod/uasyncio_basic.py | 10 +++++----- tests/extmod/uasyncio_basic.py.exp | 2 +- tests/extmod/uasyncio_gather.py | 12 ++++++------ tests/extmod/uasyncio_heaplock.py | 8 ++++---- tests/extmod/uasyncio_wait_task.py | 6 +++--- tests/extmod/uasyncio_wait_task.py.exp | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/extmod/uasyncio_basic.py b/tests/extmod/uasyncio_basic.py index c88908d99b320..20c0a82e47a91 100644 --- a/tests/extmod/uasyncio_basic.py +++ b/tests/extmod/uasyncio_basic.py @@ -32,18 +32,18 @@ async def main(): print("after sleep") t0 = ticks() - await delay_print(0.02, "short") + await delay_print(0.2, "short") t1 = ticks() - await delay_print(0.04, "long") + await delay_print(0.4, "long") t2 = ticks() await delay_print(-1, "negative") t3 = ticks() print( "took {} {} {}".format( - round(ticks_diff(t1, t0), -1), - round(ticks_diff(t2, t1), -1), - round(ticks_diff(t3, t2), -1), + round(ticks_diff(t1, t0), -2), + round(ticks_diff(t2, t1), -2), + round(ticks_diff(t3, t2), -2), ) ) diff --git a/tests/extmod/uasyncio_basic.py.exp b/tests/extmod/uasyncio_basic.py.exp index 6673978769fbf..478e22abc8ff6 100644 --- a/tests/extmod/uasyncio_basic.py.exp +++ b/tests/extmod/uasyncio_basic.py.exp @@ -3,4 +3,4 @@ after sleep short long negative -took 20 40 0 +took 200 400 0 diff --git a/tests/extmod/uasyncio_gather.py b/tests/extmod/uasyncio_gather.py index fb47e753f1429..c081221c9fc68 100644 --- a/tests/extmod/uasyncio_gather.py +++ b/tests/extmod/uasyncio_gather.py @@ -20,7 +20,7 @@ async def factorial(name, number): return f -async def task(id, t=0.02): +async def task(id, t=0.1): print("start", id) await asyncio.sleep(t) print("end", id) @@ -30,11 +30,11 @@ async def task(id, t=0.02): async def task_loop(id): print("task_loop start", id) while True: - await asyncio.sleep(0.02) + await asyncio.sleep(0.1) print("task_loop loop", id) -async def task_raise(id, t=0.02): +async def task_raise(id, t=0.1): print("task_raise start", id) await asyncio.sleep(t) print("task_raise raise", id) @@ -75,7 +75,7 @@ async def main(): print(tasks[0].done(), tasks[1].done()) for t in tasks: t.cancel() - await asyncio.sleep(0.04) + await asyncio.sleep(0.2) print("====") @@ -92,9 +92,9 @@ async def main(): # Cancel a multi gather. t = asyncio.create_task(gather_task(task(1), task(2))) - await asyncio.sleep(0.01) + await asyncio.sleep(0.05) t.cancel() - await asyncio.sleep(0.04) + await asyncio.sleep(0.2) # Test edge cases where the gather is cancelled just as tasks are created and ending. for i in range(1, 4): diff --git a/tests/extmod/uasyncio_heaplock.py b/tests/extmod/uasyncio_heaplock.py index 3a92d36c9f57b..34a51cd370e52 100644 --- a/tests/extmod/uasyncio_heaplock.py +++ b/tests/extmod/uasyncio_heaplock.py @@ -29,15 +29,15 @@ async def task(id, n, t): async def main(): - t1 = asyncio.create_task(task(1, 4, 20)) - t2 = asyncio.create_task(task(2, 2, 50)) + t1 = asyncio.create_task(task(1, 4, 100)) + t2 = asyncio.create_task(task(2, 2, 250)) micropython.heap_lock() print("start") - await asyncio.sleep_ms(1) + await asyncio.sleep_ms(5) print("sleep") - await asyncio.sleep_ms(70) + await asyncio.sleep_ms(350) print("finish") micropython.heap_unlock() diff --git a/tests/extmod/uasyncio_wait_task.py b/tests/extmod/uasyncio_wait_task.py index 3c79320c9f5c4..e19e29903ccc3 100644 --- a/tests/extmod/uasyncio_wait_task.py +++ b/tests/extmod/uasyncio_wait_task.py @@ -54,8 +54,8 @@ async def main(): print("----") # Create 2 tasks - ts1 = asyncio.create_task(delay_print(0.04, "hello")) - ts2 = asyncio.create_task(delay_print(0.08, "world")) + ts1 = asyncio.create_task(delay_print(0.2, "hello")) + ts2 = asyncio.create_task(delay_print(0.4, "world")) # Time how long the tasks take to finish, they should execute in parallel print("start") @@ -64,7 +64,7 @@ async def main(): t1 = ticks() await ts2 t2 = ticks() - print("took {} {}".format(round(ticks_diff(t1, t0), -1), round(ticks_diff(t2, t1), -1))) + print("took {} {}".format(round(ticks_diff(t1, t0), -2), round(ticks_diff(t2, t1), -2))) # Wait on a task that raises an exception t = asyncio.create_task(task_raise()) diff --git a/tests/extmod/uasyncio_wait_task.py.exp b/tests/extmod/uasyncio_wait_task.py.exp index ee4e70fb4eb1e..04be37f48406d 100644 --- a/tests/extmod/uasyncio_wait_task.py.exp +++ b/tests/extmod/uasyncio_wait_task.py.exp @@ -5,6 +5,6 @@ task 2 start hello world -took 40 40 +took 200 200 task_raise ValueError pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy