|
| 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! |
| 13 | + |
| 14 | +import subprocess |
| 15 | +import socket |
| 16 | +import time |
| 17 | +from typing import List |
| 18 | + |
| 19 | +import pytest |
| 20 | +import requests |
| 21 | + |
| 22 | +from eval_protocol.data_loader.dynamic_data_loader import DynamicDataLoader |
| 23 | +from eval_protocol.models import EvaluationRow, Message, Status |
| 24 | +from eval_protocol.pytest import evaluation_test |
| 25 | +from eval_protocol.pytest.remote_rollout_processor import RemoteRolloutProcessor |
| 26 | + |
| 27 | + |
| 28 | +def find_available_port() -> int: |
| 29 | + """Find an available port on localhost""" |
| 30 | + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: |
| 31 | + s.bind(("", 0)) |
| 32 | + port = s.getsockname()[1] |
| 33 | + return port |
| 34 | + |
| 35 | + |
| 36 | +SERVER_PORT = find_available_port() |
| 37 | + |
| 38 | + |
| 39 | +def wait_for_server_to_startup(timeout: int = 120): |
| 40 | + start_time = time.time() |
| 41 | + while True: |
| 42 | + try: |
| 43 | + requests.get(f"http://127.0.0.1:{SERVER_PORT}") |
| 44 | + break |
| 45 | + except requests.exceptions.RequestException: |
| 46 | + time.sleep(1) |
| 47 | + if time.time() - start_time > timeout: |
| 48 | + raise TimeoutError(f"Server did not start within {timeout} seconds") |
| 49 | + |
| 50 | + |
| 51 | +@pytest.fixture(autouse=True) |
| 52 | +def setup_remote_server(): |
| 53 | + """Start the remote server""" |
| 54 | + # kill all Python processes matching "python -m tests.remote_server.remote_server" |
| 55 | + subprocess.run(["pkill", "-f", "python -m tests.remote_server.remote_server"]) |
| 56 | + |
| 57 | + host = "127.0.0.1" |
| 58 | + process = subprocess.Popen( |
| 59 | + [ |
| 60 | + "python", |
| 61 | + "-m", |
| 62 | + "tests.remote_server.remote_server", |
| 63 | + "--host", |
| 64 | + host, |
| 65 | + "--port", |
| 66 | + str(SERVER_PORT), |
| 67 | + "--force-early-error", |
| 68 | + "test error", |
| 69 | + ] |
| 70 | + ) |
| 71 | + # wait for the server to startup by pollingK |
| 72 | + wait_for_server_to_startup() |
| 73 | + yield |
| 74 | + process.terminate() |
| 75 | + process.wait() |
| 76 | + |
| 77 | + |
| 78 | +def rows() -> List[EvaluationRow]: |
| 79 | + row = EvaluationRow(messages=[Message(role="user", content="What is the capital of France?")]) |
| 80 | + return [row] |
| 81 | + |
| 82 | + |
| 83 | +@pytest.mark.parametrize("completion_params", [{"model": "fireworks_ai/accounts/fireworks/models/gpt-oss-120b"}]) |
| 84 | +@evaluation_test( |
| 85 | + data_loaders=DynamicDataLoader( |
| 86 | + generators=[rows], |
| 87 | + ), |
| 88 | + rollout_processor=RemoteRolloutProcessor( |
| 89 | + remote_base_url=f"http://127.0.0.1:{SERVER_PORT}", |
| 90 | + timeout_seconds=30, |
| 91 | + ), |
| 92 | +) |
| 93 | +async def test_remote_rollout_and_fetch_fireworks_propagate_status(row: EvaluationRow) -> EvaluationRow: |
| 94 | + assert row.rollout_status.code == Status.Code.INTERNAL |
| 95 | + assert row.rollout_status.message == "test error" |
| 96 | + return row |
0 commit comments