A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 14, 05:30 UTC
[Test] Add test for /health endpoint on engine failure (#26074)
[Test] Add test for /health endpoint on engine failure (#26074) Signed-off-by: dongbo910220 <1275604947@qq.com>
dongbo910220 committed
Oct 18, 2025 at 17:59 UTC
83004020fd2400f56df2686e8c55df3d9fc79b7b
1 file changed
+24
tests/entrypoints/openai/test_basic.py
+24
@@ -3,12 +3,15 @@
3
4
import asyncio
5
from http import HTTPStatus
6
+from unittest.mock import AsyncMock, Mock
7
8
import openai
9
import pytest
10
import pytest_asyncio
11
import requests
12
+from fastapi import Request
13
14
+from vllm.v1.engine.exceptions import EngineDeadError
15
from vllm.version import __version__ as VLLM_VERSION
16
17
from ...utils import RemoteOpenAIServer
@@ -224,3 +227,24 @@ async def test_server_load(server: RemoteOpenAIServer):
227
response = requests.get(server.url_for("load"))
228
assert response.status_code == HTTPStatus.OK
229
assert response.json().get("server_load") == 0
230
+
231
+
232
+@pytest.mark.asyncio
233
+async def test_health_check_engine_dead_error():
234
+ # Import the health function directly to test it in isolation
235
+ from vllm.entrypoints.openai.api_server import health
236
+
237
+ # Create a mock request that simulates what FastAPI would provide
238
+ mock_request = Mock(spec=Request)
239
+ mock_app_state = Mock()
240
+ mock_engine_client = AsyncMock()
241
+ mock_engine_client.check_health.side_effect = EngineDeadError()
242
+ mock_app_state.engine_client = mock_engine_client
243
+ mock_request.app.state = mock_app_state
244
+
245
+ # Test the health function directly with our mocked request
246
+ # This simulates what would happen if the engine dies
247
+ response = await health(mock_request)
248
+
249
+ # Assert that it returns 503 Service Unavailable
250
+ assert response.status_code == 503