Skip to content

Commit ac560ec

Browse files
dongbo910220albertoperdomo2
authored andcommitted
[Test] Add test for /health endpoint on engine failure (vllm-project#26074)
Signed-off-by: dongbo910220 <1275604947@qq.com> Signed-off-by: Alberto Perdomo <aperdomo@redhat.com>
1 parent 7b4407b commit ac560ec

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/entrypoints/openai/test_basic.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33

44
import asyncio
55
from http import HTTPStatus
6+
from unittest.mock import AsyncMock, Mock
67

78
import openai
89
import pytest
910
import pytest_asyncio
1011
import requests
12+
from fastapi import Request
1113

14+
from vllm.v1.engine.exceptions import EngineDeadError
1215
from vllm.version import __version__ as VLLM_VERSION
1316

1417
from ...utils import RemoteOpenAIServer
@@ -224,3 +227,24 @@ def make_long_completion_request():
224227
response = requests.get(server.url_for("load"))
225228
assert response.status_code == HTTPStatus.OK
226229
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

0 commit comments

Comments
 (0)