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