Skip to content

Commit d0f4aea

Browse files
committed
Add api status and use mock in test
Signed-off-by: Junyi Xu <219237550+JunyiXu-nv@users.noreply.github.com>
1 parent 6909e17 commit d0f4aea

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

tensorrt_llm/llmapi/llm.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,13 @@ def shutdown(self) -> None:
766766
self.mpi_session.shutdown()
767767
self.mpi_session = None
768768

769+
@set_api_status("prototype")
769770
def check_health(self) -> bool:
771+
"""Check if the LLM is healthy.
772+
773+
Returns:
774+
bool: True if the executor is running and not shutdown, False otherwise.
775+
"""
770776
if hasattr(self, "_executor") and self._executor is not None:
771777
return not self._executor.is_shutdown()
772778

tests/unittest/api_stability/references/llm.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ methods:
271271
parameters: {}
272272
return_annotation: None
273273
status: beta
274+
check_health:
275+
parameters: {}
276+
return_annotation: bool
277+
status: prototype
274278
properties:
275279
llm_id:
276280
annotation: str

tests/unittest/llmapi/apps/_test_openai_metrics.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Test the metrics endpoint when using OpenAI API to send requests"""
22

3+
from unittest.mock import patch
4+
35
import pytest
46
from fastapi.testclient import TestClient
57

@@ -40,9 +42,12 @@ def client(llm):
4042
(False, 503)])
4143
def test_health(client, llm, is_healthy, response_code):
4244
if not is_healthy:
43-
llm.shutdown()
44-
response = client.get("/health")
45-
assert response.status_code == response_code
45+
with patch.object(llm._executor, 'is_shutdown', return_value=True):
46+
response = client.get("/health")
47+
assert response.status_code == response_code
48+
else:
49+
response = client.get("/health")
50+
assert response.status_code == response_code
4651

4752

4853
def test_version(client):

0 commit comments

Comments
 (0)