diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/extmod/uasyncio_loop_stop.py | 45 | ||||
-rw-r--r-- | tests/extmod/uasyncio_loop_stop.py.exp | 7 |
2 files changed, 52 insertions, 0 deletions
diff --git a/tests/extmod/uasyncio_loop_stop.py b/tests/extmod/uasyncio_loop_stop.py new file mode 100644 index 0000000000..23507f9a7e --- /dev/null +++ b/tests/extmod/uasyncio_loop_stop.py @@ -0,0 +1,45 @@ +# Test Loop.stop() to stop the event loop + +try: + import uasyncio as asyncio +except ImportError: + try: + import asyncio + except ImportError: + print("SKIP") + raise SystemExit + + +async def task(): + print("task") + + +async def main(): + print("start") + + # Stop the loop after next yield + loop.stop() + + # Check that calling stop() again doesn't do/break anything + loop.stop() + + # This await should stop + print("sleep") + await asyncio.sleep(0) + + # Schedule stop, then create a new task, then yield + loop.stop() + asyncio.create_task(task()) + await asyncio.sleep(0) + + # Final stop + print("end") + loop.stop() + + +loop = asyncio.get_event_loop() +loop.create_task(main()) + +for i in range(3): + print("run", i) + loop.run_forever() diff --git a/tests/extmod/uasyncio_loop_stop.py.exp b/tests/extmod/uasyncio_loop_stop.py.exp new file mode 100644 index 0000000000..bada5f0d84 --- /dev/null +++ b/tests/extmod/uasyncio_loop_stop.py.exp @@ -0,0 +1,7 @@ +run 0 +start +sleep +run 1 +run 2 +task +end |