micropython/tests/extmod/asyncio_fair.py
Damien George 6bb446b7ff tests/extmod: Remove asyncio .exp files that match CPython output.
These were added back in commit c4935f3049
because the tests required CPython 3.8, which was quite new at the time.
But CPython 3.8 was released over 4 years ago (October 2019) and the CI
test runners, and developers, have this (or a more recent) CPython version.

Removing the .exp files also helps keep MicroPython semantics the same as
CPython.

The asyncio_fair.py test it adjusted slightly to have more deterministic
timing and output.

Signed-off-by: Damien George <damien@micropython.org>
2024-01-24 11:20:06 +11:00

32 lines
638 B
Python

# Test fairness of scheduler
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def task(id, t):
print("task start", id)
while True:
if t > 0:
print("task work", id)
await asyncio.sleep(t)
async def main():
t1 = asyncio.create_task(task(1, -0.01))
t2 = asyncio.create_task(task(2, 0.1))
t3 = asyncio.create_task(task(3, 0.18))
t4 = asyncio.create_task(task(4, -100))
await asyncio.sleep(0.45) # t2 prints 5 times, t3 prints 3 times
t1.cancel()
t2.cancel()
t3.cancel()
t4.cancel()
print("finish")
asyncio.run(main())