feat: isolate live snapshot section deadlines (Closes #1429)
This commit is contained in:
1 parent
065cc46553
commit
dc9e64e98e
2 files changed
+115
-16
No files matched your search
@@ -103,6 +103,87 @@ async def test_live_snapshot_fetches_user_once_and_updates_work_and_activity(mon
|
||||
assert result["revisions"]["context"].endswith(".1")
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_notification_timeout_preserves_healthy_context_and_events(monkeypatch):
|
||||
async def user():
|
||||
return {"id": 1, "login": "timmy"}
|
||||
|
||||
async def empty():
|
||||
return []
|
||||
|
||||
async def events(_authenticated_user):
|
||||
return [{"type": "push"}]
|
||||
|
||||
async def stalled_notifications():
|
||||
await asyncio.Event().wait()
|
||||
|
||||
monkeypatch.setattr(main, "CONTEXT_TIMEOUT_SECONDS", 0.01)
|
||||
monkeypatch.setattr(main, "current_user", user)
|
||||
monkeypatch.setattr(main, "repos", empty)
|
||||
monkeypatch.setattr(main, "issues", empty)
|
||||
monkeypatch.setattr(main, "pull_requests", empty)
|
||||
monkeypatch.setattr(main, "activity_events", events)
|
||||
monkeypatch.setattr(main, "notifications", stalled_notifications)
|
||||
|
||||
response = await main.live_snapshot()
|
||||
result = payload(response)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert result["context"]["user"]["login"] == "timmy"
|
||||
assert result["events"] == [{"type": "push"}]
|
||||
assert result["notifications"] is None
|
||||
assert result["sections"] == {
|
||||
"context": "fresh",
|
||||
"events": "fresh",
|
||||
"notifications": "temporarily unavailable",
|
||||
}
|
||||
assert result["freshness"]["sections"]["context"]["degraded"] is False
|
||||
assert result["freshness"]["sections"]["events"]["degraded"] is False
|
||||
assert result["freshness"]["sections"]["notifications"]["degraded"] is True
|
||||
assert main._live_section_failure_count == {
|
||||
"context": 0,
|
||||
"events": 0,
|
||||
"notifications": 1,
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_identity_timeout_preserves_independent_notifications(monkeypatch):
|
||||
identity_cancelled = asyncio.Event()
|
||||
|
||||
async def stalled_user():
|
||||
try:
|
||||
await asyncio.Event().wait()
|
||||
finally:
|
||||
identity_cancelled.set()
|
||||
|
||||
async def updates():
|
||||
return [{"id": 42, "title": "Mentioned you"}]
|
||||
|
||||
monkeypatch.setattr(main, "CONTEXT_TIMEOUT_SECONDS", 0.01)
|
||||
monkeypatch.setattr(main, "current_user", stalled_user)
|
||||
monkeypatch.setattr(main, "notifications", updates)
|
||||
|
||||
response = await main.live_snapshot()
|
||||
result = payload(response)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert result["context"] is None
|
||||
assert result["events"] is None
|
||||
assert result["notifications"] == [{"id": 42, "title": "Mentioned you"}]
|
||||
assert result["sections"] == {
|
||||
"context": "temporarily unavailable",
|
||||
"events": "temporarily unavailable",
|
||||
"notifications": "fresh",
|
||||
}
|
||||
assert main._live_section_failure_count == {
|
||||
"context": 1,
|
||||
"events": 1,
|
||||
"notifications": 0,
|
||||
}
|
||||
await asyncio.wait_for(identity_cancelled.wait(), timeout=0.1)
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_live_snapshot_omits_section_bodies_at_known_revisions(monkeypatch):
|
||||
async def user():
|
||||
|
||||
Reference in new issue
Block a user