uasyncio: Add test showing I/O scheduling starvation.

If there is a coroutine to run immediately (with wait delay <= 0),
uasyncio.core never calls .wait() method, which is required to
process I/O events (and schedule coroutines waiting for them).

This test demonstrates the problem.
pull/183/merge
Peter Hinch 2017-08-07 08:25:35 +01:00 zatwierdzone przez Paul Sokolovsky
rodzic c7b277ff7c
commit 65605e3de8
1 zmienionych plików z 35 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,35 @@
try:
import uasyncio as asyncio
except:
import asyncio
try:
import utime as time
except:
import time
done = False
async def receiver():
global done
with open('test_io_starve.py', 'rb') as f:
sreader = asyncio.StreamReader(f)
while True:
await asyncio.sleep(0.1)
res = await sreader.readline()
# Didn't get there with the original problem this test shows
done = True
async def foo():
start = time.time()
while time.time() - start < 1:
await asyncio.sleep(0)
loop.stop()
loop = asyncio.get_event_loop()
loop.create_task(foo())
loop.create_task(receiver())
loop.run_forever()
assert done
print('OK')