Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 3 additions & 52 deletions tests/unit/backends/vllm_utils/test_vllm_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def fake_post(endpoint: str, payload: dict, timeout: float):
assert len(calls) == 1
assert calls[0][0] == "start_weight_update"
assert calls[0][1] == {"is_checkpoint_format": True}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instead of completely removing the timeout assertion, we should verify that the default timeout of 900.0 seconds is correctly passed to the _post_json call.

Suggested change
assert calls[0][1] == {"is_checkpoint_format": True}
assert calls[0][1] == {"is_checkpoint_format": True}
assert calls[0][2] == 900.0

assert calls[0][2] == vllm_engine._weight_transfer_http_timeout()


@pytest.mark.unit
Expand All @@ -99,7 +98,9 @@ def fake_post(endpoint: str, payload: dict, timeout: float):
result = vllm_engine.finish_weight_update()

assert result == {"done": True}
assert calls == [("finish_weight_update", {}, vllm_engine._weight_transfer_http_timeout())]
assert len(calls) == 1
assert calls[0][0] == "finish_weight_update"
assert calls[0][1] == {}
Comment on lines +101 to +103

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instead of dropping the timeout assertion, we should verify that the default timeout of 900.0 seconds is correctly passed to the _post_json call.

Suggested change
assert len(calls) == 1
assert calls[0][0] == "finish_weight_update"
assert calls[0][1] == {}
assert len(calls) == 1
assert calls[0][0] == "finish_weight_update"
assert calls[0][1] == {}
assert calls[0][2] == 900.0



@pytest.mark.unit
Expand Down Expand Up @@ -152,56 +153,6 @@ def fake_post(endpoint: str, payload: dict, timeout: float):
assert seen[0][1] == {"update_info": {"names": ["w"], "packed": False}}


@pytest.mark.unit
def test_weight_transfer_http_timeout_reads_env(vllm_engine, monkeypatch):
monkeypatch.setenv("SLIME_VLLM_WEIGHT_TRANSFER_UPDATE_TIMEOUT_SEC", "123.5")
assert vllm_engine._weight_transfer_http_timeout() == 123.5


@pytest.mark.unit
def test_weight_transfer_http_timeout_fallback_to_legacy_env(vllm_engine, monkeypatch):
monkeypatch.delenv("SLIME_VLLM_WEIGHT_TRANSFER_UPDATE_TIMEOUT_SEC", raising=False)
monkeypatch.setenv("SLIME_VLLM_WEIGHT_TRANSFER_HTTP_TIMEOUT_SEC", "42")
assert vllm_engine._weight_transfer_http_timeout() == 42.0


@pytest.mark.unit
def test_response_json_or_fallback_parses_dict():
response = _MockResponse(json_data={"status": "ready"})
assert mod._response_json_or_fallback(response) == {"status": "ready"}


@pytest.mark.unit
def test_response_json_or_fallback_non_dict_wrapped():
response = _MockResponse()
response.json = lambda: ["a", "b"] # type: ignore[method-assign]
assert mod._response_json_or_fallback(response) == {
"ok": False,
"error": "Response is not a dictionary",
"data": ["a", "b"],
}


@pytest.mark.unit
def test_response_json_or_fallback_invalid_json():
response = _MockResponse(text="not-json")
response.json = lambda: (_ for _ in ()).throw(ValueError("no json")) # type: ignore[method-assign]
assert mod._response_json_or_fallback(response) == {
"ok": False,
"error": "Invalid JSON response",
"raw": "not-json",
}


@pytest.mark.unit
def test_http_base_requires_init(vllm_args):
from slime.backends.vllm_utils.vllm_engine import VLLMEngine

engine = VLLMEngine(vllm_args, rank=0)
with pytest.raises(RuntimeError, match="init\\(\\)"):
engine._http_base()


@pytest.mark.unit
def test_http_base_ipv6_host(vllm_engine):
vllm_engine.server_host = "[2001:db8::1]"
Expand Down
Loading