This commit is contained in:
@@ -28,13 +28,15 @@ from morbidissimo import MorIOC
|
||||
def run_test_ioc():
|
||||
def ioc():
|
||||
with MorIOC("TEST") as mor:
|
||||
mor.host(PV1=float, PV2=float, PV3=float, PV4=float)
|
||||
mor.host(PV1=float, PV2=float, PV3=float, PV4=float, PV5=float, PV6=float)
|
||||
while True:
|
||||
mor.serve(
|
||||
PV1=1.0,
|
||||
PV2=2.0,
|
||||
PV3=3.0,
|
||||
PV4=4.0
|
||||
PV4=4.0,
|
||||
PV5=5.0,
|
||||
PV6=6.0
|
||||
)
|
||||
time.sleep(0.1)
|
||||
|
||||
@@ -253,3 +255,45 @@ def test_offload_exception(tmp_path, caplog):
|
||||
|
||||
logs = "\n".join(caplog.messages)
|
||||
assert "PV preload file not saved due to: IsADirectoryError:" in logs
|
||||
|
||||
def test_pvpreload_end_to_end(tmp_path, caplog):
|
||||
|
||||
configure_logzero_for_pytest(caplog)
|
||||
|
||||
preload_file = tmp_path / "end2end.pkl"
|
||||
|
||||
# Patch preload/offload pour utiliser le bon fichier et un petit délai
|
||||
with pytest.MonkeyPatch().context() as mp:
|
||||
mp.setattr("slic.utils.pvpreload.fn", preload_file)
|
||||
mp.setattr("slic.utils.pvpreload.delay", 0.05)
|
||||
|
||||
# Lancer le thread une bonne fois pour toutes
|
||||
with caplog.at_level("DEBUG"):
|
||||
pvpreload()
|
||||
|
||||
# Étape 1 : Crée PV5 et attend offload
|
||||
pvname_5 = "TEST:PV5"
|
||||
pv_5 = get_pv(pvname_5, connect=True)
|
||||
assert pv_5.wait_for_connection(timeout=2)
|
||||
time.sleep(0.2) # Laisser le offload le capturer
|
||||
|
||||
assert preload_file.exists(), "Fichier non créé après offload"
|
||||
names = std_pickle.load(open(preload_file, "rb"))
|
||||
assert pvname_5 in names, f"{pvname_5} absent du fichier"
|
||||
|
||||
# Étape 2 : Injecte PV6 dans le fichier pour le prochain preload
|
||||
pvname_6 = "TEST:PV6"
|
||||
with open(preload_file, "wb") as f:
|
||||
std_pickle.dump([pvname_6], f)
|
||||
|
||||
epics.pv._PVcache_.clear()
|
||||
assert not is_pv_in_cache(pvname_6)
|
||||
|
||||
# Attendre que le prochain preload recharge PV6
|
||||
time.sleep(0.2)
|
||||
assert is_pv_in_cache(pvname_6), "PV6 non rechargé par preload"
|
||||
|
||||
# Vérifie les logs
|
||||
logs = "\n".join(caplog.messages)
|
||||
assert "PV preload done" in logs
|
||||
assert "PV offload done" in logs
|
||||
|
||||
Reference in New Issue
Block a user