|
1 | | -# MANUAL SERVER STARTUP REQUIRED: |
2 | | -# |
3 | | -# For Python server testing, start: |
4 | | -# python -m tests.remote_server.remote_server (runs on http://127.0.0.1:3000) |
5 | | -# |
6 | | -# For TypeScript server testing, start: |
7 | | -# cd tests/remote_server/typescript-server |
8 | | -# npm install |
9 | | -# npm start |
10 | | -# |
11 | | -# The TypeScript server should be running on http://127.0.0.1:3000 |
12 | | -# You only need to start one of the servers! |
| 1 | +# AUTO SERVER STARTUP: Server is automatically started and stopped by the test |
13 | 2 |
|
14 | 3 | import os |
| 4 | +import subprocess |
| 5 | +import socket |
| 6 | +import time |
15 | 7 | from typing import List |
16 | 8 |
|
17 | 9 | import pytest |
| 10 | +import requests |
18 | 11 |
|
19 | 12 | from eval_protocol.data_loader.dynamic_data_loader import DynamicDataLoader |
20 | 13 | from eval_protocol.models import EvaluationRow, Message |
|
27 | 20 | ROLLOUT_IDS = set() |
28 | 21 |
|
29 | 22 |
|
| 23 | +def find_available_port() -> int: |
| 24 | + """Find an available port on localhost""" |
| 25 | + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: |
| 26 | + s.bind(("", 0)) |
| 27 | + port = s.getsockname()[1] |
| 28 | + return port |
| 29 | + |
| 30 | + |
| 31 | +SERVER_PORT = find_available_port() |
| 32 | + |
| 33 | + |
| 34 | +def wait_for_server_to_startup(timeout: int = 120): |
| 35 | + start_time = time.time() |
| 36 | + while True: |
| 37 | + try: |
| 38 | + requests.get(f"http://127.0.0.1:{SERVER_PORT}") |
| 39 | + break |
| 40 | + except requests.exceptions.RequestException: |
| 41 | + time.sleep(1) |
| 42 | + if time.time() - start_time > timeout: |
| 43 | + raise TimeoutError(f"Server did not start within {timeout} seconds") |
| 44 | + |
| 45 | + |
| 46 | +@pytest.fixture(autouse=True) |
| 47 | +def setup_remote_server(): |
| 48 | + """Start the remote server""" |
| 49 | + # kill all Python processes matching "python -m tests.remote_server.remote_server" |
| 50 | + subprocess.run(["pkill", "-f", "python -m tests.remote_server.remote_server"], capture_output=True) |
| 51 | + |
| 52 | + host = "127.0.0.1" |
| 53 | + process = subprocess.Popen( |
| 54 | + [ |
| 55 | + "python", |
| 56 | + "-m", |
| 57 | + "tests.remote_server.remote_server", |
| 58 | + "--host", |
| 59 | + host, |
| 60 | + "--port", |
| 61 | + str(SERVER_PORT), |
| 62 | + ] |
| 63 | + ) |
| 64 | + # wait for the server to startup by polling |
| 65 | + wait_for_server_to_startup() |
| 66 | + yield |
| 67 | + process.terminate() |
| 68 | + process.wait() |
| 69 | + |
| 70 | + |
30 | 71 | @pytest.fixture(autouse=True) |
31 | 72 | def check_rollout_coverage(): |
32 | 73 | """Ensure we processed all expected rollout_ids""" |
@@ -64,15 +105,15 @@ def rows() -> List[EvaluationRow]: |
64 | 105 | generators=[rows], |
65 | 106 | ), |
66 | 107 | rollout_processor=RemoteRolloutProcessor( |
67 | | - remote_base_url="http://127.0.0.1:3000", |
| 108 | + remote_base_url=f"http://127.0.0.1:{SERVER_PORT}", |
68 | 109 | timeout_seconds=180, |
69 | 110 | output_data_loader=fireworks_output_data_loader, |
70 | 111 | ), |
71 | 112 | ) |
72 | 113 | async def test_remote_rollout_and_fetch_fireworks(row: EvaluationRow) -> EvaluationRow: |
73 | 114 | """ |
74 | 115 | End-to-end test: |
75 | | - - REQUIRES MANUAL SERVER STARTUP: python -m tests.remote_server.remote_server |
| 116 | + - AUTO SERVER STARTUP: Server is automatically started and stopped by the test |
76 | 117 | - trigger remote rollout via RemoteRolloutProcessor (calls init/status) |
77 | 118 | - fetch traces from Langfuse via Fireworks tracing proxy filtered by metadata via output_data_loader; FAIL if none found |
78 | 119 | """ |
|
0 commit comments