Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion google/cloud/storage/retry.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,7 +21,14 @@
import json


_RETRYABLE_TYPES = (
# ConnectionError is a built-in exception only in Python3 and not in Python2.
try:
_RETRYABLE_STDLIB_TYPES = (ConnectionError,)
except NameError:
_RETRYABLE_STDLIB_TYPES = ()


_RETRYABLE_TYPES = _RETRYABLE_STDLIB_TYPES + (
api_exceptions.TooManyRequests, # 429
api_exceptions.InternalServerError, # 500
api_exceptions.BadGateway, # 502
Expand All@@ -30,6 +37,7 @@
requests.ConnectionError,
)


# Some retriable errors don't have their own custom exception in api_core.
_ADDITIONAL_RETRYABLE_STATUS_CODES = (408,)

Expand Down
21 changes: 21 additions & 0 deletions tests/unit/test_retry.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,14 @@
import mock


try:
ConnectionError
except NameError:
_HAS_STDLIB_CONNECTION_ERROR = False
else:
_HAS_STDLIB_CONNECTION_ERROR = True


class Test_should_retry(unittest.TestCase):
def _call_fut(self, exc):
from google.cloud.storage import retry
Expand DownExpand Up@@ -56,9 +64,22 @@ def test_w_google_api_call_error_miss(self):
self.assertFalse(self._call_fut(exc))

def test_w_requests_connection_error(self):
import requests

exc = requests.ConnectionError()
self.assertTrue(self._call_fut(exc))

def test_miss_w_stdlib_error(self):
exc = ValueError("testing")
Comment thread
tseaver marked this conversation as resolved.
self.assertFalse(self._call_fut(exc))

@unittest.skipUnless(
_HAS_STDLIB_CONNECTION_ERROR, "No builtin 'ConnectionError' in Python 2",
)
def test_w_stdlib_connection_error(self):
exc = ConnectionError()
self.assertTrue(self._call_fut(exc))


class TestConditionalRetryPolicy(unittest.TestCase):
def _make_one(self, retry_policy, conditional_predicate, required_kwargs):
Expand Down