Skip to content

Commit 48ead94

Browse files
committed
uasyncio.core: Add test for fair scheduling.
1 parent aba6935 commit 48ead94

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

uasyncio.core/test_fair_schedule.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Test that uasyncio scheduling is fair, i.e. gives all
2+
# coroutines equal chance to run (this specifically checks
3+
# round-robin scheduling).
4+
import uasyncio.core as asyncio
5+
6+
7+
COROS = 5
8+
ITERS = 5
9+
10+
11+
result = []
12+
13+
14+
async def coro(n):
15+
for i in range(ITERS):
16+
result.append(n)
17+
yield
18+
19+
20+
async def done():
21+
while True:
22+
if len(result) == COROS * ITERS:
23+
#print(result)
24+
assert result == list(range(COROS)) * ITERS
25+
return
26+
yield
27+
28+
29+
loop = asyncio.get_event_loop()
30+
31+
for n in range(COROS):
32+
loop.create_task(coro(n))
33+
34+
loop.run_until_complete(done())

0 commit comments

Comments
 (0)