Commit 0512b2ad authored by Matias Guijarro's avatar Matias Guijarro
Browse files

tests: lima prepare_timeout: alternative version using a signal to block the...

tests: lima prepare_timeout: alternative version using a signal to block the server (no need to allocate memory)
parent abcf237e
Pipeline #51709 passed with stages
in 101 minutes and 54 seconds
......@@ -6,6 +6,7 @@
# Distributed under the GNU LGPLv3. See LICENSE for more info.
import os
import signal
import time
import types
import pytest
......@@ -1517,52 +1518,40 @@ def test_roi_collection(default_session, lima_simulator, tmp_path):
def test_prepare_timeout(default_session):
frame_num = 100
# measure the allocation time using a very large prepare_timeout to avoid the timeout exception
cfg = default_session.config.get_config("lima_simulator")
cfg["prepare_timeout"] = 100
with lima_simulator_context("simulator", "id00/limaccds/simulator1") as fqdn_proxy:
cam = default_session.config.get("lima_simulator")
reset_cam(cam)
# check it receives the correct value from config
assert cam._Lima__prepare_timeout == 100
cam._proxy.acq_nb_frames = frame_num
t0 = time.time()
cam.prepareAcq()
alloc_time = time.time() - t0
print("=== alloc_time = ", alloc_time)
# check it fails with a timeout exception if prepare_timeout < alloc time
del default_session.config._name2instance[
"lima_simulator"
] # remove cam from imported object list
cfg = default_session.config.get_config("lima_simulator")
cfg["prepare_timeout"] = alloc_time / 2
with lima_simulator_context("simulator", "id00/limaccds/simulator1") as fqdn_proxy:
cfg["prepare_timeout"] = 0.1
with lima_simulator_context(
"simulator", "id00/limaccds/simulator1"
) as lima_simulator:
dev_fqdn, lima_proxy = lima_simulator
cam = default_session.config.get("lima_simulator")
reset_cam(cam)
# check it receives the correct value from config
assert cam._Lima__prepare_timeout == alloc_time / 2
assert cam._Lima__prepare_timeout == 0.1
cam._proxy.acq_nb_frames = frame_num
with pytest.raises(DevFailed):
with pytest.raises(DevFailed) as exc_info:
os.kill(lima_proxy.server_pid, signal.SIGSTOP) # the server won't answer
cam.prepareAcq()
assert "Timedout" in str(exc_info.value)
# check it works if prepare_timeout > alloc time
# check it works if prepare_timeout > prepare time
del default_session.config._name2instance["lima_simulator"]
cfg = default_session.config.get_config("lima_simulator")
cfg["prepare_timeout"] = alloc_time * 2
with lima_simulator_context("simulator", "id00/limaccds/simulator1") as fqdn_proxy:
cfg["prepare_timeout"] = 1
with lima_simulator_context(
"simulator", "id00/limaccds/simulator1"
) as lima_simulator:
dev_fqdn, lima_proxy = lima_simulator
cam = default_session.config.get("lima_simulator")
reset_cam(cam)
# check it receives the correct value from config
assert cam._Lima__prepare_timeout == alloc_time * 2
cam._proxy.acq_nb_frames = frame_num
cam.prepareAcq()
assert cam._Lima__prepare_timeout == 1
os.kill(lima_proxy.server_pid, signal.SIGSTOP) # the server won't answer
prepare_task = gevent.spawn(cam.prepareAcq)
gevent.sleep(0.5)
os.kill(lima_proxy.server_pid, signal.SIGCONT) # server runs again
prepare_task.get()
assert prepare_task.successful()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment