fix: bound context fallback latency (#30)
CI / lint (pull_request) Successful in 9s
CI / build-frontend (pull_request) Successful in 4s

This commit is contained in:
timmy committed 2026-08-05 08:02:39 +00:00
1 parent 426c0645f9
commit 286680c053
2 files changed
+45 -5

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
import asyncio
import pytest
from src import main
@pytest.mark.anyio
async def test_context_returns_fallback_when_gitea_exceeds_deadline(monkeypatch):
cancelled = asyncio.Event()
async def hanging_current_user():
try:
await asyncio.Event().wait()
finally:
cancelled.set()
async def empty_collection():
return []
monkeypatch.setattr(main, "CONTEXT_TIMEOUT_SECONDS", 0.01)
monkeypatch.setattr(main, "current_user", hanging_current_user)
monkeypatch.setattr(main, "repos", empty_collection)
monkeypatch.setattr(main, "issues", empty_collection)
monkeypatch.setattr(main, "pull_requests", empty_collection)
response = await main.context()
assert response.status_code == 200
assert b'"repos":[]' in response.body
assert b'"error":"Gitea context request timed out after 0.01s"' in response.body
assert cancelled.is_set()