@@ -1009,20 +1009,16 @@ def gen():
10091009 self .assertEqual (res , "ok" )
10101010
10111011 def test_wait_for_cancellation_race_condition (self ):
1012- def gen ():
1013- yield 0.1
1014- yield 0.1
1015- yield 0.1
1016- yield 0.1
1012+ async def inner ():
1013+ with contextlib .suppress (asyncio .CancelledError ):
1014+ await asyncio .sleep (1 )
1015+ return 1
10171016
1018- loop = self .new_test_loop (gen )
1017+ async def main ():
1018+ result = await asyncio .wait_for (inner (), timeout = .01 )
1019+ assert result == 1
10191020
1020- fut = self .new_future (loop )
1021- loop .call_later (0.1 , fut .set_result , "ok" )
1022- task = loop .create_task (asyncio .wait_for (fut , timeout = 1 ))
1023- loop .call_later (0.1 , task .cancel )
1024- res = loop .run_until_complete (task )
1025- self .assertEqual (res , "ok" )
1021+ asyncio .run (main ())
10261022
10271023 def test_wait_for_waits_for_task_cancellation (self ):
10281024 loop = asyncio .new_event_loop ()
@@ -1101,24 +1097,6 @@ async def inner():
11011097 with self .assertRaises (FooException ):
11021098 loop .run_until_complete (foo ())
11031099
1104- def test_wait_for_raises_timeout_error_if_returned_during_cancellation (self ):
1105- loop = asyncio .new_event_loop ()
1106- self .addCleanup (loop .close )
1107-
1108- async def foo ():
1109- async def inner ():
1110- try :
1111- await asyncio .sleep (0.2 )
1112- except asyncio .CancelledError :
1113- return 42
1114-
1115- inner_task = self .new_task (loop , inner ())
1116-
1117- await asyncio .wait_for (inner_task , timeout = _EPSILON )
1118-
1119- with self .assertRaises (asyncio .TimeoutError ):
1120- loop .run_until_complete (foo ())
1121-
11221100 def test_wait_for_self_cancellation (self ):
11231101 loop = asyncio .new_event_loop ()
11241102 self .addCleanup (loop .close )
0 commit comments