uasyncio.core: Add test for wait_for() call.

pull/234/merge
Paul Sokolovsky 2017-12-14 19:38:49 +02:00
rodzic f6555bae97
commit f6c00613db
1 zmienionych plików z 46 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,46 @@
try:
import uasyncio.core as asyncio
except ImportError:
import asyncio
import logging
#logging.basicConfig(level=logging.DEBUG)
#asyncio.set_debug(True)
def looper(iters):
for i in range(iters):
print("ping")
yield from asyncio.sleep(1.0)
return 10
def run_to():
try:
ret = yield from asyncio.wait_for(looper(2), 1)
print("result:", ret)
assert False
except asyncio.TimeoutError:
print("Coro timed out")
print("=================")
try:
ret = yield from asyncio.wait_for(looper(2), 2)
print("result:", ret)
assert False
except asyncio.TimeoutError:
print("Coro timed out")
print("=================")
try:
ret = yield from asyncio.wait_for(looper(2), 3)
print("result:", ret)
except asyncio.TimeoutError:
print("Coro timed out")
assert False
loop = asyncio.get_event_loop()
loop.run_until_complete(run_to())
loop.run_until_complete(asyncio.sleep(1))