Spaces:
Running on Zero
Running on Zero
File size: 1,337 Bytes
eb808a5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | """ZeroGPU command serialization and parent-side error restoration."""
from __future__ import annotations
import pickle
from pathlib import Path
import pytest
from core.errors import GatewayError
from core.executor import (
CommandError,
CommandResult,
InferenceCommand,
execute_inference,
)
def test_inference_command_is_pickle_safe(tmp_path: Path) -> None:
command = InferenceCommand(
model_name="flux",
method_name="generate",
arguments={"prompt": "city", "output_path": tmp_path / "image.png"},
request_id="request-1",
duration_seconds=180,
)
restored = pickle.loads(pickle.dumps(command))
assert restored == command
def test_serialized_worker_error_restores_gateway_error(monkeypatch) -> None:
command = InferenceCommand(
model_name="flux",
method_name="generate",
arguments={},
request_id="request-1",
duration_seconds=180,
)
monkeypatch.setattr(
"core.executor._invoke_large",
lambda _: CommandResult(
error=CommandError("flux ran out of memory", 507, "out_of_memory")
),
)
with pytest.raises(GatewayError) as captured:
execute_inference(command)
assert captured.value.status_code == 507
assert captured.value.code == "out_of_memory"
|