Merge branch 'rename-s2'
This commit is contained in:
@@ -9,7 +9,9 @@ from sqlmodel import Session, select
|
||||
|
||||
from fluksio.api.routes import flows as flows_route
|
||||
from fluksio.core.config import settings
|
||||
from fluksio.flow.devices import Binding
|
||||
from fluksio.flow.events import event_bus
|
||||
from fluksio.flow.pipeline import EngineHeld
|
||||
from fluksio.models import Run, RunArtifact, RunMetric, RunNode
|
||||
from tests.utils.flows import put_flow
|
||||
|
||||
@@ -600,3 +602,35 @@ def test_a_shared_source_write_is_audited(
|
||||
headers=superuser_token_headers,
|
||||
)
|
||||
client.delete(f"{PREFIX}/audited", headers=superuser_token_headers)
|
||||
|
||||
|
||||
def test_a_publish_while_a_rename_holds_the_engine_is_refused(
|
||||
client: TestClient,
|
||||
superuser_token_headers: dict[str, str],
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Over REST as a 503 to retry, from a device's socket as ``busy``."""
|
||||
controller = client.app.state.flow_controller # type: ignore[attr-defined]
|
||||
|
||||
def held(*_: object) -> None:
|
||||
raise EngineHeld("A rename holds the engine; try again shortly")
|
||||
|
||||
monkeypatch.setattr(controller, "publish_message", held)
|
||||
response = client.post(
|
||||
f"{settings.API_V1_STR}/messages/porch.doorbell",
|
||||
headers=superuser_token_headers,
|
||||
json={"value": True},
|
||||
)
|
||||
assert response.status_code == 503
|
||||
assert response.headers["Retry-After"] == "5"
|
||||
|
||||
bound = Binding("panel", "porch", "panel", "gpio.4", "porch.doorbell", "in", "bool")
|
||||
app = SimpleNamespace(
|
||||
state=SimpleNamespace(
|
||||
device_store=SimpleNamespace(bound=lambda _: [bound]),
|
||||
flow_controller=controller,
|
||||
)
|
||||
)
|
||||
device = SimpleNamespace(id="panel", title="Panel")
|
||||
value = {"type": "publish", "name": "porch.doorbell", "value": True}
|
||||
assert flows_route.ingest_publish(app, device, value) == "busy" # type: ignore[arg-type]
|
||||
|
||||
Reference in New Issue
Block a user