Skip to content

Commit f681112

Browse files
committed
[Test] Add test for health endpoint 503 status on engine death
Signed-off-by: dongbo910220 <1275604947@qq.com>
1 parent a332b84 commit f681112

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
@@ -220,3 +223,24 @@ def make_long_completion_request():
220223
response = requests.get(server.url_for("load"))
221224
assert response.status_code == HTTPStatus.OK
222225
assert response.json().get("server_load") == 0
226+
227+
228+
@pytest.mark.asyncio
229+
async def test_health_check_engine_dead_error():
230+
# Import the health function directly to test it in isolation
231+
from vllm.entrypoints.openai.api_server import health
232+
233+
# Create a mock request that simulates what FastAPI would provide
234+
mock_request = Mock(spec=Request)
235+
mock_app_state = Mock()
236+
mock_engine_client = AsyncMock()
237+
mock_engine_client.check_health.side_effect = EngineDeadError()
238+
mock_app_state.engine_client = mock_engine_client
239+
mock_request.app.state = mock_app_state
240+
241+
# Test the health function directly with our mocked request
242+
# This simulates what would happen if the engine dies
243+
response = await health(mock_request)
244+
245+
# Assert that it returns 503 Service Unavailable
246+
assert response.status_code == 503

0 commit comments

Comments
 (0)