@@ -639,27 +639,30 @@ def on_timeout():
639639 await asyncio .sleep (0 )
640640 return timed_out , structured_block_finished , outer_code_reached
641641
642- # Test which timed out.
643- t1 = self .new_task (loop , make_request_with_timeout (sleep = 10.0 , timeout = 0.1 ))
644- timed_out , structured_block_finished , outer_code_reached = (
645- loop .run_until_complete (t1 )
646- )
647- self .assertTrue (timed_out )
648- self .assertFalse (structured_block_finished ) # it was cancelled
649- self .assertTrue (outer_code_reached ) # task got uncancelled after leaving
650- # the structured block and continued until
651- # completion
652- self .assertEqual (t1 .cancelling (), 0 ) # no pending cancellation of the outer task
653-
654- # Test which did not time out.
655- t2 = self .new_task (loop , make_request_with_timeout (sleep = 0 , timeout = 10.0 ))
656- timed_out , structured_block_finished , outer_code_reached = (
657- loop .run_until_complete (t2 )
658- )
659- self .assertFalse (timed_out )
660- self .assertTrue (structured_block_finished )
661- self .assertTrue (outer_code_reached )
662- self .assertEqual (t2 .cancelling (), 0 )
642+ try :
643+ # Test which timed out.
644+ t1 = self .new_task (loop , make_request_with_timeout (sleep = 10.0 , timeout = 0.1 ))
645+ timed_out , structured_block_finished , outer_code_reached = (
646+ loop .run_until_complete (t1 )
647+ )
648+ self .assertTrue (timed_out )
649+ self .assertFalse (structured_block_finished ) # it was cancelled
650+ self .assertTrue (outer_code_reached ) # task got uncancelled after leaving
651+ # the structured block and continued until
652+ # completion
653+ self .assertEqual (t1 .cancelling (), 0 ) # no pending cancellation of the outer task
654+
655+ # Test which did not time out.
656+ t2 = self .new_task (loop , make_request_with_timeout (sleep = 0 , timeout = 10.0 ))
657+ timed_out , structured_block_finished , outer_code_reached = (
658+ loop .run_until_complete (t2 )
659+ )
660+ self .assertFalse (timed_out )
661+ self .assertTrue (structured_block_finished )
662+ self .assertTrue (outer_code_reached )
663+ self .assertEqual (t2 .cancelling (), 0 )
664+ finally :
665+ loop .close ()
663666
664667 def test_cancel (self ):
665668
0 commit comments