Skip to content

Commit

Permalink
fix: retry all 5xx status code errors (#452)
Browse files Browse the repository at this point in the history
Fixes: codecov/engineering-team#1709

Signed-off-by: joseph-sentry <[email protected]>
  • Loading branch information
joseph-sentry authored Jun 4, 2024
1 parent 7432bad commit bd4f749
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions codecov_cli/helpers/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def wrapper(*args, **kwargs):
while retry < MAX_RETRIES:
try:
response = func(*args, **kwargs)
if response.status_code == 502:
if response.status_code >= 500:
logger.warning(
"Response status code was 502.",
f"Response status code was {response.status_code}.",
extra=dict(extra_log_attributes=dict(retry=retry)),
)
raise RetryException
Expand Down
10 changes: 6 additions & 4 deletions tests/helpers/test_upload_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,19 +306,21 @@ def test_upload_sender_result_fail_post_400(

assert sender.warnings is not None

def test_upload_sender_result_fail_post_502(
self, mocker, mocked_responses, mocked_legacy_upload_endpoint, capsys

@pytest.mark.parametrize("error_code", [500, 502])
def test_upload_sender_result_fail_post_500s(
self, mocker, mocked_responses, mocked_legacy_upload_endpoint, capsys, error_code
):
mocker.patch("codecov_cli.helpers.request.sleep")
mocked_legacy_upload_endpoint.status = 502
mocked_legacy_upload_endpoint.status = error_code

with pytest.raises(Exception, match="Request failed after too many retries"):
_ = UploadSender().send_upload_data(
upload_collection, random_sha, random_token, **named_upload_data
)

matcher = re.compile(
r"(warning.*((Response status code was 502)|(Request failed\. Retrying)).*(\n)?){6}"
rf"(warning.*((Response status code was {error_code})|(Request failed\. Retrying)).*(\n)?){{6}}"
)

assert matcher.match(capsys.readouterr().err) is not None
Expand Down

0 comments on commit bd4f749

Please sign in to comment.