CI for mx_bec / e2e tests with pxi_bec (push) Failing after 1m4s
CI for mx_bec / e2e tests with pxii_bec (push) Failing after 1m17s
CI for mx_bec / e2e tests with pxiii_bec (push) Failing after 1m17s
CI for mx_bec / unit tests with pxiii_bec (push) Failing after 1m47s
CI for mx_bec / unit tests with pxii_bec (push) Failing after 1m55s
CI for mx_bec / unit tests with pxi_bec (push) Failing after 1m55s
# MX task architecture: AareBec service, tasks, queues and widgets Brings the AareBec task architecture into `mx_bec` ## Components - **AareBec service** (`service.py`, `main.py`): custom BEC client that owns the task queue, the actor manager and the external API clients. - **Task framework** (`tasks/core.py`): `@task` decorator and `TaskManager` with `Server` and `Client` roles. The server runs tasks one at a time and pauses the queue on failure; clients request tasks over Redis. `MxTaskQueue` works off the execution list. - **MX tasks** (`tasks/mx_tasks.py`): sample mount, optical centering, raster and multi-raster scans, X-ray centering, rotation data collection, beamline state change and cleanup. - **Automation actors** (`actors/`, `actor_manager.py`): actors that react to sequence milestones and queue the next task, each switchable through a Redis config value. - **External clients**: `AareDaq` REST client (Kerberos token, baton handling), `JFJoch` raster client, `OpticalPrediction` (AareLC). The `AareDaq` client is to be replaced with native BEC implementations. - **Devices** (`devices/`): Aerotech, Smargon (smargopolo), HTTP device base, simulated stages and sample changer, plus a demo config. - **Widgets** (`bec_widgets/widgets/aare_bec/`): actor config, task queue, task panel, sample queue and sample spreadsheet display - for development and admin use. - **Endpoints and messages** for task requests, the execution list, queue-change notifications and sequence state. ## Notes - BEC-driven optical centering was removed; it will be reimplemented from scratch. - The sample spreadsheet is copied between Redis instances by a hack in the service, to be replaced by the sample database connection module. - CI installs from the MX Gitea package index (`jfjoch_client` is pre-release only). --------- Co-authored-by: x10sa <x10sa@psi.ch> Reviewed-on: #2 Co-authored-by: David Perl <david.perl@psi.ch>
63 lines
2.4 KiB
Python
63 lines
2.4 KiB
Python
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
from bec_lib.endpoints import MessageOp
|
|
from bec_lib.messages import BoolConfigDefaultFalse
|
|
from bec_lib.redis_connector import MessageObject
|
|
|
|
from mx_bec.actors.mx_automation import OnSampleMountedRunOpticalCentering
|
|
from mx_bec.endpoints import StateEndpoints
|
|
from mx_bec.messages import MXMeasurementSequenceMessage, MXTaskExecutionMessage
|
|
|
|
|
|
@pytest.fixture
|
|
def client():
|
|
return MagicMock()
|
|
|
|
|
|
def _msg_obj(
|
|
endpoint, sample_id: int, success: bool
|
|
) -> MessageObject[MXMeasurementSequenceMessage]:
|
|
return MessageObject(
|
|
topic=endpoint.endpoint,
|
|
value=MXMeasurementSequenceMessage(sample_id=sample_id, success=success),
|
|
)
|
|
|
|
|
|
def test_config_endpoint_is_a_managed_bool_stream():
|
|
ep = OnSampleMountedRunOpticalCentering.config_endpoint()
|
|
assert ep.message_op == MessageOp.STREAM
|
|
assert ep.message_type is BoolConfigDefaultFalse
|
|
assert OnSampleMountedRunOpticalCentering.config_key in ep.endpoint
|
|
|
|
|
|
def test_actor_subscribes_to_its_milestone(client):
|
|
OnSampleMountedRunOpticalCentering(client, name="a", exec_id="a")
|
|
registered = {call.args[0].endpoint for call in client.connector.register.call_args_list}
|
|
assert StateEndpoints.sample_mounted().endpoint in registered
|
|
|
|
|
|
def test_successful_milestone_triggers_next_step(client):
|
|
client.sample_info.sample_id = 42 # the actor takes the sample from the service
|
|
actor = OnSampleMountedRunOpticalCentering(client, name="a", exec_id="a")
|
|
actor.evaluate(_msg_obj(StateEndpoints.sample_mounted(), sample_id=42, success=True))
|
|
|
|
client.add_task_to_queue.assert_called_once_with(
|
|
MXTaskExecutionMessage(name="run_optical_centering", args=(42,), kwargs={})
|
|
)
|
|
assert actor.last_message is None
|
|
|
|
|
|
def test_failed_milestone_does_not_trigger(client):
|
|
actor = OnSampleMountedRunOpticalCentering(client, name="a", exec_id="a")
|
|
actor.evaluate(_msg_obj(StateEndpoints.sample_mounted(), sample_id=42, success=False))
|
|
client.add_task_to_queue.assert_not_called()
|
|
client.connector.set_and_publish.assert_not_called()
|
|
|
|
|
|
def test_unexpected_message_is_ignored(client):
|
|
actor = OnSampleMountedRunOpticalCentering(client, name="a", exec_id="a")
|
|
actor.evaluate(MessageObject(topic="x", value=BoolConfigDefaultFalse()))
|
|
client.add_task_to_queue.assert_not_called()
|
|
client.connector.set_and_publish.assert_not_called()
|