From 48ead94116c6a33d60200cece635e432b3592b35 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 6 Mar 2017 12:16:34 +0100 Subject: [PATCH] uasyncio.core: Add test for fair scheduling. --- uasyncio.core/test_fair_schedule.py | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 uasyncio.core/test_fair_schedule.py diff --git a/uasyncio.core/test_fair_schedule.py b/uasyncio.core/test_fair_schedule.py new file mode 100644 index 00000000..24206d7e --- /dev/null +++ b/uasyncio.core/test_fair_schedule.py @@ -0,0 +1,34 @@ +# Test that uasyncio scheduling is fair, i.e. gives all +# coroutines equal chance to run (this specifically checks +# round-robin scheduling). +import uasyncio.core as asyncio + + +COROS = 5 +ITERS = 5 + + +result = [] + + +async def coro(n): + for i in range(ITERS): + result.append(n) + yield + + +async def done(): + while True: + if len(result) == COROS * ITERS: + #print(result) + assert result == list(range(COROS)) * ITERS + return + yield + + +loop = asyncio.get_event_loop() + +for n in range(COROS): + loop.create_task(coro(n)) + +loop.run_until_complete(done())