Skip to content

Commit f6c0061

Browse files
committed
uasyncio.core: Add test for wait_for() call.
1 parent f6555ba commit f6c0061

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

uasyncio.core/test_wait_for.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
try:
2+
import uasyncio.core as asyncio
3+
except ImportError:
4+
import asyncio
5+
import logging
6+
#logging.basicConfig(level=logging.DEBUG)
7+
#asyncio.set_debug(True)
8+
9+
10+
def looper(iters):
11+
for i in range(iters):
12+
print("ping")
13+
yield from asyncio.sleep(1.0)
14+
return 10
15+
16+
17+
def run_to():
18+
try:
19+
ret = yield from asyncio.wait_for(looper(2), 1)
20+
print("result:", ret)
21+
assert False
22+
except asyncio.TimeoutError:
23+
print("Coro timed out")
24+
25+
print("=================")
26+
27+
try:
28+
ret = yield from asyncio.wait_for(looper(2), 2)
29+
print("result:", ret)
30+
assert False
31+
except asyncio.TimeoutError:
32+
print("Coro timed out")
33+
34+
print("=================")
35+
36+
try:
37+
ret = yield from asyncio.wait_for(looper(2), 3)
38+
print("result:", ret)
39+
except asyncio.TimeoutError:
40+
print("Coro timed out")
41+
assert False
42+
43+
44+
loop = asyncio.get_event_loop()
45+
loop.run_until_complete(run_to())
46+
loop.run_until_complete(asyncio.sleep(1))

0 commit comments

Comments
 (0)