@@ -711,7 +711,6 @@ def future_func():
711
711
712
712
713
713
class AsCompletedTests :
714
- # TODO([email protected] ): Should have a test with a non-zero timeout.
715
714
def test_no_timeout (self ):
716
715
future1 = self .executor .submit (mul , 2 , 21 )
717
716
future2 = self .executor .submit (mul , 7 , 6 )
@@ -728,24 +727,29 @@ def test_no_timeout(self):
728
727
future1 , future2 ]),
729
728
completed )
730
729
731
- def test_zero_timeout (self ):
732
- future1 = self .executor .submit (time .sleep , 2 )
733
- completed_futures = set ()
734
- try :
735
- for future in futures .as_completed (
736
- [CANCELLED_AND_NOTIFIED_FUTURE ,
737
- EXCEPTION_FUTURE ,
738
- SUCCESSFUL_FUTURE ,
739
- future1 ],
740
- timeout = 0 ):
741
- completed_futures .add (future )
742
- except futures .TimeoutError :
743
- pass
730
+ def test_future_times_out (self ):
731
+ """Test ``futures.as_completed`` timing out before
732
+ completing it's final future."""
733
+ already_completed = {CANCELLED_AND_NOTIFIED_FUTURE ,
734
+ EXCEPTION_FUTURE ,
735
+ SUCCESSFUL_FUTURE }
744
736
745
- self .assertEqual (set ([CANCELLED_AND_NOTIFIED_FUTURE ,
746
- EXCEPTION_FUTURE ,
747
- SUCCESSFUL_FUTURE ]),
748
- completed_futures )
737
+ for timeout in (0 , 0.01 ):
738
+ with self .subTest (timeout ):
739
+
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 )
749
753
750
754
def test_duplicate_futures (self ):
751
755
# Issue 20367. Duplicate futures should not raise exceptions or give
0 commit comments