@@ -200,7 +200,8 @@ def test_success_with_retry_connection_error(self, randint_mock, sleep_mock):
200200 def test_success_with_retry_chunked_encoding_error (self , randint_mock , sleep_mock ):
201201 randint_mock .side_effect = [125 , 625 , 375 ]
202202
203- response = _make_response (http .client .NOT_FOUND )
203+ status_code = int (http .client .OK )
204+ response = _make_response (status_code )
204205 responses = [
205206 requests .exceptions .ChunkedEncodingError ,
206207 requests .exceptions .ChunkedEncodingError ,
@@ -225,6 +226,37 @@ def test_success_with_retry_chunked_encoding_error(self, randint_mock, sleep_moc
225226 sleep_mock .assert_any_call (1.125 )
226227 sleep_mock .assert_any_call (2.625 )
227228
229+ @mock .patch (u"time.sleep" )
230+ @mock .patch (u"random.randint" )
231+ def test_success_with_retry_client_timeout (self , randint_mock , sleep_mock ):
232+ randint_mock .side_effect = [125 , 625 , 375 ]
233+
234+ status_code = int (http .client .OK )
235+ response = _make_response (status_code )
236+ responses = [
237+ requests .exceptions .Timeout ,
238+ requests .exceptions .Timeout ,
239+ response ,
240+ ]
241+ func = mock .Mock (side_effect = responses , spec = [])
242+
243+ retry_strategy = common .RetryStrategy ()
244+ ret_val = _request_helpers .wait_and_retry (
245+ func , _get_status_code , retry_strategy
246+ )
247+
248+ 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
257+ sleep_mock .assert_any_call (1.125 )
258+ sleep_mock .assert_any_call (2.625 )
259+
228260 @mock .patch ("time.sleep" )
229261 @mock .patch ("random.randint" )
230262 def test_retry_exceeds_max_cumulative (self , randint_mock , sleep_mock ):
0 commit comments