Skip to content

Commit c0f87f4

Browse files
committed
try new port
1 parent 071f5c4 commit c0f87f4

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

tests/pytest/test_mcp_session_autocreate.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
without requiring a prior initial state fetch, and returns JSON.
44
"""
55

6+
import socket
67
import time
7-
from multiprocessing import Process
8+
from multiprocessing import Process, Queue
89

910
import httpx
1011
import pytest
@@ -13,10 +14,16 @@
1314
from eval_protocol.types import MCPSession
1415

1516

16-
def _run_airline_server():
17+
def _run_airline_server(port_queue):
1718
import os
1819

19-
os.environ["PORT"] = "9700"
20+
# Use dynamic port allocation to avoid conflicts in parallel CI runs
21+
with socket.socket() as s:
22+
s.bind(("", 0))
23+
port = s.getsockname()[1]
24+
25+
port_queue.put(port) # Send the port back to the test
26+
os.environ["PORT"] = str(port)
2027
from eval_protocol.mcp_servers.tau2.tau2_mcp import AirlineDomainMcp
2128

2229
server = AirlineDomainMcp(seed=None)
@@ -25,11 +32,14 @@ def _run_airline_server():
2532

2633
@pytest.mark.asyncio
2734
async def test_tool_call_returns_json_without_prior_initial_state():
28-
proc = Process(target=_run_airline_server, daemon=True)
35+
port_queue = Queue()
36+
proc = Process(target=_run_airline_server, args=(port_queue,), daemon=True)
2937
proc.start()
3038

3139
try:
32-
base_url = "http://127.0.0.1:9700/mcp"
40+
# Get the dynamically assigned port
41+
port = port_queue.get(timeout=10)
42+
base_url = f"http://127.0.0.1:{port}/mcp"
3343
client = httpx.Client(timeout=1.0)
3444
deadline = time.time() + 20
3545
while time.time() < deadline:
@@ -41,7 +51,7 @@ async def test_tool_call_returns_json_without_prior_initial_state():
4151
pass
4252
time.sleep(0.2)
4353
else:
44-
pytest.fail("Server did not start on port 9700 in time")
54+
pytest.fail(f"Server did not start on port {port} in time")
4555

4656
session = MCPSession(base_url=base_url, session_id="test-autocreate", seed=None, model_id="test-model")
4757

0 commit comments

Comments
 (0)