@@ -727,46 +727,29 @@ def test_no_timeout(self):
727
727
future1 , future2 ]),
728
728
completed )
729
729
730
- def test_zero_timeout (self ):
731
- future1 = self .executor .submit (time .sleep , 2 )
732
- completed_futures = set ()
733
- try :
734
- for future in futures .as_completed (
735
- [CANCELLED_AND_NOTIFIED_FUTURE ,
736
- EXCEPTION_FUTURE ,
737
- SUCCESSFUL_FUTURE ,
738
- future1 ],
739
- timeout = 0 ):
740
- completed_futures .add (future )
741
- except futures .TimeoutError :
742
- pass
743
-
744
- self .assertEqual (set ([CANCELLED_AND_NOTIFIED_FUTURE ,
745
- EXCEPTION_FUTURE ,
746
- SUCCESSFUL_FUTURE ]),
747
- completed_futures )
748
-
749
- def test_nonzero_timeout (self ):
730
+ def test_future_times_out (self ):
750
731
"""Test ``futures.as_completed`` timing out before
751
- completing it's final future completes."""
732
+ completing it's final future."""
733
+ already_completed = {CANCELLED_AND_NOTIFIED_FUTURE ,
734
+ EXCEPTION_FUTURE ,
735
+ SUCCESSFUL_FUTURE }
752
736
753
- future1 = self .executor .submit (time .sleep , 1 )
754
- completed_futures = set ()
755
- try :
756
- for future in futures .as_completed (
757
- [CANCELLED_AND_NOTIFIED_FUTURE ,
758
- EXCEPTION_FUTURE ,
759
- SUCCESSFUL_FUTURE ,
760
- future1 ],
761
- timeout = 0.01 ):
762
- completed_futures .add (future )
763
- except futures .TimeoutError :
764
- pass
737
+ for timeout in (0 , 0.01 ):
738
+ with self .subTest (timeout ):
765
739
766
- self .assertEqual (set ([CANCELLED_AND_NOTIFIED_FUTURE ,
767
- EXCEPTION_FUTURE ,
768
- SUCCESSFUL_FUTURE ]),
769
- completed_futures )
740
+ future = self .executor .submit (time .sleep , 0.1 )
741
+ completed_futures = set ()
742
+ try :
743
+ for f in futures .as_completed (
744
+ already_completed | {future },
745
+ timeout
746
+ ):
747
+ completed_futures .add (f )
748
+ except futures .TimeoutError :
749
+ pass
750
+
751
+ # Check that ``future`` wasn't completed.
752
+ self .assertEqual (completed_futures , already_completed )
770
753
771
754
def test_duplicate_futures (self ):
772
755
# Issue 20367. Duplicate futures should not raise exceptions or give
0 commit comments