The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(gateway): loop-heartbeat probes use pairwise and annotate the measured sleeps
Tekniumb7e40d548168
diff --git a/tests/gateway/test_managed_worker_reservation_off_loop.py b/tests/gateway/test_managed_worker_reservation_off_loop.pyindex 41dcb599c83..569e78d02d6 100644--- a/tests/gateway/test_managed_worker_reservation_off_loop.py+++ b/tests/gateway/test_managed_worker_reservation_off_loop.py@@ -2,6 +2,7 @@writer held by another process (up to _WRITE_PATIENCE_S) must not freeze every other session,timer, socket and Stop on the loop. Real child, real SQLite, a real competing writer."""import asyncio+from itertools import pairwiseimport sqlite3import subprocessimport sys@@ -12,6 +13,7 @@ from types import SimpleNamespaceimport pytestfrom gateway.session_contract import Principal, SessionRef+from tests.waiting import wait_untilCHILD = """import json, os, sys, time, psutilme = psutil.Process()@@ -63,12 +65,11 @@ def test_reservation_and_loss_writes_never_block_the_loop(tmp_path, monkeypatch,def competing_writer():if held_during == 'lose':- while not bootstrapped.exists():- time.sleep(.01)+ wait_until(bootstrapped.exists, timeout=30, what='the worker to receive its bootstrap')rival = sqlite3.connect(tmp_path / 'state.db', isolation_level=None)rival.execute('BEGIN IMMEDIATE')held.set()- time.sleep(HOLD_S)+ time.sleep(HOLD_S) # health: allow HX013 -- the held writer's duration IS the behaviour under testrival.execute('ROLLBACK')rival.close()@@ -84,7 +85,7 @@ def test_reservation_and_loss_writes_never_block_the_loop(tmp_path, monkeypatch,async def ticker():while True:ticks.append(time.monotonic())- await asyncio.sleep(.05)+ await asyncio.sleep(.05) # health: allow HX013 -- the loop heartbeat probe; its gaps are the measurementbeat = asyncio.create_task(ticker())try:async with asyncio.timeout(60):@@ -94,7 +95,7 @@ def test_reservation_and_loss_writes_never_block_the_loop(tmp_path, monkeypatch,finally:beat.cancel()await asyncio.to_thread(writer.join, 10)- return row, max(b - a for a, b in zip(ticks, ticks[1:]))+ return row, max(b - a for a, b in pairwise(ticks))with db:row, gap = asyncio.run(scenario())status = db._read_one('SELECT status FROM session_admissions WHERE admission_id=?', (row['admission_id'],))[0]diff --git a/tests/gateway/test_session_kanban_run_off_loop.py b/tests/gateway/test_session_kanban_run_off_loop.pyindex 3c93600b13d..44614233174 100644--- a/tests/gateway/test_session_kanban_run_off_loop.py+++ b/tests/gateway/test_session_kanban_run_off_loop.py@@ -2,6 +2,7 @@Kanban DB is the cross-profile dispatch bus (busy_timeout up to 120 s), so a dispatcher holdingits writer must not freeze every session on the loop. Real Kanban SQLite, a real held writer."""import asyncio+from itertools import pairwisefrom contextlib import closingimport sqlite3import threading@@ -54,7 +55,7 @@ def test_run_task_kanban_write_never_blocks_the_loop(tmp_path, monkeypatch):rival = sqlite3.connect(board_db, isolation_level=None)rival.execute('BEGIN IMMEDIATE')held.set()- time.sleep(HOLD_S)+ time.sleep(HOLD_S) # health: allow HX013 -- the held writer's duration IS the behaviour under testrival.execute('ROLLBACK')rival.close()monkeypatch.setattr('gateway.session_kanban.asdict', lambda receipt: {})@@ -68,7 +69,7 @@ def test_run_task_kanban_write_never_blocks_the_loop(tmp_path, monkeypatch):async def ticker():while True:ticks.append(time.monotonic())- await asyncio.sleep(.05)+ await asyncio.sleep(.05) # health: allow HX013 -- the loop heartbeat probe; its gaps are the measurementbeat = asyncio.create_task(ticker())try:async with asyncio.timeout(30):@@ -77,7 +78,7 @@ def test_run_task_kanban_write_never_blocks_the_loop(tmp_path, monkeypatch):beat.cancel()ticks.append(time.monotonic()) # a loop blocked from the first tick still yields one gapawait asyncio.to_thread(writer.join, 10)- return max(b - a for a, b in zip(ticks, ticks[1:]))+ return max(b - a for a, b in pairwise(ticks))gap = asyncio.run(scenario())assert calls == ['resume', 'submit']with closing(connect(board='owned')) as conn: