summaryrefslogtreecommitdiff
path: root/tests/extmod/asyncio_gather_notimpl.py
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2023-06-08 16:01:38 +1000
committerDamien George <damien@micropython.org>2023-06-19 17:33:03 +1000
commit6027c41c8f5b8f1a9e7b85b2bb93b3e6f2718e54 (patch)
tree08f41a4d0cd48fa5c0bc49519832ac2faba6923a /tests/extmod/asyncio_gather_notimpl.py
parent2fbc08c462e247e7f78460783c9a07c76c5b762e (diff)
tests: Rename uasyncio to asyncio.
This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'tests/extmod/asyncio_gather_notimpl.py')
-rw-r--r--tests/extmod/asyncio_gather_notimpl.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/extmod/asyncio_gather_notimpl.py b/tests/extmod/asyncio_gather_notimpl.py
new file mode 100644
index 000000000..98f9a9368
--- /dev/null
+++ b/tests/extmod/asyncio_gather_notimpl.py
@@ -0,0 +1,50 @@
+# Test asyncio.gather() function, features that are not implemented.
+
+try:
+ import asyncio
+except ImportError:
+ print("SKIP")
+ raise SystemExit
+
+
+def custom_handler(loop, context):
+ print(repr(context["exception"]))
+
+
+async def task(id):
+ print("task start", id)
+ await asyncio.sleep(0.01)
+ print("task end", id)
+ return id
+
+
+async def gather_task(t0, t1):
+ print("gather_task start")
+ await asyncio.gather(t0, t1)
+ print("gather_task end")
+
+
+async def main():
+ loop = asyncio.get_event_loop()
+ loop.set_exception_handler(custom_handler)
+
+ # Test case where can't wait on a task being gathered.
+ tasks = [asyncio.create_task(task(1)), asyncio.create_task(task(2))]
+ gt = asyncio.create_task(gather_task(tasks[0], tasks[1]))
+ await asyncio.sleep(0) # let the gather start
+ try:
+ await tasks[0] # can't await because this task is part of the gather
+ except RuntimeError as er:
+ print(repr(er))
+ await gt
+
+ print("====")
+
+ # Test case where can't gather on a task being waited.
+ tasks = [asyncio.create_task(task(1)), asyncio.create_task(task(2))]
+ asyncio.create_task(gather_task(tasks[0], tasks[1]))
+ await tasks[0] # wait on this task before the gather starts
+ await tasks[1]
+
+
+asyncio.run(main())