bpo-32684: Fix gather to propagate cancel of itself with return_exceptions (GH-7209)

This commit is contained in:
Yury Selivanov 2018-05-29 17:20:02 -04:00 committed by GitHub
parent 1cee216cf3
commit 863b674909
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 2 deletions

View file

@ -2037,7 +2037,7 @@ class BaseTaskTests:
def test_cancel_wait_for(self):
self._test_cancel_wait_for(60.0)
def test_cancel_gather(self):
def test_cancel_gather_1(self):
"""Ensure that a gathering future refuses to be cancelled once all
children are done"""
loop = asyncio.new_event_loop()
@ -2067,6 +2067,33 @@ class BaseTaskTests:
self.assertFalse(gather_task.cancelled())
self.assertEqual(gather_task.result(), [42])
def test_cancel_gather_2(self):
loop = asyncio.new_event_loop()
self.addCleanup(loop.close)
async def test():
time = 0
while True:
time += 0.05
await asyncio.gather(asyncio.sleep(0.05),
return_exceptions=True,
loop=loop)
if time > 1:
return
async def main():
qwe = asyncio.Task(test())
await asyncio.sleep(0.2)
qwe.cancel()
try:
await qwe
except asyncio.CancelledError:
pass
else:
self.fail('gather did not propagate the cancellation request')
loop.run_until_complete(main())
def test_exception_traceback(self):
# See http://bugs.python.org/issue28843