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):
28
28
pass
29
29
30
30
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
+ )
32
37
DEFAULT_RETRY = retry .Retry (predicate = RETRY_PREDICATE )
33
38
34
39
Original file line number Diff line number Diff line change 19
19
import mock
20
20
import pytest
21
21
22
+ from google .api_core import exceptions
22
23
from google .api_core .future import polling
23
24
24
25
@@ -118,6 +119,34 @@ def test_result_timeout():
118
119
future .result (timeout = 1 )
119
120
120
121
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
+
121
150
def test_callback_background_thread ():
122
151
future = PollingFutureImplWithPoll ()
123
152
callback = mock .Mock ()
You can’t perform that action at this time.
0 commit comments