@@ -165,14 +165,18 @@ def raise_response():
165
165
166
166
@mock .patch ("time.sleep" )
167
167
@mock .patch ("random.randint" )
168
- def test_success_with_retry_connection_error (self , randint_mock , sleep_mock ):
169
- randint_mock .side_effect = [125 , 625 , 375 ]
168
+ def test_retry_success_http_standard_lib_connection_errors (
169
+ self , randint_mock , sleep_mock
170
+ ):
171
+ randint_mock .side_effect = [125 , 625 , 500 , 875 , 375 ]
170
172
171
- response = _make_response (http .client .NOT_FOUND )
173
+ status_code = int (http .client .OK )
174
+ response = _make_response (status_code )
172
175
responses = [
173
- ConnectionResetError , # Subclass of ConnectionError
174
- urllib3 .exceptions .ConnectionError ,
175
- requests .exceptions .ConnectionError ,
176
+ http .client .BadStatusLine ("" ),
177
+ http .client .IncompleteRead ("" ),
178
+ http .client .ResponseNotReady ,
179
+ ConnectionError ,
176
180
response ,
177
181
]
178
182
func = mock .Mock (side_effect = responses , spec = [])
@@ -183,28 +187,29 @@ def test_success_with_retry_connection_error(self, randint_mock, sleep_mock):
183
187
)
184
188
185
189
assert ret_val == responses [- 1 ]
186
-
187
- assert func .call_count == 4
188
- assert func .mock_calls == [mock .call ()] * 4
189
-
190
- assert randint_mock .call_count == 3
191
- assert randint_mock .mock_calls == [mock .call (0 , 1000 )] * 3
192
-
193
- assert sleep_mock .call_count == 3
190
+ assert func .call_count == 5
191
+ assert func .mock_calls == [mock .call ()] * 5
192
+ assert randint_mock .call_count == 4
193
+ assert randint_mock .mock_calls == [mock .call (0 , 1000 )] * 4
194
+ assert sleep_mock .call_count == 4
194
195
sleep_mock .assert_any_call (1.125 )
195
196
sleep_mock .assert_any_call (2.625 )
196
- sleep_mock .assert_any_call (4.375 )
197
+ sleep_mock .assert_any_call (4.500 )
198
+ sleep_mock .assert_any_call (8.875 )
197
199
198
200
@mock .patch ("time.sleep" )
199
201
@mock .patch ("random.randint" )
200
- def test_success_with_retry_chunked_encoding_error (self , randint_mock , sleep_mock ):
201
- randint_mock .side_effect = [125 , 625 , 375 ]
202
+ def test_retry_success_requests_lib_connection_errors (
203
+ self , randint_mock , sleep_mock
204
+ ):
205
+ randint_mock .side_effect = [125 , 625 , 500 , 875 ]
202
206
203
207
status_code = int (http .client .OK )
204
208
response = _make_response (status_code )
205
209
responses = [
210
+ requests .exceptions .ConnectionError ,
206
211
requests .exceptions .ChunkedEncodingError ,
207
- requests .exceptions .ChunkedEncodingError ,
212
+ requests .exceptions .Timeout ,
208
213
response ,
209
214
]
210
215
func = mock .Mock (side_effect = responses , spec = [])
@@ -215,27 +220,27 @@ def test_success_with_retry_chunked_encoding_error(self, randint_mock, sleep_moc
215
220
)
216
221
217
222
assert ret_val == responses [- 1 ]
218
-
219
- assert func .call_count == 3
220
- assert func .mock_calls == [mock .call ()] * 3
221
-
222
- assert randint_mock .call_count == 2
223
- assert randint_mock .mock_calls == [mock .call (0 , 1000 )] * 2
224
-
225
- assert sleep_mock .call_count == 2
223
+ assert func .call_count == 4
224
+ assert func .mock_calls == [mock .call ()] * 4
225
+ assert randint_mock .call_count == 3
226
+ assert randint_mock .mock_calls == [mock .call (0 , 1000 )] * 3
227
+ assert sleep_mock .call_count == 3
226
228
sleep_mock .assert_any_call (1.125 )
227
229
sleep_mock .assert_any_call (2.625 )
230
+ sleep_mock .assert_any_call (4.500 )
228
231
229
232
@mock .patch ("time.sleep" )
230
233
@mock .patch ("random.randint" )
231
- def test_success_with_retry_client_timeout (self , randint_mock , sleep_mock ):
232
- randint_mock .side_effect = [125 , 625 , 375 ]
234
+ def test_retry_success_urllib3_connection_errors (self , randint_mock , sleep_mock ):
235
+ randint_mock .side_effect = [125 , 625 , 500 , 875 , 375 ]
233
236
234
237
status_code = int (http .client .OK )
235
238
response = _make_response (status_code )
236
239
responses = [
237
- requests .exceptions .Timeout ,
238
- requests .exceptions .Timeout ,
240
+ urllib3 .exceptions .PoolError (None , "" ),
241
+ urllib3 .exceptions .ProtocolError ,
242
+ urllib3 .exceptions .SSLError ,
243
+ urllib3 .exceptions .TimeoutError ,
239
244
response ,
240
245
]
241
246
func = mock .Mock (side_effect = responses , spec = [])
@@ -246,16 +251,15 @@ def test_success_with_retry_client_timeout(self, randint_mock, sleep_mock):
246
251
)
247
252
248
253
assert ret_val == responses [- 1 ]
249
-
250
- assert func .call_count == 3
251
- assert func .mock_calls == [mock .call ()] * 3
252
-
253
- assert randint_mock .call_count == 2
254
- assert randint_mock .mock_calls == [mock .call (0 , 1000 )] * 2
255
-
256
- assert sleep_mock .call_count == 2
254
+ assert func .call_count == 5
255
+ assert func .mock_calls == [mock .call ()] * 5
256
+ assert randint_mock .call_count == 4
257
+ assert randint_mock .mock_calls == [mock .call (0 , 1000 )] * 4
258
+ assert sleep_mock .call_count == 4
257
259
sleep_mock .assert_any_call (1.125 )
258
260
sleep_mock .assert_any_call (2.625 )
261
+ sleep_mock .assert_any_call (4.500 )
262
+ sleep_mock .assert_any_call (8.875 )
259
263
260
264
@mock .patch ("time.sleep" )
261
265
@mock .patch ("random.randint" )
0 commit comments