Skip to content

Commit 55ff73f

Browse files
committed
Add test for nested task groups
Co-Authored-By: @arthur-tacca
1 parent 3f91f2d commit 55ff73f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Lib/test/test_asyncio/test_taskgroups.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,28 @@ async def raise_after(t, e):
845845
pass
846846
self.assertEqual(asyncio.current_task().cancelling(), 0)
847847

848+
async def test_nested_groups_both_cancelled(self):
849+
async def raise_after(t, e):
850+
await asyncio.sleep(t)
851+
raise e()
852+
853+
try:
854+
async with asyncio.TaskGroup() as outer_tg:
855+
try:
856+
async with asyncio.TaskGroup() as inner_tg:
857+
inner_tg.create_task(raise_after(0, RuntimeError))
858+
outer_tg.create_task(raise_after(0, ValueError))
859+
except* RuntimeError:
860+
pass
861+
else:
862+
self.fail("RuntimeError not raised")
863+
self.assertEqual(asyncio.current_task().cancelling(), 1)
864+
except* ValueError:
865+
pass
866+
else:
867+
self.fail("ValueError not raised")
868+
self.assertEqual(asyncio.current_task().cancelling(), 0)
869+
848870

849871
if __name__ == "__main__":
850872
unittest.main()

0 commit comments

Comments
 (0)