summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-03-16 23:44:22 (GMT)
committerGitHub <noreply@github.com>2022-03-16 23:44:22 (GMT)
commit0412e3ae03a694af1e27d4af61ca503a6513394d (patch)
treec5cc32c1f71369cc87a744b7eb963427a0525c82
parent3244659521798417810100904f39ae5dabe60a7f (diff)
downloadcpython-0412e3ae03a694af1e27d4af61ca503a6513394d.zip
cpython-0412e3ae03a694af1e27d4af61ca503a6513394d.tar.gz
cpython-0412e3ae03a694af1e27d4af61ca503a6513394d.tar.bz2
bpo-47038: Rewrite missed asyncio.wait_for test to use IsolatedAnsyncioTestCase (GH-31946)
(cherry picked from commit 3dd9bfac04d3dcdbfd3f8011a6c9d4b9ac8c116a) Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
-rw-r--r--Lib/test/test_asyncio/test_tasks.py26
-rw-r--r--Lib/test/test_asyncio/test_waitfor.py24
2 files changed, 24 insertions, 26 deletions
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
index 58f8d49..f311876 100644
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -2188,32 +2188,6 @@ class BaseTaskTests:
'test_task_source_traceback'))
self.loop.run_until_complete(task)
- def _test_cancel_wait_for(self, timeout):
- loop = asyncio.new_event_loop()
- self.addCleanup(loop.close)
-
- async def blocking_coroutine():
- fut = self.new_future(loop)
- # Block: fut result is never set
- await fut
-
- task = loop.create_task(blocking_coroutine())
-
- wait = loop.create_task(asyncio.wait_for(task, timeout))
- loop.call_soon(wait.cancel)
-
- self.assertRaises(asyncio.CancelledError,
- loop.run_until_complete, wait)
-
- # Python issue #23219: cancelling the wait must also cancel the task
- self.assertTrue(task.cancelled())
-
- def test_cancel_blocking_wait_for(self):
- self._test_cancel_wait_for(None)
-
- def test_cancel_wait_for(self):
- self._test_cancel_wait_for(60.0)
-
def test_cancel_gather_1(self):
"""Ensure that a gathering future refuses to be cancelled once all
children are done"""
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__':