62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
"""pause/resume RPC handler tests (REQ-032 AC-4)."""
|
|
from __future__ import annotations
|
|
|
|
from trex_core.application.messaging import RpcRequest
|
|
from trex_core.application.messaging_handlers import make_pause_rpc_handler
|
|
from trex_core.application.portfolio import InMemoryPauseStore
|
|
|
|
|
|
def _handler():
|
|
store = InMemoryPauseStore()
|
|
return store, make_pause_rpc_handler(store)
|
|
|
|
|
|
def _call(handler, action, pid=None, actor="cli"):
|
|
return handler(RpcRequest(
|
|
payload={"action": action, "portfolio_id": pid, "actor": actor},
|
|
correlation_id="cid-1",
|
|
)).payload
|
|
|
|
|
|
def test_pause_then_list():
|
|
store, handler = _handler()
|
|
assert _call(handler, "pause", "pf-A")["status"] == "ok"
|
|
assert _call(handler, "pause", "pf-B")["status"] == "ok"
|
|
listed = _call(handler, "list")
|
|
assert listed["status"] == "ok"
|
|
assert listed["paused"] == ["pf-A", "pf-B"]
|
|
|
|
|
|
def test_resume_clears_pause():
|
|
store, handler = _handler()
|
|
_call(handler, "pause", "pf-A")
|
|
_call(handler, "resume", "pf-A")
|
|
assert _call(handler, "list")["paused"] == []
|
|
|
|
|
|
def test_missing_portfolio_id_returns_error():
|
|
_, handler = _handler()
|
|
resp = _call(handler, "pause", None)
|
|
assert resp["status"] == "error"
|
|
assert "portfolio_id" in resp["reason"]
|
|
|
|
|
|
def test_unknown_action_returns_error():
|
|
_, handler = _handler()
|
|
resp = _call(handler, "kill", "pf-A")
|
|
assert resp["status"] == "error"
|
|
assert "unknown action" in resp["reason"]
|
|
|
|
|
|
def test_cli_pause_visible_to_rpc_list_via_shared_store():
|
|
"""REQ-032 AC-4 — CLI and RPC share the same store."""
|
|
store = InMemoryPauseStore()
|
|
handler = make_pause_rpc_handler(store)
|
|
# CLI-side: directly mutate the store (CLI uses the same impl)
|
|
store.pause("pf-cli", actor="cli")
|
|
# RPC-side: list returns the same pause
|
|
resp = handler(RpcRequest(
|
|
payload={"action": "list"}, correlation_id="cid-cli",
|
|
)).payload
|
|
assert "pf-cli" in resp["paused"]
|