Skip to content

The agent that grows with you

test: relay probe waits for the settled reply's send before dropping the socket

Tekniumc54534d3bcf8
diff --git a/tests/gateway/test_relay_authority.py b/tests/gateway/test_relay_authority.py
index cddffcd39bc..04d415fb6f0 100644
--- a/tests/gateway/test_relay_authority.py
+++ b/tests/gateway/test_relay_authority.py
@@ -93,8 +93,12 @@ async def probe(peer):
entries = list(authority.sessions.values())
rows = list_session_admissions(authority.db, session_id=next(iter(authority.sessions)),
pending_only=False) if entries else []
- if any(r['request_id'] == raw_event['message_id'] and r['status'] == 'terminal' for r in rows):
- while adapter._active_sessions:
+ settled = [r for r in rows if r['request_id'] == raw_event['message_id'] and r['status'] == 'terminal']
+ if settled:
+ # The drain hands the reply to the adapter only AFTER the terminal commit
+ # (deliver_settled); the entry leaves pending_deliveries once that send
+ # returned. Closing the connector before then drops the final mid-send.
+ while adapter._active_sessions or settled[0]['admission_id'] in authority.pending_deliveries:
await asyncio.sleep(.01)
assert any(f.get('type') == 'inbound_ack' and f.get('bufferId') == raw_event['message_id']
for f in outgoing), outgoing