File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change 2121import json
2222
2323
24- _RETRYABLE_TYPES = (
24+ # ConnectionError is a built-in exception only in Python3 and not in Python2.
25+ try :
26+ _RETRYABLE_STDLIB_TYPES = (ConnectionError ,)
27+ except NameError :
28+ _RETRYABLE_STDLIB_TYPES = ()
29+
30+
31+ _RETRYABLE_TYPES = _RETRYABLE_STDLIB_TYPES + (
2532 api_exceptions .TooManyRequests , # 429
2633 api_exceptions .InternalServerError , # 500
2734 api_exceptions .BadGateway , # 502
3037 requests .ConnectionError ,
3138)
3239
40+
3341# Some retriable errors don't have their own custom exception in api_core.
3442_ADDITIONAL_RETRYABLE_STATUS_CODES = (408 ,)
3543
Original file line number Diff line number Diff line change 1919import mock
2020
2121
22+ try :
23+ ConnectionError
24+ except NameError :
25+ _HAS_STDLIB_CONNECTION_ERROR = False
26+ else :
27+ _HAS_STDLIB_CONNECTION_ERROR = True
28+
29+
2230class Test_should_retry (unittest .TestCase ):
2331 def _call_fut (self , exc ):
2432 from google .cloud .storage import retry
@@ -56,9 +64,22 @@ def test_w_google_api_call_error_miss(self):
5664 self .assertFalse (self ._call_fut (exc ))
5765
5866 def test_w_requests_connection_error (self ):
67+ import requests
68+
69+ exc = requests .ConnectionError ()
70+ self .assertTrue (self ._call_fut (exc ))
71+
72+ def test_miss_w_stdlib_error (self ):
5973 exc = ValueError ("testing" )
6074 self .assertFalse (self ._call_fut (exc ))
6175
76+ @unittest .skipUnless (
77+ _HAS_STDLIB_CONNECTION_ERROR , "No builtin 'ConnectionError' in Python 2" ,
78+ )
79+ def test_w_stdlib_connection_error (self ):
80+ exc = ConnectionError ()
81+ self .assertTrue (self ._call_fut (exc ))
82+
6283
6384class TestConditionalRetryPolicy (unittest .TestCase ):
6485 def _make_one (self , retry_policy , conditional_predicate , required_kwargs ):
You can’t perform that action at this time.
0 commit comments