File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,12 @@ class _OperationNotComplete(Exception):
2828 pass
2929
3030
31- RETRY_PREDICATE = retry .if_exception_type (_OperationNotComplete )
31+ RETRY_PREDICATE = retry .if_exception_type (
32+ _OperationNotComplete ,
33+ exceptions .TooManyRequests ,
34+ exceptions .InternalServerError ,
35+ exceptions .BadGateway ,
36+ )
3237DEFAULT_RETRY = retry .Retry (predicate = RETRY_PREDICATE )
3338
3439
Original file line number Diff line number Diff line change 1919import mock
2020import pytest
2121
22+ from google .api_core import exceptions
2223from google .api_core .future import polling
2324
2425
@@ -118,6 +119,34 @@ def test_result_timeout():
118119 future .result (timeout = 1 )
119120
120121
122+ class PollingFutureImplTransient (PollingFutureImplWithPoll ):
123+ def __init__ (self , errors ):
124+ super (PollingFutureImplTransient , self ).__init__ ()
125+ self ._errors = errors
126+
127+ def done (self ):
128+ if self ._errors :
129+ error , self ._errors = self ._errors [0 ], self ._errors [1 :]
130+ raise error ('testing' )
131+ self .poll_count += 1
132+ self .set_result (42 )
133+ return True
134+
135+
136+ def test_result_transient_error ():
137+ future = PollingFutureImplTransient ((
138+ exceptions .TooManyRequests ,
139+ exceptions .InternalServerError ,
140+ exceptions .BadGateway ,
141+ ))
142+ result = future .result ()
143+ assert result == 42
144+ assert future .poll_count == 1
145+ # Repeated calls should not cause additional polling
146+ assert future .result () == result
147+ assert future .poll_count == 1
148+
149+
121150def test_callback_background_thread ():
122151 future = PollingFutureImplWithPoll ()
123152 callback = mock .Mock ()
You can’t perform that action at this time.
0 commit comments