8000 tests/extmod: Increase timing on uasyncio tests to make more reliable. · micropython/micropython@c90f097 · GitHub
[go: up one dir, main page]

Skip to content

Commit c90f097

Browse files
committed
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 <damien@micropython.org>
1 parent 0e7bfc8 commit c90f097

6 files changed

+20
-20
lines changed

tests/extmod/uasyncio_basic.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ async def main():
3232
print("after sleep")
3333

3434
t0 = ticks()
35-
await delay_print(0.02, "short")
35+
await delay_print(0.2, "short")
3636
t1 = ticks()
37-
await delay_print(0.04, "long")
37+
await delay_print(0.4, "long")
3838
t2 = ticks()
3939
await delay_print(-1, "negative")
4040
t3 = ticks()
4141

4242
print(
4343
"took {} {} {}".format(
44-
round(ticks_diff(t1, t0), -1),
45-
round(ticks_diff(t2, t1), -1),
46-
round(ticks_diff(t3, t2), -1),
44+
round(ticks_diff(t1, t0), -2),
45+
round(ticks_diff(t2, t1), -2),
46+
round(ticks_diff(t3, t2), -2),
4747
)
4848
)
4949

tests/extmod/uasyncio_basic.py.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ after sleep
33
short
44
long
55
negative
6-
took 20 40 0
6+
took 200 400 0

tests/extmod/uasyncio_gather.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async def factorial(name, number):
2020
return f
2121

2222

23-
async def task(id, t=0.02):
23+
async def task(id, t=0.1):
2424
print("start", id)
2525
await asyncio.sleep(t)
2626
print("end", id)
@@ -30,11 +30,11 @@ async def task(id, t=0.02):
3030
async def task_loop(id):
3131
print("task_loop start", id)
3232
while True:
33-
await asyncio.sleep(0.02)
33+
await asyncio.sleep(0.1)
3434
print("task_loop loop", id)
3535

3636

37-
async def task_raise(id, t=0.02):
37+
async def task_raise(id, t=0.1):
3838
print("task_raise start", id)
3939
await asyncio.sleep(t)
4040
print("task_raise raise", id)
@@ -75,7 +75,7 @@ async def main():
7575
print(tasks[0].done(), tasks[1].done())
7676
for t in tasks:
7777
t.cancel()
78-
await asyncio.sleep(0.04)
78+
await asyncio.sleep(0.2)
7979

8080
print("====")
8181

@@ -92,9 +92,9 @@ async def main():
9292

9393
# Cancel a multi gather.
9494
t = asyncio.create_task(gather_task(task(1), task(2)))
95-
await asyncio.sleep(0.01)
95+
await asyncio.sleep(0.05)
9696
t.cancel()
97-
await asyncio.sleep(0.04)
97+
await asyncio.sleep(0.2)
9898

9999
# Test edge cases where the gather is cancelled just as tasks are created and ending.
100100
for i in range(1, 4):

tests/extmod/uasyncio_heaplock.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ async def task(id, n, t):
2929

3030

3131
async def main():
32-
t1 = asyncio.create_task(task(1, 4, 20))
33-
t2 = asyncio.create_task(task(2, 2, 50))
32+
t1 = asyncio.create_task(task(1, 4, 100))
33+
t2 = asyncio.create_task(task(2, 2, 250))
3434

3535
micropython.heap_lock()
3636

3737
print("start")
38-
await asyncio.sleep_ms(1)
38+
await asyncio.sleep_ms(5)
3939
print("sleep")
40-
await asyncio.sleep_ms(70)
40+
await asyncio.sleep_ms(350)
4141
print("finish")
4242

4343
micropython.heap_unlock()

tests/extmod/uasyncio_wait_task.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ async def main():
5454
print("----")
5555

5656
# Create 2 tasks
57-
ts1 = asyncio.create_task(delay_print(0.04, "hello"))
58-
ts2 = asyncio.create_task(delay_print(0.08, "world"))
57+
ts1 = asyncio.create_task(delay_print(0.2, "hello"))
58+
ts2 = asyncio.create_task(delay_print(0.4, "world"))
5959

6060
# Time how long the tasks take to finish, they should execute in parallel
6161
print("start")
@@ -64,7 +64,7 @@ async def main():
6464
t1 = ticks()
6565
await ts2
6666
t2 = ticks()
67-
print("took {} {}".format(round(ticks_diff(t1, t0), -1), round(ticks_diff(t2, t1), -1)))
67+
print("took {} {}".format(round(ticks_diff(t1, t0), -2), round(ticks_diff(t2, t1), -2)))
6868

6969
# Wait on a task that raises an exception
7070
t = asyncio.create_task(task_raise())

tests/extmod/uasyncio_wait_task.py.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ task 2
55
start
66
hello
77
world
8-
took 40 40
8+
took 200 200
99
task_raise
1010
ValueError

0 commit comments

Comments
 (0)
0