From f6c00613dbc5819be6567f8c3f3c4015a30d5e4d Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 14 Dec 2017 19:38:49 +0200 Subject: [PATCH] uasyncio.core: Add test for wait_for() call. --- uasyncio.core/test_wait_for.py | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 uasyncio.core/test_wait_for.py diff --git a/uasyncio.core/test_wait_for.py b/uasyncio.core/test_wait_for.py new file mode 100644 index 00000000..0e156387 --- /dev/null +++ b/uasyncio.core/test_wait_for.py @@ -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))