Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion proofline/_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ def check_stream(size: int, status: int, deadline: float) -> None:
)
budget = remaining()
if monotonic() >= deadline or (budget is not None and budget <= 0):
if 200 <= status < 300:
# Retryable statuses time out as an expired read does; other problems keep their status.
if 200 <= status < 300 or status in (429, 503):
raise timeout_error()
raise unreadable_problem(status)

Expand Down
30 changes: 30 additions & 0 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,36 @@ async def test_retry_after_is_bounded_by_wait_deadline(mode: str) -> None:
assert len(server.requests) == 1


@MODES
@pytest.mark.parametrize("status", [429, 503, 403])
async def test_deadline_expiring_with_a_received_problem_chunk_keeps_retry_policy(
mode: str, status: int, monkeypatch: pytest.MonkeyPatch
) -> None:
clock = Clock(monkeypatch)
checked = _transport.check_stream

def late(size: int, response_status: int, deadline: float) -> None:
# The wait deadline passes while a received body chunk is still being checked.
clock.now += 10
checked(size, response_status, deadline)

monkeypatch.setattr(_transport, "check_stream", late)
with Server(
lambda request, index: Reply(status, {"detail": PRIVATE}, {"Retry-After": "2"})
) as server:
async with session(mode, server.url) as client:
if status == 403:
with pytest.raises(ProoflineError) as raised:
await call(client, "wait_for_review", ORG, REVIEW, timeout=1)
assert raised.value.status == 403
else:
result = await call(client, "wait_for_review", ORG, REVIEW, timeout=1)
assert result.status == "TIMED_OUT"
assert result.review_url == f"{server.url}/orgs/by-id/{ORG}/reviews/{REVIEW}"
assert len(server.requests) == 1
assert clock.delays == []


@MODES
@pytest.mark.parametrize("status", [200, 403])
async def test_body_stream_deadline_does_not_turn_authority_into_timeout(
Expand Down
Loading