From bd4f749af6d3a941a3ce6075f7bec44fe9dd7ca2 Mon Sep 17 00:00:00 2001 From: joseph-sentry <136376984+joseph-sentry@users.noreply.github.com> Date: Tue, 4 Jun 2024 09:45:23 -0400 Subject: [PATCH] fix: retry all 5xx status code errors (#452) Fixes: https://github.com/codecov/engineering-team/issues/1709 Signed-off-by: joseph-sentry --- codecov_cli/helpers/request.py | 4 ++-- tests/helpers/test_upload_sender.py | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/codecov_cli/helpers/request.py b/codecov_cli/helpers/request.py index d356eed8..048efd23 100644 --- a/codecov_cli/helpers/request.py +++ b/codecov_cli/helpers/request.py @@ -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 diff --git a/tests/helpers/test_upload_sender.py b/tests/helpers/test_upload_sender.py index 054974fc..19d6ddea 100644 --- a/tests/helpers/test_upload_sender.py +++ b/tests/helpers/test_upload_sender.py @@ -306,11 +306,13 @@ 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( @@ -318,7 +320,7 @@ def test_upload_sender_result_fail_post_502( ) 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