Skip to content

Commit 3dd9bfa

Browse files
authored
bpo-47038: Rewrite missed asyncio.wait_for test to use IsolatedAnsyncioTestCase (GH-31946)
1 parent dd0082c commit 3dd9bfa

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

Lib/test/test_asyncio/test_tasks.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,32 +1990,6 @@ def test_task_source_traceback(self):
19901990
'test_task_source_traceback'))
19911991
self.loop.run_until_complete(task)
19921992

1993-
def _test_cancel_wait_for(self, timeout):
1994-
loop = asyncio.new_event_loop()
1995-
self.addCleanup(loop.close)
1996-
1997-
async def blocking_coroutine():
1998-
fut = self.new_future(loop)
1999-
# Block: fut result is never set
2000-
await fut
2001-
2002-
task = loop.create_task(blocking_coroutine())
2003-
2004-
wait = loop.create_task(asyncio.wait_for(task, timeout))
2005-
loop.call_soon(wait.cancel)
2006-
2007-
self.assertRaises(asyncio.CancelledError,
2008-
loop.run_until_complete, wait)
2009-
2010-
# Python issue #23219: cancelling the wait must also cancel the task
2011-
self.assertTrue(task.cancelled())
2012-
2013-
def test_cancel_blocking_wait_for(self):
2014-
self._test_cancel_wait_for(None)
2015-
2016-
def test_cancel_wait_for(self):
2017-
self._test_cancel_wait_for(60.0)
2018-
20191993
def test_cancel_gather_1(self):
20201994
"""Ensure that a gathering future refuses to be cancelled once all
20211995
children are done"""

Lib/test/test_asyncio/test_waitfor.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,30 @@ async def inner():
264264

265265
self.assertEqual(await inner_task, 42)
266266

267+
async def _test_cancel_wait_for(self, timeout):
268+
loop = asyncio.get_running_loop()
269+
270+
async def blocking_coroutine():
271+
fut = loop.create_future()
272+
# Block: fut result is never set
273+
await fut
274+
275+
task = asyncio.create_task(blocking_coroutine())
276+
277+
wait = asyncio.create_task(asyncio.wait_for(task, timeout))
278+
loop.call_soon(wait.cancel)
279+
280+
with self.assertRaises(asyncio.CancelledError):
281+
await wait
282+
283+
# Python issue #23219: cancelling the wait must also cancel the task
284+
self.assertTrue(task.cancelled())
285+
286+
async def test_cancel_blocking_wait_for(self):
287+
await self._test_cancel_wait_for(None)
288+
289+
async def test_cancel_wait_for(self):
290+
await self._test_cancel_wait_for(60.0)
267291

268292

269293
if __name__ == '__main__':

0 commit comments

Comments
 (0)