test: raise tight wall-clock bounds that flaked on loaded CI runners

Seven test files asserted sub-2s wall-clock bounds (elapsed < 0.5/1.0s,
stop(timeout=1.0), event waits of 0.5-2s). Under CI load these fired on
healthy code: main run 33455779041 alone flaked 6 of them in one pass
(observed 1.01s vs 0.5, 1.20s vs 1.0, 3.61s vs 3.0, 1.55s vs 1.0,
stop(1.0) returning False, lease TTL 0.1s expiring before the authority
change was observed).

Per the AGENTS.md flake policy (waits >= 2s), bounds are raised to 5s+
while keeping their teeth: every hang path they guard blocks for 10s+
(release.wait holds), so the loosened bounds still distinguish bounded
from unbounded behavior. The authority-loss test gets a 30s lease TTL so
lease expiry can no longer preempt the authority-change assertion.
This commit is contained in:
Teknium
2026-09-01 09:24:54 -07:00
parent 67de93862c
commit 28834a2098
7 changed files with 61 additions and 55 deletions
+13 -11
View File
@@ -353,18 +353,19 @@ async def test_bare_path_history_lookup_timeout_fails_open(tmp_path, monkeypatch
started = time.monotonic()
await adapter._process_message_background(event, build_session_key(event.source))
# The lookup times out after 0.02s and fails open; the generous 1.0s
# bound only guards against delivery hanging on the wedged read
# indefinitely, without flaking on loaded CI hosts. Delivery of the
# document below is the real fail-open assertion.
assert time.monotonic() - started < 1.0
# The lookup times out after 0.02s and fails open; the bound only guards
# against delivery hanging on the wedged read indefinitely. 1.0s still
# flaked on loaded CI runners (observed 1.55s on main run 33455779041),
# so keep it >= 5s per the flake policy. Delivery of the document below
# is the real fail-open assertion.
assert time.monotonic() - started < 5.0
assert adapter.documents == [str(pdf)]
@pytest.mark.asyncio
async def test_history_lookup_saturation_fails_open_without_new_worker(monkeypatch):
"""Wedged lookups are bounded and cannot consume unbounded worker threads."""
monkeypatch.setattr("gateway.platforms.base._HISTORY_MEDIA_LOOKUP_TIMEOUT_SECONDS", 1.0)
monkeypatch.setattr("gateway.platforms.base._HISTORY_MEDIA_LOOKUP_TIMEOUT_SECONDS", 5.0)
monkeypatch.setattr(
"gateway.platforms.base._HISTORY_MEDIA_LOOKUP_ADMISSION",
threading.BoundedSemaphore(2),
@@ -381,13 +382,13 @@ async def test_history_lookup_saturation_fails_open_without_new_worker(monkeypat
calls += 1
if calls == 2:
two_started.set()
release.wait(timeout=1)
release.wait(timeout=10)
return None
monkeypatch.setattr(adapter, "_history_media_paths_for_session", blocked_lookup)
first = asyncio.create_task(adapter._bounded_history_media_paths_for_session("one"))
second = asyncio.create_task(adapter._bounded_history_media_paths_for_session("two"))
deadline = time.monotonic() + 1
deadline = time.monotonic() + 5
while not two_started.is_set() and time.monotonic() < deadline:
await asyncio.sleep(0.005)
assert two_started.is_set()
@@ -397,9 +398,10 @@ async def test_history_lookup_saturation_fails_open_without_new_worker(monkeypat
elapsed = time.monotonic() - began
assert third is None
# Saturation must fail open immediately (no waiting on the 1.0s lookup
# timeout); 0.5s is a generous bound that stays flake-free on loaded CI.
assert elapsed < 0.5
# Saturation must fail open immediately (no waiting on the 5.0s lookup
# timeout); 2.0s keeps the distinction while staying flake-free on
# loaded CI runners.
assert elapsed < 2.0
assert calls == 2
release.set()
await asyncio.gather(first, second)