Skip to content
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- n/a
### Fixed
- Fixed certain exceptions from requests library (such as SSL handshake errors) not being
propagated correctly.

## [2.0.0] - 2019-09-09

Expand Down
2 changes: 1 addition & 1 deletion pubtools/pulplib/_impl/client/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def should_retry(self, attempt, future):
retry = self._delegate.should_retry(attempt, future)

exception = future.exception()
if exception and hasattr(exception, "response"):
if exception and getattr(exception, "response", None) is not None:
# if returned status code is 404, never retry on that
if exception.response.status_code == 404:
return False
Expand Down
35 changes: 35 additions & 0 deletions tests/client/test_retry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import requests
from more_executors.futures import f_return_error

from pubtools.pulplib._impl.client.retry import PulpRetryPolicy


def test_retries_by_default():
"""Retry policy will retry on generic exception types."""
policy = PulpRetryPolicy()
assert policy.should_retry(0, f_return_error(RuntimeError("oops!")))


def test_retries_http_errors():
"""Retry policy will retry on HTTP-level errors."""
policy = PulpRetryPolicy()
response = requests.Response()
response.status_code = 500
error = requests.HTTPError(response=response)
assert policy.should_retry(0, f_return_error(error))


def test_retries_http_errors_no_response():
"""Retry policy will retry on requests exception types with response=None."""
policy = PulpRetryPolicy()
error = requests.HTTPError(response=None)
assert policy.should_retry(0, f_return_error(error))


def test_no_retries_http_404_errors():
"""Retry policy does not retry on HTTP 404 responses."""
policy = PulpRetryPolicy()
response = requests.Response()
response.status_code = 404
error = requests.HTTPError(response=response)
assert not policy.should_retry(0, f_return_error(error))