Skip to content

Commit

Permalink
fix: do not mark upload download instances invalid with retriable err…
Browse files Browse the repository at this point in the history
…or codes (#261)
  • Loading branch information
cojenco committed Aug 30, 2021
1 parent 00ccf71 commit a1c5f7d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion google/resumable_media/_helpers.py
Expand Up @@ -95,7 +95,8 @@ def require_status_code(response, status_codes, get_status_code, callback=do_not
"""
status_code = get_status_code(response)
if status_code not in status_codes:
callback()
if status_code not in common.RETRYABLE:
callback()
raise common.InvalidResponse(
response,
"Request failed with status code",
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/test__helpers.py
Expand Up @@ -125,6 +125,28 @@ def test_failure_with_callback(self):
assert error.args[3:] == status_codes
callback.assert_called_once_with()

def test_retryable_failure_without_callback(self):
status_codes = (http.client.OK,)
retryable_responses = [
_make_response(status_code) for status_code in common.RETRYABLE
]
callback = mock.Mock(spec=[])
for retryable_response in retryable_responses:
with pytest.raises(common.InvalidResponse) as exc_info:
_helpers.require_status_code(
retryable_response,
status_codes,
self._get_status_code,
callback=callback,
)

error = exc_info.value
assert error.response is retryable_response
assert len(error.args) == 4
assert error.args[1] == retryable_response.status_code
assert error.args[3:] == status_codes
callback.assert_not_called()


class Test_calculate_retry_wait(object):
@mock.patch("random.randint", return_value=125)
Expand Down

0 comments on commit a1c5f7d

Please sign in to comment.