Skip to content

Commit 6a7ecd5

Browse files
committed
fix: add connection waiting mechanism for Windows compatibility
1 parent f8072c9 commit 6a7ecd5

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

tests/issues/test_1363_race_condition_streamable_http.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,23 @@ def start_server_process(port: int) -> subprocess.Popen[str]:
141141

142142
process = subprocess.Popen([sys.executable, script_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
143143

144-
# Give server time to start
145-
time.sleep(1)
144+
# Wait for server to be running with connection testing (like other tests)
145+
max_attempts = 20
146+
attempt = 0
147+
while attempt < max_attempts:
148+
try:
149+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
150+
s.connect(("127.0.0.1", port))
151+
break
152+
except ConnectionRefusedError:
153+
time.sleep(0.1)
154+
attempt += 1
155+
else:
156+
# If server failed to start, terminate the process and raise an error
157+
process.terminate()
158+
process.wait()
159+
raise RuntimeError(f"Server failed to start after {max_attempts} attempts")
160+
146161
return process
147162

148163

0 commit comments

Comments
 (0)