MCPcopy
hub / github.com/ray-project/ray / mock_server

Function mock_server

python/ray/llm/tests/serve/benchmark/conftest.py:100–123  ·  view source on GitHub ↗

Start a mock SSE server in a background thread and yield its base URL.

(free_port: int)

Source from the content-addressed store, hash-verified

98
99@pytest.fixture()
100def mock_server(free_port: int) -> Generator[str, None, None]:
101 """Start a mock SSE server in a background thread and yield its base URL."""
102 port = free_port
103 app = aiohttp.web.Application()
104 app.router.add_post("/v1/chat/completions", mock_chat_handler)
105
106 loop = asyncio.new_event_loop()
107 runner = aiohttp.web.AppRunner(app)
108 loop.run_until_complete(runner.setup())
109
110 started = threading.Event()
111 thread = threading.Thread(
112 target=_run_server, args=(loop, runner, port, started), daemon=True
113 )
114 thread.start()
115 assert started.wait(timeout=5), "Mock server failed to start"
116
117 base_url = f"http://127.0.0.1:{port}"
118 yield base_url
119
120 loop.call_soon_threadsafe(loop.stop)
121 thread.join(timeout=5)
122 loop.run_until_complete(runner.cleanup())
123 loop.close()

Callers

nothing calls this directly

Calls 7

ApplicationMethod · 0.80
waitMethod · 0.65
setupMethod · 0.45
startMethod · 0.45
joinMethod · 0.45
cleanupMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…