Skip to content

The agent that grows with you

test(gateway): CI-only timing in the hot-serve and prepare-off-loop probes

Tekniuma91d9663fa8a
diff --git a/tests/gateway/test_multiplex_hot_serve_live.py b/tests/gateway/test_multiplex_hot_serve_live.py
index 130642a018e..6fbfc48f551 100644
--- a/tests/gateway/test_multiplex_hot_serve_live.py
+++ b/tests/gateway/test_multiplex_hot_serve_live.py
@@ -134,6 +134,13 @@ def recorded_served(root):
return json.loads((root / 'gateway_state.json').read_text(encoding='utf-8')).get('served_profiles')
+def wait_recorded(root, predicate, what):
+ """gateway_state.json is written by the runtime-status writer thread after the control reply
+ (publish_runtime_status enqueues, never waits), so the recorded set is eventually consistent."""
+ wait_until(lambda: predicate(recorded_served(root) or []), timeout=20, interval=.05, what=what)
+ return recorded_served(root)
+
+
async def open_session_for(root, home, desc):
"""A ticket bound to *home* opens a session the multiplexer commits into *home*'s state.db."""
grant = control(root, 'session-ticket', {'profile_id': str(home.resolve()),
@@ -166,7 +173,7 @@ def test_profile_created_under_live_multiplexer_is_served_and_owned(mux):
time.sleep(.2)
desc = control(root, 'identify')
assert fresh.resolve() in served_homes(desc), (desc, tail(mux))
- assert recorded_served(root) == ['default', 'boot', 'fresh']
+ assert wait_recorded(root, lambda r: r == ['default', 'boot', 'fresh'], 'fresh recorded') == ['default', 'boot', 'fresh']
# The new profile's sessions are this multiplexer's: same instance, its own state.db.
sid = asyncio.run(open_session_for(root, fresh, desc))
import sqlite3
@@ -288,7 +295,7 @@ def test_invalid_hot_profile_config_is_parked_and_unserved(mux):
assert result['parked'] == ['invalid-hot'], (result, tail(mux))
assert added.resolve() not in served_homes(desc), desc
assert 'invalid-hot' in desc.get('parked_profiles', {}), desc
- assert 'invalid-hot' not in recorded_served(root)
+ wait_recorded(root, lambda r: 'invalid-hot' not in r, 'invalid-hot never recorded')
# The same contract applies to a secondary that was already published and then edited
# into an invalid configuration.
@@ -302,6 +309,6 @@ def test_invalid_hot_profile_config_is_parked_and_unserved(mux):
assert added.resolve() not in served_homes(desc), desc
assert mux['boot'].resolve() not in served_homes(desc), desc
assert 'boot' in desc.get('parked_profiles', {}), desc
- assert 'boot' not in recorded_served(root)
+ wait_recorded(root, lambda r: 'boot' not in r, 'parked boot withdrawn from the recorded set')
finally:
stop(proc, expect=None)
diff --git a/tests/gateway/test_mutation_prepare_off_loop.py b/tests/gateway/test_mutation_prepare_off_loop.py
index ddc13141f66..69ad91ce369 100644
--- a/tests/gateway/test_mutation_prepare_off_loop.py
+++ b/tests/gateway/test_mutation_prepare_off_loop.py
@@ -68,6 +68,9 @@ async def test_model_prepare_waiting_on_a_contended_writer_keeps_the_loop_live(t
now = time.monotonic()
gaps.append(now - last)
last = now
+ # The first dispatch imports the wire-contract registry (a one-time cold import of a few hundred
+ # ms on a loaded runner); warm it so the probe measures the prepare writer wait, not module load.
+ import tui_gateway.contracts.registry
tick = asyncio.create_task(ticker())
try:
await async_wait_until(lambda: gaps, timeout=10, what='the loop-stall probe ticking')