summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio
diff options
context:
space:
mode:
authorTin Tvrtković <tinchester@gmail.com>2022-02-26 16:18:48 (GMT)
committerGitHub <noreply@github.com>2022-02-26 16:18:48 (GMT)
commitedbee56d698ebb4489aa68311f44d104a23f5eb7 (patch)
treea893557a3c45e059d09c0de457a7fb18da63a294 /Lib/test/test_asyncio
parent41ddcd3f40f8171a396e57b841a74fcc83884eab (diff)
downloadcpython-edbee56d698ebb4489aa68311f44d104a23f5eb7.zip
cpython-edbee56d698ebb4489aa68311f44d104a23f5eb7.tar.gz
cpython-edbee56d698ebb4489aa68311f44d104a23f5eb7.tar.bz2
Taskgroup tweaks (GH-31559)
Now uses .cancel()/.uncancel(), for even fewer broken edge cases.
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r--Lib/test/test_asyncio/test_taskgroups.py26
1 files changed, 19 insertions, 7 deletions
diff --git a/Lib/test/test_asyncio/test_taskgroups.py b/Lib/test/test_asyncio/test_taskgroups.py
index 40774a8..df51528 100644
--- a/Lib/test/test_asyncio/test_taskgroups.py
+++ b/Lib/test/test_asyncio/test_taskgroups.py
@@ -120,7 +120,11 @@ class TestTaskGroup(unittest.IsolatedAsyncioTestCase):
self.assertTrue(t2_cancel)
self.assertTrue(t2.cancelled())
- async def test_taskgroup_05(self):
+ async def test_cancel_children_on_child_error(self):
+ """
+ When a child task raises an error, the rest of the children
+ are cancelled and the errors are gathered into an EG.
+ """
NUM = 0
t2_cancel = False
@@ -165,7 +169,7 @@ class TestTaskGroup(unittest.IsolatedAsyncioTestCase):
self.assertTrue(t2_cancel)
self.assertTrue(runner_cancel)
- async def test_taskgroup_06(self):
+ async def test_cancellation(self):
NUM = 0
@@ -186,10 +190,12 @@ class TestTaskGroup(unittest.IsolatedAsyncioTestCase):
await asyncio.sleep(0.1)
self.assertFalse(r.done())
- r.cancel()
- with self.assertRaises(asyncio.CancelledError):
+ r.cancel("test")
+ with self.assertRaises(asyncio.CancelledError) as cm:
await r
+ self.assertEqual(cm.exception.args, ('test',))
+
self.assertEqual(NUM, 5)
async def test_taskgroup_07(self):
@@ -226,7 +232,7 @@ class TestTaskGroup(unittest.IsolatedAsyncioTestCase):
self.assertEqual(NUM, 15)
- async def test_taskgroup_08(self):
+ async def test_cancellation_in_body(self):
async def foo():
await asyncio.sleep(0.1)
@@ -246,10 +252,12 @@ class TestTaskGroup(unittest.IsolatedAsyncioTestCase):
await asyncio.sleep(0.1)
self.assertFalse(r.done())
- r.cancel()
- with self.assertRaises(asyncio.CancelledError):
+ r.cancel("test")
+ with self.assertRaises(asyncio.CancelledError) as cm:
await r
+ self.assertEqual(cm.exception.args, ('test',))
+
async def test_taskgroup_09(self):
t1 = t2 = None
@@ -699,3 +707,7 @@ class TestTaskGroup(unittest.IsolatedAsyncioTestCase):
async with taskgroups.TaskGroup() as g:
t = g.create_task(coro(), name="yolo")
self.assertEqual(t.get_name(), "yolo")
+
+
+if __name__ == "__main__":
+ unittest.main()