Skip to content

Commit 9d29d8c

Browse files
committed
test(e2e): replace fixed WS-readiness sleeps with polls in core e2e tests
test_e2e.py and test_parallel_tool_calls.py both used fixed asyncio.sleep() calls (0.5s–0.8s) as synchronization barriers to wait for WebSocket connections to establish. Under full-suite load these could fail or waste wall-clock time. test_publish_and_chat: poll conn._ws instead of sleep(0.5). test_invoke_capability: poll pub.find_capability() which is the actual readiness condition (WS up + hub round-trip + connection-event processed). test_parallel_tool_calls: poll conn._ws instead of sleep(0.8). Also removed the pre-existing unused `os` import from test_e2e.py.
1 parent d154510 commit 9d29d8c

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

tests/test_e2e.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"""
66

77
import asyncio
8-
import os
98
import socket
109
import threading
1110
import time
@@ -88,7 +87,10 @@ def chat_handler(messages, options):
8887
hub_url=hub,
8988
capabilities={}, # no capabilities exposed
9089
)
91-
await asyncio.sleep(0.5)
90+
for _ in range(50):
91+
if conn._ws is not None:
92+
break
93+
await asyncio.sleep(0.05)
9294

9395
resp = await conn.chat(messages=[{"role": "user", "content": "hello"}])
9496
assert "got: hello" in resp.get("text", "")
@@ -117,18 +119,23 @@ def fake_capability(args):
117119
break
118120
await asyncio.sleep(0.1)
119121

120-
conn = connect(
122+
connect(
121123
ai_name=pub.name,
122124
api_key=pub.api_key,
123125
hub_url=hub,
124126
capabilities={
125127
"test_op": ({"type": "object"}, fake_capability),
126128
},
127129
)
128-
# wait for the connection-event to propagate
129-
await asyncio.sleep(0.8)
130+
# poll until the publisher receives the connection-event carrying the
131+
# capability (WS up + hub round-trip + publisher WS message processed)
132+
cid = None
133+
for _ in range(60):
134+
cid = pub.find_capability("test_op")
135+
if cid is not None:
136+
break
137+
await asyncio.sleep(0.05)
130138

131-
cid = pub.find_capability("test_op")
132139
assert cid is not None, "publisher never saw the capability"
133140

134141
result = await pub.invoke(cid, "test_op", {"hello": "world"})

tests/test_parallel_tool_calls.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ async def slow_b(_args):
120120
"slow_b": ({"type": "object"}, slow_b),
121121
},
122122
)
123-
await asyncio.sleep(0.8)
123+
for _ in range(60):
124+
if conn._ws is not None:
125+
break
126+
await asyncio.sleep(0.05)
124127

125128
t0 = time.monotonic()
126129
async with httpx.AsyncClient(timeout=15.0) as client:

0 commit comments

Comments
 (0)