Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions tests/test_github_rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,23 @@ def test_mixed_server_and_network_failures_share_budget(monkeypatch):
assert send.call_count == 3


def test_rate_limit_retries_do_not_consume_transient_budget(monkeypatch):
@pytest.mark.parametrize("max_attempts", [5, 7])
def test_rate_limit_retries_do_not_consume_transient_budget(monkeypatch, max_attempts):
# Keep the overall DLT limit explicit: four rate limits followed by two
# transient failures need seven attempts to reach the successful response.
monkeypatch.setenv("RUNTIME__REQUEST_MAX_ATTEMPTS", str(max_attempts))
session, send = _session(monkeypatch, [
*[make_response(429, body={"message": "secondary rate limit"}) for _ in range(4)],
make_response(503), make_response(503), make_response(200),
])

assert session.get("https://api.github.com/example").status_code == 200
assert send.call_count == 7
if max_attempts == 5:
with pytest.raises(HTTPError) as caught:
session.get("https://api.github.com/example")
assert caught.value.response.status_code == 503
else:
assert session.get("https://api.github.com/example").status_code == 200
assert send.call_count == max_attempts


@pytest.mark.parametrize(("status", "headers", "body"), [
Expand Down