From 3e4c1c4c4fd4fcc6d8bceeff63dce5898a1bbc78 Mon Sep 17 00:00:00 2001 From: tligui_y Date: Fri, 8 Aug 2025 13:29:27 +0200 Subject: [PATCH] Update tests/test_utils_opmsg.py --- tests/test_utils_opmsg.py | 71 +++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 41 deletions(-) diff --git a/tests/test_utils_opmsg.py b/tests/test_utils_opmsg.py index aa2b6f598..b5d95179e 100644 --- a/tests/test_utils_opmsg.py +++ b/tests/test_utils_opmsg.py @@ -6,74 +6,57 @@ from morbidissimo import MorIOC from slic.utils.opmsg import * +import time +import threading +import pytest +from morbidissimo import MorIOC +from slic.utils.opmsg import IDS, BEAMLINES, N_MSG_HISTORY + def ioc(): """ - Start MorIOC servers for ALL PVs used by: - - OperationMessageStatus (STATUS, STATUS-DATE) - - OperationMessageEntry (OP-DATEi, OP-MSGi) - - OperationMessage (OP-MSG-tmp) - - MachineStatus (CATEGORY, DOWNTIME) - - One MorIOC per prefix: - - For each ID in IDS: 'SF-OP:{ID}-MSG' - - For each beamline in BEAMLINES: 'SF-STATUS-{beamline}' + IOC de test pour: + - STATUS / STATUS-DATE + - OP-DATEi / OP-MSGi + - OP-MSG-tmp (exactement ce que ton code utilise) + - CATEGORY / DOWNTIME """ - # Use TUPLES for enums so enum_strs is populated properly - STATUS_ENUMS = ("OFFLINE", "PREPARATION", "REMOTE", "ATTENDED") - CATEGORY_ENUMS = ("USER", "MD", "SD", "ACCESS", "DOWN") - def run_op_prefix(prefix: str): - """ - OP message space: - - STATUS (enum), STATUS-DATE (str) - - OP-DATE0..N_MSG_HISTORY-1 (str), OP-MSG0..N_MSG_HISTORY-1 (str) - - OP-MSG-tmp (str) AND OP-MSG-TMP (str) (both variants, kept in sync) - """ with MorIOC(prefix) as mor: - host_kwargs = { - "STATUS": STATUS_ENUMS, # true enum (tuple) + mor.host( + STATUS={"type": "enum", "enums": ["OFFLINE", "PREPARATION", "REMOTE", "ATTENDED"]}, **{"STATUS-DATE": str}, **{f"OP-DATE{i}": str for i in range(N_MSG_HISTORY)}, **{f"OP-MSG{i}": str for i in range(N_MSG_HISTORY)}, - # host BOTH tmp variants to avoid case-sensitivity issues **{"OP-MSG-tmp": str}, **{"OP-MSG-TMP": str}, - } - mor.host(**host_kwargs) + ) - # Seed ONCE, then stop clobbering - initial = { - "STATUS": "OFFLINE", - "STATUS-DATE": "2024-01-01 00:00:00", + # Seed une seule fois + mor.serve( + STATUS="OFFLINE", + **{"STATUS-DATE": "2024-01-01 00:00:00"}, **{f"OP-DATE{i}": f"2024-01-01 00:00:0{i}" for i in range(N_MSG_HISTORY)}, **{f"OP-MSG{i}": f"Initial message {i}" for i in range(N_MSG_HISTORY)}, - "OP-MSG-tmp": "", - "OP-MSG-TMP": "", - } - mor.serve(**initial) + **{"OP-MSG-tmp": ""}, + **{"OP-MSG-TMP": ""}, + ) - # Loop WITHOUT serving values again (so client puts persist) while True: - mor.serve() + mor.serve() time.sleep(0.02) def run_status_prefix(beamline: str): - """MachineStatus space: CATEGORY (enum), DOWNTIME (str).""" with MorIOC(f"SF-STATUS-{beamline}") as mor: mor.host( - CATEGORY=CATEGORY_ENUMS, # true enum (tuple) + CATEGORY={"type": "enum", "enums": ["USER", "MD", "SD", "ACCESS", "DOWN"]}, DOWNTIME=str, ) - # Seed ONCE mor.serve(CATEGORY="USER", DOWNTIME="00:00:00") - - # Then do nothing; client updates must persist while True: - mor.serve() + mor.serve() time.sleep(0.02) threads = [] - for ID in IDS.values(): prefix = f"SF-OP:{ID}-MSG" t = threading.Thread(target=run_op_prefix, args=(prefix,), daemon=True) @@ -87,6 +70,12 @@ def ioc(): return threads +@pytest.fixture(scope="module", autouse=True) +def run_all_iocs(): + threads = ioc() + time.sleep(0.5) + yield + @pytest.fixture(scope="module", autouse=True) def run_all_iocs():