Skip to content

Commit df4f14e

Browse files
committed
Append shutdown/wait‐related tests from main into clean_logs
1 parent 7d79d76 commit df4f14e

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

tests/vec_inf/client/test_api.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66

77
from vec_inf.client import ModelStatus, ModelType, VecInfClient
8+
from vec_inf.client._exceptions import ServerError, SlurmJobError
89

910

1011
@pytest.fixture
@@ -199,3 +200,84 @@ def test_cleanup_logs_matching_dirs_dry_run(tmp_path):
199200
assert deleted == [model_a_1]
200201
assert model_a_1.exists()
201202
assert model_a_2.exists()
203+
204+
205+
def test_shutdown_model_success():
206+
"""Test model shutdown success."""
207+
client = VecInfClient()
208+
with patch("vec_inf.client.api.run_bash_command") as mock_command:
209+
mock_command.return_value = ("", "")
210+
result = client.shutdown_model(12345)
211+
212+
assert result is True
213+
mock_command.assert_called_once_with("scancel 12345")
214+
215+
216+
def test_shutdown_model_failure():
217+
"""Test model shutdown failure."""
218+
client = VecInfClient()
219+
with patch("vec_inf.client.api.run_bash_command") as mock_command:
220+
mock_command.return_value = ("", "Error: Job not found")
221+
with pytest.raises(
222+
SlurmJobError, match="Failed to shutdown model: Error: Job not found"
223+
):
224+
client.shutdown_model(12345)
225+
226+
227+
def test_wait_until_ready_timeout():
228+
"""Test timeout in wait_until_ready."""
229+
client = VecInfClient()
230+
231+
with patch.object(client, "get_status") as mock_status:
232+
mock_response = MagicMock()
233+
mock_response.server_status = ModelStatus.LAUNCHING
234+
mock_status.return_value = mock_response
235+
236+
with (
237+
patch("time.sleep"),
238+
pytest.raises(ServerError, match="Timed out waiting for model"),
239+
):
240+
client.wait_until_ready(12345, timeout_seconds=1, poll_interval_seconds=0.5)
241+
242+
243+
def test_wait_until_ready_failed_status():
244+
"""Test wait_until_ready when model fails."""
245+
client = VecInfClient()
246+
247+
with patch.object(client, "get_status") as mock_status:
248+
mock_response = MagicMock()
249+
mock_response.server_status = ModelStatus.FAILED
250+
mock_response.failed_reason = "Out of memory"
251+
mock_status.return_value = mock_response
252+
253+
with pytest.raises(ServerError, match="Model failed to start: Out of memory"):
254+
client.wait_until_ready(12345)
255+
256+
257+
def test_wait_until_ready_failed_no_reason():
258+
"""Test wait_until_ready when model fails without reason."""
259+
client = VecInfClient()
260+
261+
with patch.object(client, "get_status") as mock_status:
262+
mock_response = MagicMock()
263+
mock_response.server_status = ModelStatus.FAILED
264+
mock_response.failed_reason = None
265+
mock_status.return_value = mock_response
266+
267+
with pytest.raises(ServerError, match="Model failed to start: Unknown error"):
268+
client.wait_until_ready(12345)
269+
270+
271+
def test_wait_until_ready_shutdown():
272+
"""Test wait_until_ready when model is shutdown."""
273+
client = VecInfClient()
274+
275+
with patch.object(client, "get_status") as mock_status:
276+
mock_response = MagicMock()
277+
mock_response.server_status = ModelStatus.SHUTDOWN
278+
mock_status.return_value = mock_response
279+
280+
with pytest.raises(
281+
ServerError, match="Model was shutdown before it became ready"
282+
):
283+
client.wait_until_ready(12345)

0 commit comments

Comments
 (0)