Skip to content

Commit 03b599a

Browse files
authored
fix: use separate ports for runtime integ tests to avoid parallel conflicts (aws#332)
1 parent 4470447 commit 03b599a

3 files changed

Lines changed: 12 additions & 11 deletions

File tree

tests_integ/runtime/base_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
logger = logging.getLogger("sdk-runtime-base-test")
1212

13-
AGENT_SERVER_ENDPOINT = "http://127.0.0.1:8080"
13+
DEFAULT_PORT = 8080
1414

1515

1616
class BaseSDKRuntimeTest(ABC):
@@ -36,8 +36,8 @@ def run_test(self) -> None:
3636

3737

3838
@contextmanager
39-
def start_agent_server(agent_module, timeout=5) -> Generator[Popen, None, None]:
40-
logger.info("Starting agent server...")
39+
def start_agent_server(agent_module, port=DEFAULT_PORT, timeout=5) -> Generator[Popen, None, None]:
40+
logger.info("Starting agent server on port %d...", port)
4141
start_time = time.time()
4242

4343
try:
@@ -58,7 +58,7 @@ def start_agent_server(agent_module, timeout=5) -> Generator[Popen, None, None]:
5858
line = line.strip()
5959
if line:
6060
logger.info(line)
61-
if "Uvicorn running on http://127.0.0.1:8080" in line:
61+
if f"Uvicorn running on http://127.0.0.1:{port}" in line:
6262
_start_logging_thread(agent_server.stdout)
6363
yield agent_server
6464
return

tests_integ/runtime/test_simple_agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
import textwrap
33

4-
from tests_integ.runtime.base_test import AGENT_SERVER_ENDPOINT, BaseSDKRuntimeTest, start_agent_server
4+
from tests_integ.runtime.base_test import DEFAULT_PORT, BaseSDKRuntimeTest, start_agent_server
55
from tests_integ.runtime.http_client import HttpClient
66

77
logger = logging.getLogger("sdk-runtime-simple-agent-test")
@@ -28,7 +28,7 @@ async def agent_invocation(payload):
2828

2929
def run_test(self):
3030
with start_agent_server(self.agent_module):
31-
client = HttpClient(AGENT_SERVER_ENDPOINT)
31+
client = HttpClient(f"http://127.0.0.1:{DEFAULT_PORT}")
3232

3333
ping_response = client.ping()
3434
logger.info(ping_response)

tests_integ/runtime/test_websocket_agent.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
import websockets
77

8-
from tests_integ.runtime.base_test import AGENT_SERVER_ENDPOINT, BaseSDKRuntimeTest, start_agent_server
8+
from tests_integ.runtime.base_test import BaseSDKRuntimeTest, start_agent_server
99

1010
logger = logging.getLogger("sdk-runtime-websocket-test")
1111

12+
WEBSOCKET_PORT = 8081
13+
1214

1315
class TestSDKWebSocketAgent(BaseSDKRuntimeTest):
1416
def setup(self):
@@ -53,14 +55,13 @@ async def websocket_handler(websocket, context):
5355
finally:
5456
await websocket.close()
5557
56-
app.run()
58+
app.run(port=8081)
5759
""").strip()
5860
file.write(content)
5961

6062
def run_test(self):
61-
with start_agent_server(self.agent_module):
62-
# Replace http:// with ws:// for WebSocket connection
63-
ws_endpoint = AGENT_SERVER_ENDPOINT.replace("http://", "ws://") + "/ws"
63+
with start_agent_server(self.agent_module, port=WEBSOCKET_PORT):
64+
ws_endpoint = f"ws://127.0.0.1:{WEBSOCKET_PORT}/ws"
6465

6566
# Run async WebSocket tests
6667
asyncio.run(self._test_websocket_echo(ws_endpoint))

0 commit comments

Comments
 (0)