Skip to content

Commit

Permalink
Retry test on 502 Bad Gateway (#1737)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wauplin authored Oct 13, 2023
1 parent 866b927 commit 209c1ea
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ def disable_experimental_warnings(monkeypatch: pytest.MonkeyPatch) -> None:

def retry_on_transient_error(fn: CallableT) -> CallableT:
"""
Retry test if failure because of unavailable service or race condition.
Retry test if failure because of unavailable service, bad gateway or race condition.
Tests are retried up to 3 times, waiting 5s between each try.
"""
NUMBER_OF_TRIES = 3
WAIT_TIME = 5
HTTP_ERRORS = (502, 504) # 502 Bad gateway (repo creation) or 504 Gateway timeout

@wraps(fn)
def _inner(*args, **kwargs):
Expand All @@ -101,10 +102,10 @@ def _inner(*args, **kwargs):
except HTTPError as e:
if retry_count >= NUMBER_OF_TRIES:
raise
if e.response.status_code == 504:
if e.response.status_code in HTTP_ERRORS:
logger.info(
f"Attempt {retry_count} failed with a 504 error. Retrying new execution in"
f" {WAIT_TIME} second(s)..."
f"Attempt {retry_count} failed with a {e.response.status_code} error. Retrying new execution"
f" in {WAIT_TIME} second(s)..."
)
else:
raise
Expand Down

0 comments on commit 209c1ea

Please sign in to comment.