@@ -291,15 +291,12 @@ async def test_cancel_wait_for(self):
291
291
292
292
async def simultaneous_self_cancel_and_inner_result (
293
293
self ,
294
- do_cancel ,
295
294
waitfor_timeout ,
296
295
inner_action ,
297
296
):
298
297
"""Construct scenario where external cancellation and
299
298
awaitable becoming done happen simultaneously.
300
299
inner_acion is one of 'cancel', 'exception' or 'result'.
301
- if do_cancel, the wait_for() call is cancelled at the same time when
302
- inner_action is executed.
303
300
Make sure waitfor_timeout > 0.1. Trying to make it == 0.1 is not
304
301
a reliable way to make timeout happen at the same time as the above.
305
302
"""
@@ -320,30 +317,31 @@ async def simultaneous_self_cancel_and_inner_result(
320
317
else :
321
318
assert inner_action == 'result'
322
319
inner .set_result ('inner result' )
323
- if do_cancel :
324
- waitfor_task .cancel ()
325
- return await waitfor_task
320
+ waitfor_task .cancel ()
321
+ with self .assertRaises (asyncio .CancelledError ):
322
+ return await waitfor_task
323
+ # Consume inner's exception, to avoid "Future exception was never
324
+ # retrieved" messages
325
+ if inner_action == 'exception' :
326
+ self .assertIsInstance (inner .exception (), RuntimeError )
326
327
327
328
async def test_simultaneous_self_cancel_and_inner_result (self ):
328
329
for timeout in (10 , None ):
329
330
with self .subTest (waitfor_timeout = timeout ):
330
- with self .assertRaises (asyncio .CancelledError ):
331
- await self .simultaneous_self_cancel_and_inner_result (
332
- True , timeout , 'result' )
331
+ await self .simultaneous_self_cancel_and_inner_result (
332
+ timeout , 'result' )
333
333
334
334
async def test_simultaneous_self_cancel_and_inner_exc (self ):
335
335
for timeout in (10 , None ):
336
336
with self .subTest (waitfor_timeout = timeout ):
337
- with self .assertRaises (RuntimeError ):
338
- await self .simultaneous_self_cancel_and_inner_result (
339
- True , timeout , 'exception' )
337
+ await self .simultaneous_self_cancel_and_inner_result (
338
+ timeout , 'exception' )
340
339
341
340
async def test_simultaneous_self_cancel_and_inner_cancel (self ):
342
341
for timeout in (10 , None ):
343
342
with self .subTest (waitfor_timeout = timeout ):
344
- with self .assertRaises (asyncio .CancelledError ):
345
- await self .simultaneous_self_cancel_and_inner_result (
346
- True , timeout , 'cancel' )
343
+ await self .simultaneous_self_cancel_and_inner_result (
344
+ timeout , 'cancel' )
347
345
348
346
349
347
if __name__ == '__main__' :
0 commit comments