bec-lib 4.4.2__tar.gz → 4.5.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {bec_lib-4.4.2 → bec_lib-4.5.1}/PKG-INFO +1 -1
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/endpoints.py +16 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/messages.py +32 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/redis_connector/managed_redis_connection.py +1 -1
- {bec_lib-4.4.2 → bec_lib-4.5.1}/pyproject.toml +1 -1
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_bec_messages.py +46 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_hli_connector_fakeredis.py +2 -3
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_hli_redis_connector.py +5 -20
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_managed_redis_connection.py +47 -63
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_messaging_service.py +31 -7
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_redis_connector_fakeredis.py +73 -69
- {bec_lib-4.4.2 → bec_lib-4.5.1}/.gitignore +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/README.md +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/__init__.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/_print_versions.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/acl_login.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/actors.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/alarm_handler.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/atlas_models.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/bec_errors.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/bec_service.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/bec_yaml_loader.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/bl_state_manager.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/bl_states.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/builtin_actor_hli.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/callback_handler.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/channel_monitor.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/client.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/codecs.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/config_helper.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/config_values.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/configs/__init__.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/configs/demo_config.yaml +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/configs/openapi_schema.json +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/connector.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/dap_plugin_objects.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/dap_plugins.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/device.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/devicemanager.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/file_utils.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/live_scan_data.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/lmfit_serializer.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/logger.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/macro_update_handler.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/messaging_hooks.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/messaging_services.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/metadata_schema.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/numpy_encoder.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/observer.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/path_optimization.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/pdf_writer.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/plugin_helper.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/position_generators.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/procedures/__init__.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/procedures/helper.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/procedures/hli.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/procedures/status.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/queue_items.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/redis_connector/__init__.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/redis_connector/constants.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/redis_connector/hli.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/redis_connector/streams.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/redis_connector/validation.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/request_context.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/request_items.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/scan_args.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/scan_data_container.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/scan_history.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/scan_input_validator.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/scan_items.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/scan_manager.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/scan_number_container.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/scan_preview.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/scan_repeat.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/scan_report.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/scans.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/scibec_validator.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/script_executor.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/serialization.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/serialization_registry.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/service_config.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/signature_serializer.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/tests/__init__.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/tests/fixtures.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/tests/test_config.yaml +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/tests/test_service_config.yaml +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/tests/utils.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/user_macros.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/utils/__init__.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/utils/copier_jinja_filters.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/utils/deprecation.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/utils/import_utils.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/utils/json_extended.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/utils/plugin_manager/__init__.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/utils/plugin_manager/_constants.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/utils/plugin_manager/_util.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/utils/plugin_manager/create/__init__.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/utils/plugin_manager/create/device.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/utils/plugin_manager/create/scan.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/utils/plugin_manager/create/templates/scan.py.jinja +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/utils/plugin_manager/main.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/utils/proxy.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/utils/pydantic_pretty_print.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/utils/rpc_utils.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/utils/scan_utils.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/utils/threading_utils.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/bec_lib/utils/user_acls_test.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/__init__.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/_additional_for_signature_serializer_test.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/conftest.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_acl_login.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_alarm_handler.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_atlas_models.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_beamline_states.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_bec_logger.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_bec_service.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_callback_handler.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_channel_monitor.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_client.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_config_helper.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_core_utils.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_dap_plugins.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_data_container.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_deprecation.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_device_hashing.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_device_manager.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_devices.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_file_utils.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_import_utils.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_jinja_plugins.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_lmfit_serializer.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_managed_config_values.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_messaging_hooks.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_metadata_schema.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_observer.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_path_optimization.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_pdf_writer.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_plugin_helper.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_plugin_manager.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_plugin_system.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_position_generators.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_procedure_submission.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_pydantic_pretty_print.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_queue_items.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_roi_endpoints.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_roi_messages.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_scan_context.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_scan_data.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_scan_history.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_scan_items.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_scan_manager.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_scan_object.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_scan_preview.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_scan_repeat.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_scan_report.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_scibec_validator.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_script_executor.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_serializer.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_service_config.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_signature_serializer.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_signature_serializer_with_future_import.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_stream_subs.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_user_macros.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_utils.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/tests/test_yaml_loader.py +0 -0
- {bec_lib-4.4.2 → bec_lib-4.5.1}/util_scripts/init_config.py +0 -0
|
@@ -796,6 +796,22 @@ class MessageEndpoints:
|
|
|
796
796
|
message_op=MessageOp.SET_PUBLISH,
|
|
797
797
|
)
|
|
798
798
|
|
|
799
|
+
@staticmethod
|
|
800
|
+
def scan_hook() -> EndpointInfo:
|
|
801
|
+
"""Endpoint for the latest scan hook or instruction update of the running scan.
|
|
802
|
+
|
|
803
|
+
Step changes are published at once, instruction updates at most once per 0.1 second
|
|
804
|
+
window. The latest update is stored, so clients that start mid-scan can read it.
|
|
805
|
+
|
|
806
|
+
Returns:
|
|
807
|
+
EndpointInfo: Endpoint carrying messages.ScanHookMessage updates.
|
|
808
|
+
"""
|
|
809
|
+
return EndpointInfo(
|
|
810
|
+
endpoint=f"{EndpointType.INFO.value}/scans/scan_hook",
|
|
811
|
+
message_type=messages.ScanHookMessage,
|
|
812
|
+
message_op=MessageOp.SET_PUBLISH,
|
|
813
|
+
)
|
|
814
|
+
|
|
799
815
|
@staticmethod
|
|
800
816
|
def scan_progress():
|
|
801
817
|
"""
|
|
@@ -763,6 +763,38 @@ class DeviceInstructionMessage(BECMessage):
|
|
|
763
763
|
parameter: dict
|
|
764
764
|
|
|
765
765
|
|
|
766
|
+
class ScanHookMessage(BECMessage):
|
|
767
|
+
"""A scan lifecycle event, optionally including dispatched device instructions.
|
|
768
|
+
|
|
769
|
+
Args:
|
|
770
|
+
scan_id (str): Scan whose lifecycle is being reported.
|
|
771
|
+
hook (str | None): Active lifecycle hook, or None before a hook has started.
|
|
772
|
+
status (Literal["running", "completed", "interrupted", "error"]): Hook execution state.
|
|
773
|
+
"interrupted" means the step was ended by a user or alarm interruption of the scan
|
|
774
|
+
(finish now, abort or halt); "error" is used for any other exception.
|
|
775
|
+
instructions (list[DeviceInstructionMessage]): Instructions dispatched in this hook.
|
|
776
|
+
Instruction updates are coalesced to the latest one in each 0.1 second window;
|
|
777
|
+
the start, completion or failure of a top-level step is sent at once.
|
|
778
|
+
waiting (bool): Whether this update was recorded during a device or exposure wait.
|
|
779
|
+
Wait updates include only pending instructions. The next hook or instruction update
|
|
780
|
+
replaces the wait; no separate update is emitted when waiting ends.
|
|
781
|
+
wait_started_at (float | None): Start time of the reported wait, or None for other updates.
|
|
782
|
+
hook_started_at (float | None): Start time of the current top-level step, e.g. scan_core,
|
|
783
|
+
or None outside a step.
|
|
784
|
+
timestamp (float): Time at which the lifecycle or instruction event was recorded.
|
|
785
|
+
"""
|
|
786
|
+
|
|
787
|
+
msg_type: ClassVar[str] = "scan_hook"
|
|
788
|
+
scan_id: str
|
|
789
|
+
hook: str | None
|
|
790
|
+
status: Literal["running", "completed", "interrupted", "error"] = "running"
|
|
791
|
+
instructions: list[DeviceInstructionMessage] = Field(default_factory=list)
|
|
792
|
+
timestamp: float = Field(default_factory=time.time)
|
|
793
|
+
waiting: bool = False
|
|
794
|
+
wait_started_at: float | None = None
|
|
795
|
+
hook_started_at: float | None = None
|
|
796
|
+
|
|
797
|
+
|
|
766
798
|
class ErrorInfo(BaseModel):
|
|
767
799
|
id: str = Field(default_factory=lambda: str(uuid.uuid4()))
|
|
768
800
|
error_message: str
|
|
@@ -716,7 +716,7 @@ class ManagedRedisConnection:
|
|
|
716
716
|
except redis.exceptions.ConnectionError:
|
|
717
717
|
if not error:
|
|
718
718
|
error = True
|
|
719
|
-
|
|
719
|
+
logger.error(self.connection_error_str)
|
|
720
720
|
self._stop_events_listener_thread.wait(timeout=1)
|
|
721
721
|
# pylint: disable=broad-except
|
|
722
722
|
except Exception:
|
|
@@ -1124,3 +1124,49 @@ def test_feedback_message():
|
|
|
1124
1124
|
assert res_loaded == msg
|
|
1125
1125
|
assert res_loaded.username == getpass.getuser()
|
|
1126
1126
|
assert res_loaded.versions == messages.ServiceVersions._get_version_numbers()
|
|
1127
|
+
|
|
1128
|
+
|
|
1129
|
+
def test_scan_hook_message_roundtrip():
|
|
1130
|
+
instruction = messages.DeviceInstructionMessage(
|
|
1131
|
+
device="samx", action="set", parameter={"value": 2}, metadata={"device_instr_id": "move"}
|
|
1132
|
+
)
|
|
1133
|
+
msg = messages.ScanHookMessage(
|
|
1134
|
+
scan_id="scan-id",
|
|
1135
|
+
hook="pre_scan",
|
|
1136
|
+
instructions=[instruction],
|
|
1137
|
+
metadata={"RID": "request-id", "queue_id": "queue-id"},
|
|
1138
|
+
)
|
|
1139
|
+
loaded = MsgpackSerialization.loads(MsgpackSerialization.dumps(msg))
|
|
1140
|
+
assert loaded == msg
|
|
1141
|
+
assert isinstance(loaded.instructions[0], messages.DeviceInstructionMessage)
|
|
1142
|
+
assert messages.ScanHookMessage(scan_id="scan-id", hook="stage").instructions == []
|
|
1143
|
+
|
|
1144
|
+
|
|
1145
|
+
def test_scan_hook_wait_fields_are_optional_and_roundtrip():
|
|
1146
|
+
old_update = messages.ScanHookMessage.model_validate(
|
|
1147
|
+
{"scan_id": "scan-id", "hook": "at_each_point", "status": "running", "instructions": []}
|
|
1148
|
+
)
|
|
1149
|
+
assert old_update.waiting is False
|
|
1150
|
+
assert old_update.wait_started_at is None
|
|
1151
|
+
assert old_update.hook_started_at is None
|
|
1152
|
+
waiting = old_update.model_copy(update={"waiting": True, "wait_started_at": 1791244800.0})
|
|
1153
|
+
loaded = MsgpackSerialization.loads(MsgpackSerialization.dumps(waiting))
|
|
1154
|
+
assert loaded == waiting
|
|
1155
|
+
assert loaded.waiting is True
|
|
1156
|
+
assert loaded.wait_started_at == 1791244800.0
|
|
1157
|
+
|
|
1158
|
+
|
|
1159
|
+
def test_scan_hook_step_start_roundtrips():
|
|
1160
|
+
msg = messages.ScanHookMessage(
|
|
1161
|
+
scan_id="scan-id", hook="scan_core", status="error", hook_started_at=1791244800.0
|
|
1162
|
+
)
|
|
1163
|
+
loaded = MsgpackSerialization.loads(MsgpackSerialization.dumps(msg))
|
|
1164
|
+
assert loaded == msg
|
|
1165
|
+
assert loaded.hook_started_at == 1791244800.0
|
|
1166
|
+
|
|
1167
|
+
|
|
1168
|
+
def test_scan_hook_interrupted_status_roundtrips():
|
|
1169
|
+
msg = messages.ScanHookMessage(scan_id="scan-id", hook="scan_core", status="interrupted")
|
|
1170
|
+
loaded = MsgpackSerialization.loads(MsgpackSerialization.dumps(msg))
|
|
1171
|
+
assert loaded == msg
|
|
1172
|
+
assert loaded.status == "interrupted"
|
|
@@ -12,7 +12,6 @@ from bec_lib.redis_connector.constants import (
|
|
|
12
12
|
IncompatibleMessageForEndpoint,
|
|
13
13
|
IncompatibleRedisOperation,
|
|
14
14
|
)
|
|
15
|
-
from bec_lib.redis_connector.managed_redis_connection import ManagedRedisConnection
|
|
16
15
|
from bec_lib.serialization import MsgpackSerialization
|
|
17
16
|
|
|
18
17
|
from .test_managed_redis_connection import TestMessage
|
|
@@ -34,9 +33,9 @@ def fake_redis_server(host, port, **kwargs):
|
|
|
34
33
|
|
|
35
34
|
|
|
36
35
|
@pytest.fixture
|
|
37
|
-
def connected_connector():
|
|
38
|
-
ManagedRedisConnection.RETRY_ON_TIMEOUT = 0
|
|
36
|
+
def connected_connector(monkeypatch):
|
|
39
37
|
connector = RedisConnector("localhost:1", redis_cls=fake_redis_server)
|
|
38
|
+
monkeypatch.setattr(connector._managed_connection, "RETRY_ON_TIMEOUT", 0)
|
|
40
39
|
connector._managed_connection.flushall()
|
|
41
40
|
try:
|
|
42
41
|
yield connector
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
from typing import Any, ClassVar, Optional
|
|
2
1
|
from unittest import mock
|
|
3
2
|
|
|
4
3
|
import pytest
|
|
5
4
|
|
|
6
|
-
import bec_lib.messages as bec_messages
|
|
7
5
|
from bec_lib import messages
|
|
8
6
|
from bec_lib.alarm_handler import Alarms
|
|
9
|
-
from bec_lib.endpoints import
|
|
10
|
-
from bec_lib.messages import AlarmMessage
|
|
7
|
+
from bec_lib.endpoints import MessageEndpoints
|
|
8
|
+
from bec_lib.messages import AlarmMessage
|
|
11
9
|
from bec_lib.messaging_hooks import MessagingEvent
|
|
12
10
|
from bec_lib.redis_connector import IncompatibleRedisOperation, RedisConnector
|
|
13
|
-
from bec_lib.redis_connector.constants import WrongArguments
|
|
14
|
-
from bec_lib.redis_connector.validation import validate_endpoint
|
|
15
11
|
from bec_lib.serialization import MsgpackSerialization
|
|
16
12
|
|
|
17
13
|
# pylint: disable=protected-access
|
|
@@ -20,17 +16,6 @@ from bec_lib.serialization import MsgpackSerialization
|
|
|
20
16
|
# pylint: disable=redefined-outer-name
|
|
21
17
|
|
|
22
18
|
|
|
23
|
-
class TestMessage(BECMessage):
|
|
24
|
-
__test__: ClassVar[bool] = False # just for pytest to ignore this class
|
|
25
|
-
msg_type: ClassVar[str] = "test_message"
|
|
26
|
-
msg: Optional[str] = None
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
# register at BEC messages module level, to be able to
|
|
30
|
-
# find it when using "loads()"
|
|
31
|
-
bec_messages.TestMessage = TestMessage
|
|
32
|
-
|
|
33
|
-
|
|
34
19
|
@pytest.fixture
|
|
35
20
|
def hli_connector():
|
|
36
21
|
_connector = RedisConnector("localhost:1", redis_cls=mock.MagicMock)
|
|
@@ -110,7 +95,7 @@ def test_redis_connector_raise_alarm(
|
|
|
110
95
|
|
|
111
96
|
def test_redis_connector_send_converts_ep(hli_connector: RedisConnector):
|
|
112
97
|
topic = MessageEndpoints.scan_segment()
|
|
113
|
-
msg =
|
|
98
|
+
msg = messages.ScanMessage(point_id=1, scan_id="scan_id", data={})
|
|
114
99
|
hli_connector.send(topic, msg)
|
|
115
100
|
hli_connector._redis_conn.publish.assert_called_once_with(
|
|
116
101
|
topic.endpoint, MsgpackSerialization.dumps(msg)
|
|
@@ -131,12 +116,12 @@ def test_redis_connector_keys(hli_connector, pattern):
|
|
|
131
116
|
|
|
132
117
|
|
|
133
118
|
def test_send_raises_on_invalid_message_type(hli_connector):
|
|
134
|
-
correct_msg =
|
|
119
|
+
correct_msg = messages.DeviceMessage(
|
|
135
120
|
signals={"samx": {"value": 1, "timestamp": 1}}, metadata={}
|
|
136
121
|
)
|
|
137
122
|
hli_connector.set_and_publish(MessageEndpoints.device_read("samx"), correct_msg)
|
|
138
123
|
with pytest.raises(TypeError) as excinfo:
|
|
139
|
-
msg =
|
|
124
|
+
msg = messages.ScanMessage(point_id=1, scan_id="scan_id", data={}, metadata={})
|
|
140
125
|
hli_connector.set_and_publish(MessageEndpoints.device_read("samx"), msg)
|
|
141
126
|
assert "Message type <class 'bec_lib.messages.ScanMessage'> is not compatible " in str(
|
|
142
127
|
excinfo.value
|
|
@@ -10,11 +10,11 @@ from louie.saferef import safe_ref
|
|
|
10
10
|
from redis import Redis
|
|
11
11
|
from redis.exceptions import RedisError
|
|
12
12
|
|
|
13
|
-
import bec_lib.messages as bec_messages
|
|
14
13
|
from bec_lib import messages
|
|
15
14
|
from bec_lib.endpoints import EndpointInfo, MessageEndpoints
|
|
15
|
+
from bec_lib.logger import bec_logger
|
|
16
16
|
from bec_lib.messages import BECMessage, BECStatus, BundleMessage, ClientInfoMessage
|
|
17
|
-
from bec_lib.redis_connector import IncompatibleRedisOperation
|
|
17
|
+
from bec_lib.redis_connector import IncompatibleRedisOperation, managed_redis_connection
|
|
18
18
|
from bec_lib.redis_connector.constants import WrongArguments
|
|
19
19
|
from bec_lib.redis_connector.managed_redis_connection import ManagedRedisConnection
|
|
20
20
|
from bec_lib.redis_connector.streams import StreamSubInfo
|
|
@@ -33,9 +33,11 @@ class TestMessage(BECMessage):
|
|
|
33
33
|
msg: Optional[str] = None
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
@pytest.fixture
|
|
37
|
+
def connector_logger():
|
|
38
|
+
# Rebind the module's logger so other services can keep using the shared logger.
|
|
39
|
+
with mock.patch.object(managed_redis_connection, "logger") as logger:
|
|
40
|
+
yield logger
|
|
39
41
|
|
|
40
42
|
|
|
41
43
|
@pytest.fixture
|
|
@@ -68,7 +70,7 @@ def legacy_object_array_payload():
|
|
|
68
70
|
|
|
69
71
|
@pytest.mark.parametrize("from_start", [True, False])
|
|
70
72
|
def test_stream_listener_skips_rejected_object_arrays(
|
|
71
|
-
connector, legacy_object_array_payload, from_start
|
|
73
|
+
connector, connector_logger, legacy_object_array_payload, from_start
|
|
72
74
|
):
|
|
73
75
|
topic = MessageEndpoints.processed_data("legacy").endpoint
|
|
74
76
|
other_topic = MessageEndpoints.processed_data("valid").endpoint
|
|
@@ -91,11 +93,8 @@ def test_stream_listener_skips_rejected_object_arrays(
|
|
|
91
93
|
connector._redis_conn.xread.return_value = [] if from_start else response
|
|
92
94
|
connector._redis_conn.xrange.side_effect = lambda topic, *_: dict(response)[topic.encode()]
|
|
93
95
|
|
|
94
|
-
with (
|
|
95
|
-
|
|
96
|
-
connector._stop_stream_events_listener_thread, "is_set", side_effect=[False, True]
|
|
97
|
-
),
|
|
98
|
-
mock.patch("bec_lib.redis_connector.managed_redis_connection.logger.error") as log_error,
|
|
96
|
+
with mock.patch.object(
|
|
97
|
+
connector._stop_stream_events_listener_thread, "is_set", side_effect=[False, True]
|
|
99
98
|
):
|
|
100
99
|
connector._get_stream_messages_loop()
|
|
101
100
|
|
|
@@ -106,11 +105,11 @@ def test_stream_listener_skips_rejected_object_arrays(
|
|
|
106
105
|
message = connector._message_callbacks_queue.get_nowait()
|
|
107
106
|
assert message.msg == {"data": valid}
|
|
108
107
|
assert list(message.callbacks) == [(subscription.cb_ref, {})]
|
|
109
|
-
assert
|
|
108
|
+
assert connector_logger.error.call_count == 2
|
|
110
109
|
|
|
111
110
|
|
|
112
111
|
def test_direct_stream_listener_skips_rejected_object_arrays(
|
|
113
|
-
connector, legacy_object_array_payload
|
|
112
|
+
connector, connector_logger, legacy_object_array_payload
|
|
114
113
|
):
|
|
115
114
|
topic = MessageEndpoints.processed_data("legacy").endpoint
|
|
116
115
|
valid = messages.RawMessage(data="valid")
|
|
@@ -121,8 +120,7 @@ def test_direct_stream_listener_skips_rejected_object_arrays(
|
|
|
121
120
|
stop_event = mock.Mock()
|
|
122
121
|
stop_event.is_set.side_effect = [False, False, True]
|
|
123
122
|
callback = mock.Mock()
|
|
124
|
-
|
|
125
|
-
connector._direct_stream_listener(topic, stop_event, callback, {})
|
|
123
|
+
connector._direct_stream_listener(topic, stop_event, callback, {})
|
|
126
124
|
|
|
127
125
|
assert connector._redis_conn.xrevrange.call_args_list == [
|
|
128
126
|
mock.call(topic, "+", "-", count=1),
|
|
@@ -132,7 +130,7 @@ def test_direct_stream_listener_skips_rejected_object_arrays(
|
|
|
132
130
|
message = connector._message_callbacks_queue.get_nowait()
|
|
133
131
|
assert message.msg == {"data": valid}
|
|
134
132
|
assert list(message.callbacks) == [(callback, {})]
|
|
135
|
-
|
|
133
|
+
connector_logger.error.assert_called_once()
|
|
136
134
|
|
|
137
135
|
|
|
138
136
|
def test_redis_connector_send_client_info(connector: ManagedRedisConnection):
|
|
@@ -525,7 +523,7 @@ def test_blocking_list_pop(connector: ManagedRedisConnection):
|
|
|
525
523
|
),
|
|
526
524
|
)
|
|
527
525
|
def test_user_pw_restored_on_auth_fail(connector: ManagedRedisConnection, test_dict):
|
|
528
|
-
connector._redis_conn.connection_pool.connection_kwargs = test_dict
|
|
526
|
+
connector._redis_conn.connection_pool.connection_kwargs = test_dict.copy()
|
|
529
527
|
connector._redis_conn.auth.side_effect = RedisError
|
|
530
528
|
with pytest.raises(RedisError):
|
|
531
529
|
connector.authenticate(username="user", password="pass")
|
|
@@ -543,7 +541,9 @@ def test_try_read_streams_returns_error_message_for_no_permission(
|
|
|
543
541
|
assert error == "Permission denied for stream topics: {'topic'}"
|
|
544
542
|
|
|
545
543
|
|
|
546
|
-
def test_stream_connection_logs_once_and_logs_recovery(
|
|
544
|
+
def test_stream_connection_logs_once_and_logs_recovery(
|
|
545
|
+
connector: ManagedRedisConnection, connector_logger
|
|
546
|
+
):
|
|
547
547
|
stream_subs = mock.MagicMock()
|
|
548
548
|
stream_subs.lock = contextlib.nullcontext()
|
|
549
549
|
stream_subs.gc_cb_refs = mock.MagicMock()
|
|
@@ -564,20 +564,18 @@ def test_stream_connection_logs_once_and_logs_recovery(connector: ManagedRedisCo
|
|
|
564
564
|
[],
|
|
565
565
|
]
|
|
566
566
|
|
|
567
|
-
|
|
568
|
-
mock.patch("bec_lib.redis_connector.managed_redis_connection.logger.error") as log_error,
|
|
569
|
-
mock.patch("bec_lib.redis_connector.managed_redis_connection.logger.info") as log_info,
|
|
570
|
-
):
|
|
571
|
-
connector._get_stream_messages_loop()
|
|
567
|
+
connector._get_stream_messages_loop()
|
|
572
568
|
|
|
573
|
-
|
|
574
|
-
|
|
569
|
+
connector_logger.error.assert_called_once_with(connector.connection_error_str)
|
|
570
|
+
connector_logger.info.assert_called_once_with(
|
|
575
571
|
f"{connector.name} reconnected to redis ({connector.host}:{connector.port})."
|
|
576
572
|
)
|
|
577
573
|
assert connector._stop_stream_events_listener_thread.wait.call_count == 2
|
|
578
574
|
|
|
579
575
|
|
|
580
|
-
def test_stream_connection_logs_permission_error_and_recovery(
|
|
576
|
+
def test_stream_connection_logs_permission_error_and_recovery(
|
|
577
|
+
connector: ManagedRedisConnection, connector_logger
|
|
578
|
+
):
|
|
581
579
|
stream_subs = mock.MagicMock()
|
|
582
580
|
stream_subs.lock = contextlib.nullcontext()
|
|
583
581
|
stream_subs.gc_cb_refs = mock.MagicMock()
|
|
@@ -592,14 +590,10 @@ def test_stream_connection_logs_permission_error_and_recovery(connector: Managed
|
|
|
592
590
|
connector._stop_stream_events_listener_thread.wait = mock.MagicMock()
|
|
593
591
|
connector._redis_conn.xread.side_effect = [redis.exceptions.NoPermissionError("denied"), []]
|
|
594
592
|
|
|
595
|
-
|
|
596
|
-
mock.patch("bec_lib.redis_connector.managed_redis_connection.logger.error") as log_error,
|
|
597
|
-
mock.patch("bec_lib.redis_connector.managed_redis_connection.logger.info") as log_info,
|
|
598
|
-
):
|
|
599
|
-
connector._get_stream_messages_loop()
|
|
593
|
+
connector._get_stream_messages_loop()
|
|
600
594
|
|
|
601
|
-
|
|
602
|
-
|
|
595
|
+
connector_logger.error.assert_called_once_with("Permission denied for stream topics: {'topic'}")
|
|
596
|
+
connector_logger.info.assert_called_once_with(
|
|
603
597
|
f"{connector.name} reconnected to redis ({connector.host}:{connector.port})."
|
|
604
598
|
)
|
|
605
599
|
assert connector._stop_stream_events_listener_thread.wait.call_count == 1
|
|
@@ -609,7 +603,7 @@ def test_stream_connection_logs_permission_error_and_recovery(connector: Managed
|
|
|
609
603
|
"error_type", [redis.exceptions.NoPermissionError, redis.exceptions.ConnectionError]
|
|
610
604
|
)
|
|
611
605
|
def test_stream_connection_logs_errors_from_both_read_paths(
|
|
612
|
-
connector: ManagedRedisConnection, error_type
|
|
606
|
+
connector: ManagedRedisConnection, connector_logger, error_type
|
|
613
607
|
):
|
|
614
608
|
def callback():
|
|
615
609
|
pass
|
|
@@ -619,21 +613,17 @@ def test_stream_connection_logs_errors_from_both_read_paths(
|
|
|
619
613
|
connector._redis_conn.xrange.side_effect = [error_type("denied"), error_type("denied"), []]
|
|
620
614
|
connector._redis_conn.xread.side_effect = [error_type("denied"), error_type("denied"), [], []]
|
|
621
615
|
|
|
622
|
-
with (
|
|
623
|
-
mock.patch.object(connector, "_stop_stream_events_listener_thread") as stop_event,
|
|
624
|
-
mock.patch("bec_lib.redis_connector.managed_redis_connection.logger.error") as log_error,
|
|
625
|
-
mock.patch("bec_lib.redis_connector.managed_redis_connection.logger.info") as log_info,
|
|
626
|
-
):
|
|
616
|
+
with mock.patch.object(connector, "_stop_stream_events_listener_thread") as stop_event:
|
|
627
617
|
stop_event.is_set.side_effect = [False, False, False, False, True]
|
|
628
618
|
connector._get_stream_messages_loop()
|
|
629
619
|
|
|
630
620
|
if error_type is redis.exceptions.NoPermissionError:
|
|
631
|
-
assert
|
|
632
|
-
|
|
633
|
-
|
|
621
|
+
assert connector_logger.error.call_count == 2
|
|
622
|
+
connector_logger.error.assert_any_call("Permission denied for stream topics: {'history'}")
|
|
623
|
+
connector_logger.error.assert_any_call("Permission denied for stream topics: {'live'}")
|
|
634
624
|
else:
|
|
635
|
-
|
|
636
|
-
|
|
625
|
+
connector_logger.error.assert_called_once_with(connector.connection_error_str)
|
|
626
|
+
connector_logger.info.assert_called_once_with(
|
|
637
627
|
f"{connector.name} reconnected to redis ({connector.host}:{connector.port})."
|
|
638
628
|
)
|
|
639
629
|
assert stop_event.wait.call_count == 2
|
|
@@ -644,7 +634,7 @@ def test_stream_connection_logs_errors_from_both_read_paths(
|
|
|
644
634
|
@pytest.mark.parametrize("from_start", [False, True])
|
|
645
635
|
@pytest.mark.parametrize("remove_subscription", ["unregister", "gc"])
|
|
646
636
|
def test_stream_connection_waits_for_read_before_logging_recovery(
|
|
647
|
-
connector: ManagedRedisConnection, from_start, remove_subscription
|
|
637
|
+
connector: ManagedRedisConnection, connector_logger, from_start, remove_subscription
|
|
648
638
|
):
|
|
649
639
|
def callback():
|
|
650
640
|
pass
|
|
@@ -670,30 +660,30 @@ def test_stream_connection_waits_for_read_before_logging_recovery(
|
|
|
670
660
|
else:
|
|
671
661
|
callback = None
|
|
672
662
|
elif iteration == 3:
|
|
673
|
-
|
|
663
|
+
# Other BEC components can log while the stream is still disconnected.
|
|
664
|
+
bec_logger.logger.info("Unrelated shutdown message")
|
|
665
|
+
connector_logger.info.assert_not_called()
|
|
674
666
|
assert not connector._stream_subs.all_topics
|
|
675
667
|
connector._stream_subs.add(
|
|
676
668
|
False, "0-0", "topic", StreamSubInfo(safe_ref(replacement_callback), {})
|
|
677
669
|
)
|
|
678
670
|
return iteration == 5
|
|
679
671
|
|
|
680
|
-
with (
|
|
681
|
-
mock.patch.object(connector, "_stop_stream_events_listener_thread") as stop_event,
|
|
682
|
-
mock.patch("bec_lib.redis_connector.managed_redis_connection.logger.error") as log_error,
|
|
683
|
-
mock.patch("bec_lib.redis_connector.managed_redis_connection.logger.info") as log_info,
|
|
684
|
-
):
|
|
672
|
+
with mock.patch.object(connector, "_stop_stream_events_listener_thread") as stop_event:
|
|
685
673
|
stop_event.is_set.side_effect = advance_loop
|
|
686
674
|
connector._get_stream_messages_loop()
|
|
687
675
|
|
|
688
|
-
|
|
689
|
-
|
|
676
|
+
connector_logger.error.assert_called_once_with(connector.connection_error_str)
|
|
677
|
+
connector_logger.info.assert_called_once_with(
|
|
690
678
|
f"{connector.name} reconnected to redis ({connector.host}:{connector.port})."
|
|
691
679
|
)
|
|
692
680
|
assert connector._redis_conn.xrange.call_count == int(from_start)
|
|
693
681
|
assert connector._redis_conn.xread.call_count == (2 if from_start else 3)
|
|
694
682
|
|
|
695
683
|
|
|
696
|
-
def test_pubsub_connection_logs_once_and_logs_recovery(
|
|
684
|
+
def test_pubsub_connection_logs_once_and_logs_recovery(
|
|
685
|
+
connector: ManagedRedisConnection, connector_logger
|
|
686
|
+
):
|
|
697
687
|
connector._garbage_collect_cb_refs = mock.MagicMock()
|
|
698
688
|
connector._stop_events_listener_thread = mock.MagicMock()
|
|
699
689
|
connector._stop_events_listener_thread.is_set.side_effect = [False, False, False, True]
|
|
@@ -704,16 +694,10 @@ def test_pubsub_connection_logs_once_and_logs_recovery(connector: ManagedRedisCo
|
|
|
704
694
|
None,
|
|
705
695
|
]
|
|
706
696
|
|
|
707
|
-
|
|
708
|
-
mock.patch(
|
|
709
|
-
"bec_lib.redis_connector.managed_redis_connection.bec_logger.logger.error"
|
|
710
|
-
) as log_error,
|
|
711
|
-
mock.patch("bec_lib.redis_connector.managed_redis_connection.logger.info") as log_info,
|
|
712
|
-
):
|
|
713
|
-
connector._get_messages_loop()
|
|
697
|
+
connector._get_messages_loop()
|
|
714
698
|
|
|
715
|
-
|
|
716
|
-
|
|
699
|
+
connector_logger.error.assert_called_once_with(connector.connection_error_str)
|
|
700
|
+
connector_logger.info.assert_called_once_with(
|
|
717
701
|
f"{connector.name} reconnected to redis ({connector.host}:{connector.port})."
|
|
718
702
|
)
|
|
719
703
|
assert connector._stop_events_listener_thread.wait.call_count == 2
|
|
@@ -979,8 +979,9 @@ def test_set_auto_notifications_persists_notification_config(scilog_service, con
|
|
|
979
979
|
|
|
980
980
|
|
|
981
981
|
def test_set_auto_notifications_merges_with_existing_routes(scilog_service, connected_connector):
|
|
982
|
-
|
|
983
|
-
|
|
982
|
+
# Seed Redis without queuing an older config update on the subscriber thread.
|
|
983
|
+
connected_connector._managed_connection.set( # pylint: disable=protected-access
|
|
984
|
+
MessageEndpoints.notification_config().endpoint,
|
|
984
985
|
messages.NotificationConfigMessage(
|
|
985
986
|
routes={
|
|
986
987
|
"new_scan": [
|
|
@@ -1009,8 +1010,8 @@ def test_set_auto_notifications_merges_with_existing_routes(scilog_service, conn
|
|
|
1009
1010
|
def test_set_auto_notifications_disable_removes_only_matching_service_scope(
|
|
1010
1011
|
scilog_service, connected_connector
|
|
1011
1012
|
):
|
|
1012
|
-
connected_connector.
|
|
1013
|
-
MessageEndpoints.notification_config(),
|
|
1013
|
+
connected_connector._managed_connection.set( # pylint: disable=protected-access
|
|
1014
|
+
MessageEndpoints.notification_config().endpoint,
|
|
1014
1015
|
messages.NotificationConfigMessage(
|
|
1015
1016
|
routes={
|
|
1016
1017
|
"new_scan": [
|
|
@@ -1031,7 +1032,30 @@ def test_set_auto_notifications_disable_removes_only_matching_service_scope(
|
|
|
1031
1032
|
]
|
|
1032
1033
|
}
|
|
1033
1034
|
)
|
|
1034
|
-
|
|
1035
|
+
|
|
1036
|
+
|
|
1037
|
+
def test_set_auto_notifications_disable_removes_cached_scope(scilog_service):
|
|
1038
|
+
scilog_service._on_notification_config_change_msg( # pylint: disable=protected-access
|
|
1039
|
+
{
|
|
1040
|
+
"data": messages.NotificationConfigMessage(
|
|
1041
|
+
routes={
|
|
1042
|
+
"new_scan": [
|
|
1043
|
+
messages.NotificationServiceTarget(
|
|
1044
|
+
service_name="scilog", scope=["default", "secondary"]
|
|
1045
|
+
)
|
|
1046
|
+
]
|
|
1047
|
+
}
|
|
1048
|
+
)
|
|
1049
|
+
}
|
|
1050
|
+
)
|
|
1051
|
+
|
|
1052
|
+
# Check the synchronous cache update without an asynchronous notification overwriting it.
|
|
1053
|
+
with mock.patch.object(scilog_service, "_sync_auto_notifications_config"):
|
|
1054
|
+
scilog_service.set_auto_notifications(MessagingEvent.SCAN, enabled=False, scopes="default")
|
|
1055
|
+
|
|
1056
|
+
assert scilog_service._auto_notifications == { # pylint: disable=protected-access
|
|
1057
|
+
"new_scan": ["secondary"]
|
|
1058
|
+
}
|
|
1035
1059
|
|
|
1036
1060
|
|
|
1037
1061
|
def test_set_auto_notifications_uses_default_scope_when_scopes_omitted(
|
|
@@ -1087,8 +1111,8 @@ def test_messaging_service_tracks_external_notification_config_updates(
|
|
|
1087
1111
|
|
|
1088
1112
|
|
|
1089
1113
|
def test_messaging_service_loads_notification_config_on_init(connected_connector):
|
|
1090
|
-
connected_connector.
|
|
1091
|
-
MessageEndpoints.notification_config(),
|
|
1114
|
+
connected_connector._managed_connection.set( # pylint: disable=protected-access
|
|
1115
|
+
MessageEndpoints.notification_config().endpoint,
|
|
1092
1116
|
messages.NotificationConfigMessage(
|
|
1093
1117
|
routes={
|
|
1094
1118
|
"new_scan": [
|