Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tests_integ/runtime/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

AGENT_SERVER_ENDPOINT = "http://127.0.0.1:8080"
DEFAULT_PORT = 8080


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


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

try:
Expand All @@ -58,7 +58,7 @@ def start_agent_server(agent_module, timeout=5) -> Generator[Popen, None, None]:
line = line.strip()
if line:
logger.info(line)
if "Uvicorn running on http://127.0.0.1:8080" in line:
if f"Uvicorn running on http://127.0.0.1:{port}" in line:
_start_logging_thread(agent_server.stdout)
yield agent_server
return
Expand Down
4 changes: 2 additions & 2 deletions tests_integ/runtime/test_simple_agent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import textwrap

from tests_integ.runtime.base_test import AGENT_SERVER_ENDPOINT, BaseSDKRuntimeTest, start_agent_server
from tests_integ.runtime.base_test import DEFAULT_PORT, BaseSDKRuntimeTest, start_agent_server
from tests_integ.runtime.http_client import HttpClient

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

def run_test(self):
with start_agent_server(self.agent_module):
client = HttpClient(AGENT_SERVER_ENDPOINT)
client = HttpClient(f"http://127.0.0.1:{DEFAULT_PORT}")

ping_response = client.ping()
logger.info(ping_response)
Expand Down
11 changes: 6 additions & 5 deletions tests_integ/runtime/test_websocket_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

import websockets

from tests_integ.runtime.base_test import AGENT_SERVER_ENDPOINT, BaseSDKRuntimeTest, start_agent_server
from tests_integ.runtime.base_test import BaseSDKRuntimeTest, start_agent_server

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

WEBSOCKET_PORT = 8081


class TestSDKWebSocketAgent(BaseSDKRuntimeTest):
def setup(self):
Expand Down Expand Up @@ -53,14 +55,13 @@ async def websocket_handler(websocket, context):
finally:
await websocket.close()

app.run()
app.run(port=8081)
""").strip()
file.write(content)

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

# Run async WebSocket tests
asyncio.run(self._test_websocket_echo(ws_endpoint))
Expand Down
Loading