summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio/test_waitfor.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-03-17 00:19:51 (GMT)
committerGitHub <noreply@github.com>2022-03-17 00:19:51 (GMT)
commit36f62c55759c4246f969f60f7470ba756f77b268 (patch)
treebccd9849f4826df7bf8f55f53b937bba0138b949 /Lib/test/test_asyncio/test_waitfor.py
parent4186dd662cf22613b21af948163978af4243a8d6 (diff)
downloadcpython-36f62c55759c4246f969f60f7470ba756f77b268.zip
cpython-36f62c55759c4246f969f60f7470ba756f77b268.tar.gz
cpython-36f62c55759c4246f969f60f7470ba756f77b268.tar.bz2
bpo-47038: Rewrite missed asyncio.wait_for test to use IsolatedAnsyncioTestCase (GH-31946) (#31948)
(cherry picked from commit 3dd9bfac04d3dcdbfd3f8011a6c9d4b9ac8c116a) Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com> Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Diffstat (limited to 'Lib/test/test_asyncio/test_waitfor.py')
-rw-r--r--Lib/test/test_asyncio/test_waitfor.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_waitfor.py b/Lib/test/test_asyncio/test_waitfor.py
index b00815e..874aabf 100644
--- a/Lib/test/test_asyncio/test_waitfor.py
+++ b/Lib/test/test_asyncio/test_waitfor.py
@@ -264,6 +264,30 @@ class AsyncioWaitForTest(unittest.IsolatedAsyncioTestCase):
self.assertEqual(await inner_task, 42)
+ async def _test_cancel_wait_for(self, timeout):
+ loop = asyncio.get_running_loop()
+
+ async def blocking_coroutine():
+ fut = loop.create_future()
+ # Block: fut result is never set
+ await fut
+
+ task = asyncio.create_task(blocking_coroutine())
+
+ wait = asyncio.create_task(asyncio.wait_for(task, timeout))
+ loop.call_soon(wait.cancel)
+
+ with self.assertRaises(asyncio.CancelledError):
+ await wait
+
+ # Python issue #23219: cancelling the wait must also cancel the task
+ self.assertTrue(task.cancelled())
+
+ async def test_cancel_blocking_wait_for(self):
+ await self._test_cancel_wait_for(None)
+
+ async def test_cancel_wait_for(self):
+ await self._test_cancel_wait_for(60.0)
if __name__ == '__main__':