Update tests/test_utils_opmsg.py
Run CI Tests / test (push) Successful in 1m59s

This commit is contained in:
2025-08-09 02:13:09 +02:00
parent 02f424f3e4
commit 339616193c
+41 -53
View File
@@ -14,63 +14,52 @@ from slic.utils.opmsg import (
@pytest.fixture(scope="module", autouse=True)
def run_all_iocs():
stop = threading.Event()
threads = []
def run_op_prefix(prefix: str):
with MorIOC(prefix) as mor:
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)},
**{"OP-MSG-tmp": str},
**{"OP-MSG-TMP": str},
)
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": ""},
)
def run():
with MorIOC("") as mor: # single IOC → no port clashes
# --- OPMSG for all IDs ---
for ID in IDS.values():
base = f"SF-OP:{ID}-MSG"
mor.host(
**{f"{base}:STATUS": {"type": "enum", "enums": ["OFFLINE", "PREPARATION", "REMOTE", "ATTENDED"]}},
**{f"{base}:STATUS-DATE": str},
**{f"{base}:OP-MSG-tmp": str},
**{f"{base}:OP-MSG-TMP": str},
**{f"{base}:OP-DATE{i}": str for i in range(N_MSG_HISTORY)},
**{f"{base}:OP-MSG{i}": str for i in range(N_MSG_HISTORY)},
)
mor.serve(
**{f"{base}:STATUS": "OFFLINE"},
**{f"{base}:STATUS-DATE": "2024-01-01 00:00:00"},
**{f"{base}:OP-MSG-tmp": ""},
**{f"{base}:OP-MSG-TMP": ""},
**{f"{base}:OP-DATE{i}": f"2024-01-01 00:00:0{i}" for i in range(N_MSG_HISTORY)},
**{f"{base}:OP-MSG{i}": f"Initial message {i}" for i in range(N_MSG_HISTORY)},
)
# --- STATUS for all beamlines ---
for bl in BEAMLINES:
base = f"SF-STATUS-{bl}"
mor.host(
**{f"{base}:CATEGORY": {"type": "enum", "enums": ["USER", "MD", "SD", "ACCESS", "DOWN"]}},
**{f"{base}:DOWNTIME": str},
)
mor.serve(**{f"{base}:CATEGORY": "USER", f"{base}:DOWNTIME": "00:00:00"})
# Serve loop
while not stop.is_set():
mor.serve()
time.sleep(0.1)
time.sleep(0.05)
def run_status_prefix(beamline: str):
with MorIOC(f"SF-STATUS-{beamline}") as mor:
mor.host(
CATEGORY={"type": "enum", "enums": ["USER", "MD", "SD", "ACCESS", "DOWN"]},
DOWNTIME=str,
)
mor.serve(CATEGORY="USER", DOWNTIME="00:00:00")
while not stop.is_set():
mor.serve()
time.sleep(0.1)
t = threading.Thread(target=run)
t.start()
time.sleep(1.0) # let CA announce PVs
# Start all OPMSG IOCs
for ID in IDS.values():
prefix = f"SF-OP:{ID}-MSG"
t = threading.Thread(target=run_op_prefix, args=(prefix,))
t.start()
threads.append(t)
yield
# Start all MachineStatus IOCs
for bl in BEAMLINES:
t = threading.Thread(target=run_status_prefix, args=(bl,))
t.start()
threads.append(t)
time.sleep(2.0) # Allow time for all PVs to be announced
yield # <<< all tests in this module run here >>>
# --- Teardown: stop all IOCs and wait for threads to finish ---
stop.set()
for t in threads:
t.join(timeout=2.0)
time.sleep(0.2) # Give OS a moment to release the sockets
t.join(timeout=2.0)
time.sleep(0.2)
@@ -153,7 +142,7 @@ class TestOperationMessageEntry:
time.sleep(0.05)
assert repr(entry) == f"{date_val} {msg_val}"
'''
# -------- OperationMessage --------
class TestOperationMessage:
def test_init_with_name(self):
@@ -332,5 +321,4 @@ class TestMachineStatus:
r = repr(ms)
assert beamline in r
assert "ACCESS" in r
assert "00:05:00" in r
'''
assert "00:05:00" in r