File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -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 )
@@ -747,6 +746,28 @@ def test_zero_timeout(self):
747
746
SUCCESSFUL_FUTURE ]),
748
747
completed_futures )
749
748
749
+ def test_nonzero_timeout (self ):
750
+ """Test ``futures.as_completed`` timing out before
751
+ completing it's final future completes."""
752
+
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
765
+
766
+ self .assertEqual (set ([CANCELLED_AND_NOTIFIED_FUTURE ,
767
+ EXCEPTION_FUTURE ,
768
+ SUCCESSFUL_FUTURE ]),
769
+ completed_futures )
770
+
750
771
def test_duplicate_futures (self ):
751
772
# Issue 20367. Duplicate futures should not raise exceptions or give
752
773
# duplicate responses.
You can’t perform that action at this time.
0 commit comments