diff --git a/tests/v1/engine/test_async_llm.py b/tests/v1/engine/test_async_llm.py index 3ae6293972..33a9d67202 100644 --- a/tests/v1/engine/test_async_llm.py +++ b/tests/v1/engine/test_async_llm.py @@ -369,3 +369,32 @@ async def test_dp_rank_argument(monkeypatch: pytest.MonkeyPatch): sampling_params=sampling_params, data_parallel_rank=1): pass + + +@pytest.mark.asyncio +async def test_check_health(monkeypatch: pytest.MonkeyPatch): + """Test that check_health returns normally for healthy engine + and raises EngineDeadError when the engine is dead. + """ + from unittest.mock import patch + + from vllm.v1.engine.exceptions import EngineDeadError + + with monkeypatch.context() as m, ExitStack() as after: + m.setenv("VLLM_USE_V1", "1") + + engine = AsyncLLM.from_engine_args(TEXT_ENGINE_ARGS) + after.callback(engine.shutdown) + + # Test 1: Healthy engine should not raise any exception + await engine.check_health() + + # Test 2: Mock the errored property to simulate a dead engine + with patch.object(type(engine), + 'errored', + new_callable=lambda: property(lambda self: True) + ), pytest.raises(EngineDeadError): + await engine.check_health() + + # Test 3: Verify healthy engine still works after mock + await engine.check_health() diff --git a/vllm/v1/engine/async_llm.py b/vllm/v1/engine/async_llm.py index 998c4c5ea3..3754570dfa 100644 --- a/vllm/v1/engine/async_llm.py +++ b/vllm/v1/engine/async_llm.py @@ -552,6 +552,8 @@ class AsyncLLM(EngineClient): async def check_health(self) -> None: logger.debug("Called check_health.") + if self.errored: + raise self.dead_error async def start_profile(self) -> None: await self.engine_core.profile_async(True)