diff options
| author | Christian Cleberg <[email protected]> | 2026-04-11 21:32:49 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-04-11 21:32:49 -0500 |
| commit | 533866679755bd6e7a97cfa0f050eaa832b0b373 (patch) | |
| tree | 8f2ca7dd89661be972cd5750ed991862aa0fe8da /tests/test_srht_client.py | |
| parent | fe5efeb33639e963029c3a118ccc2e98bafccb58 (diff) | |
| download | hutch-stats-533866679755bd6e7a97cfa0f050eaa832b0b373.tar.gz hutch-stats-533866679755bd6e7a97cfa0f050eaa832b0b373.tar.bz2 hutch-stats-533866679755bd6e7a97cfa0f050eaa832b0b373.zip | |
fix: reduce sr.ht poll API load with cached repo discovery
Diffstat (limited to 'tests/test_srht_client.py')
| -rw-r--r-- | tests/test_srht_client.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/test_srht_client.py b/tests/test_srht_client.py index e7ece0d..b4586e5 100644 --- a/tests/test_srht_client.py +++ b/tests/test_srht_client.py @@ -54,3 +54,29 @@ def test_graphql_client_raises_for_network_errors() -> None: client.execute("query Ping { ping }") client.close() + + +def test_graphql_client_applies_request_delay_and_retry_backoff(monkeypatch: pytest.MonkeyPatch) -> None: + attempts = {"count": 0} + sleeps: list[float] = [] + + def handler(request: httpx.Request) -> httpx.Response: + attempts["count"] += 1 + if attempts["count"] < 3: + return httpx.Response(502, json={"error": "bad gateway"}) + return httpx.Response(200, json={"data": {"ok": True}}) + + monkeypatch.setattr("srht_contrib.services.srht_client.time.sleep", sleeps.append) + client = SourceHutGraphQLClient( + "https://todo.sr.ht/query", + "token", + max_retries=2, + request_delay=0.5, + transport=httpx.MockTransport(handler), + ) + + data = client.execute("query Ping { ping }") + + assert data == {"ok": True} + assert sleeps == [0.5, 1, 2] + client.close() |
