Skip to content

[3.9] bpo-47038: Rewrite missed asyncio.wait_for test to use IsolatedAnsyncioTestCase (GH-31946) #31949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions Lib/test/test_asyncio/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2188,32 +2188,6 @@ def test_task_source_traceback(self):
'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"""
Expand Down
24 changes: 24 additions & 0 deletions Lib/test/test_asyncio/test_waitfor.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,30 @@ async def inner():

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__':
Expand Down