Skip to content

tests/extmod: Increase timing on uasyncio tests to make more reliable. #8617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions tests/extmod/uasyncio_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
)

Expand Down
2 changes: 1 addition & 1 deletion tests/extmod/uasyncio_basic.py.exp
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ after sleep
short
long
negative
took 20 40 0
took 200 400 0
12 changes: 6 additions & 6 deletions tests/extmod/uasyncio_gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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("====")

Expand All @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions tests/extmod/uasyncio_heaplock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions tests/extmod/uasyncio_wait_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion tests/extmod/uasyncio_wait_task.py.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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