Skip to content

Commit 4c3b9fc

Browse files
authored
Merge pull request #58 from scrapinghub/retry-502
Retry 502 responses
2 parents 2a957ba + 0f6b494 commit 4c3b9fc

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

scrapinghub/hubstorage/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
logger = logging.getLogger('HubstorageClient')
1818

19-
_HTTP_ERROR_CODES_TO_RETRY = (408, 429, 503, 504)
19+
_HTTP_ERROR_CODES_TO_RETRY = (408, 429, 502, 503, 504)
2020

2121

2222
def _hc_retry_on_exception(err):

tests/hubstorage/test_retry.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
import json
55
import re
66

7-
from mock import patch
7+
import pytest
88
import responses
9+
from mock import patch
910
from requests import HTTPError, ConnectionError
1011
from scrapinghub import HubstorageClient
1112
from six.moves.http_client import BadStatusLine
@@ -133,8 +134,9 @@ def test_retrier_does_not_catch_unwanted_exception(hsspiderid):
133134
assert attempts_count[0] == 1
134135

135136

137+
@pytest.mark.parametrize('err_code', [408, 429, 502, 503, 504])
136138
@responses.activate
137-
def test_retrier_catches_badstatusline_and_429(hsspiderid):
139+
def test_retrier_catches_badstatusline_and_selected_http_errors(hsspiderid, err_code):
138140
# Prepare
139141
client = hsclient_with_retries()
140142
job_metadata = {
@@ -152,7 +154,7 @@ def request_callback(request):
152154
if attempts_count[0] <= 2:
153155
raise ConnectionError("Connection aborted.", BadStatusLine("''"))
154156
if attempts_count[0] == 3:
155-
return (429, {}, u'')
157+
return (err_code, {}, u'')
156158
else:
157159
resp_body = dict(job_metadata)
158160
return (200, {}, json.dumps(resp_body))

0 commit comments

Comments
 (0)