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
2 changes: 1 addition & 1 deletion sonar-baseline.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
25
8
12 changes: 10 additions & 2 deletions tests/fastapi/test_log_tail_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
API = "/sharpit/api/log-tail"
STREAM = f"{API}/stream"
UVICORN_LOGGERS = ("uvicorn", "uvicorn.error", "uvicorn.access")
EMPTY_STREAMS = 3 # consecutive streams with no line before _ids treats the replay as complete


def _client(app: Any) -> TestClient:
Expand Down Expand Up @@ -175,12 +176,19 @@ def test_stream_replays_then_ends_with_retry():

def _ids(client: TestClient, **kw: Any) -> list[str]:
"""Log ids as EventSource reads them: a stream may end mid-replay (spec §10), so reconnect with the last id seen
as Last-Event-ID until a stream brings no line. Bounded: a resume that repeats lines shows up as duplicates."""
as Last-Event-ID until ``EMPTY_STREAMS`` streams in a row bring no line. One empty stream is not the end: on a
loaded runner a stream can time out before its first frame (CI run 45296913127). Bounded: a resume that repeats
lines shows up as duplicates."""
ids: list[str] = []
empty = 0
for _ in range(20):
batch = [e["id"] for e in _events(client.get(f"{API}/stream", **kw).text) if e.get("event") == "log"]
if not batch:
break
empty += 1
if empty == EMPTY_STREAMS:
break
continue
empty = 0
ids += batch
kw = {**kw, "headers": {**kw.get("headers", {}), "Last-Event-ID": batch[-1]}}
return ids
Expand Down