Files
mx_bec/tests/e2e/conftest.py
perl_dandx10sa d18c33f3b6
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
AareBec task service (#2)
# 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>
2026-11-24 14:41:31 +01:00

57 lines
1.9 KiB
Python

"""Fixtures for the end-to-end tests, which run against real BEC servers with the simulated MX
beamline loaded. They build on the `pytest_bec_e2e` plugin; run them with
pytest --start-servers --files-path <dir> tests/e2e
which starts a Redis server and the BEC servers for the test session (without `--start-servers`
they have to be running already).
"""
import pytest
from bec_lib.client import BECClient
from bec_lib.redis_connector import RedisConnector
from bec_lib.service_config import ServiceConfig
from bec_lib.tests.utils import wait_for_empty_queue
from mx_bec.configs import MX_SIMULATED_DEVICES, load_mx_simulated_config, render_config
from mx_bec.device_planner import SIMULATED
CLIENT_SHUTDOWN_TIMEOUT_S = 10
@pytest.fixture(scope="session")
def test_config_yaml_file_path():
"""The device config which `bec_servers` (pytest_bec_e2e) copies next to the service config."""
return render_config(MX_SIMULATED_DEVICES)
@pytest.fixture(scope="session")
def simulated_bec_session(bec_redis_fixture, bec_services_config_file_path, bec_servers):
"""A BEC client connected to the test servers, with the simulated beamline loaded once for
the whole session."""
config = ServiceConfig(bec_services_config_file_path)
bec = BECClient(config, RedisConnector, forced=True, wait_for_server=True)
bec.start()
load_mx_simulated_config(bec, force=True)
try:
yield bec
finally:
bec.shutdown(per_thread_timeout_s=CLIENT_SHUTDOWN_TIMEOUT_S)
bec._client._reset_singleton()
@pytest.fixture
def bec(simulated_bec_session):
"""The client on the simulated beamline, with an empty, running scan queue."""
bec = simulated_bec_session
bec.queue.request_queue_reset()
bec.queue.request_scan_continuation()
wait_for_empty_queue(bec)
return bec
@pytest.fixture
def simulated_beamline(monkeypatch):
"""Select the simulated beamline for the device planner."""
monkeypatch.setenv("BEAMLINE", SIMULATED)