0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 11:41:49 +02:00

fix(bec_signal_proxy): timeout for blocking implemented

This commit is contained in:
2025-01-26 14:17:20 +01:00
parent 21965a0ee3
commit 6f2f2aa06a
2 changed files with 88 additions and 11 deletions

View File

@ -73,3 +73,52 @@ def test_bec_signal_proxy(qtbot, dap_combo_box):
qtbot.wait(100)
assert proxy.blocked is False
assert proxy_container == [(("samx",),), (("samz",),)]
def test_bec_signal_proxy_timeout(qtbot, dap_combo_box):
"""
Test that BECSignalProxy auto-unblocks after the specified timeout if no manual unblock
occurs in the interim.
"""
proxy_container = []
def proxy_callback(*args):
proxy_container.append(args)
# Create the proxy with a short 1-second timeout
proxy = BECSignalProxy(
dap_combo_box.x_axis_updated, rateLimit=25, slot=proxy_callback, timeout=1.0
)
# Initially, ensure it's not blocked
assert proxy.blocked is False
# Trigger the signal once (samx) -> the proxy should block
dap_combo_box.x_axis = "samx"
qtbot.waitSignal(dap_combo_box.x_axis_updated, timeout=1000)
qtbot.wait(100)
assert proxy.blocked is True
# The first signal should be passed immediately to the callback
assert proxy_container == [(("samx",),)]
# While still blocked, set another value (samz)
dap_combo_box.x_axis = "samz"
qtbot.waitSignal(dap_combo_box.x_axis_updated, timeout=1000)
qtbot.wait(100)
# Proxy is still blocked, so the callback shouldn't see "samz" yet
assert len(proxy_container) == 1
# Wait just under 1 second -> should still be blocked
qtbot.wait(700)
assert proxy.blocked is True
# Wait a bit more than 1 s
qtbot.wait(2000)
# Wait to catch the is_blocked signal that indicates it has unblocked
qtbot.waitSignal(proxy.is_blocked, timeout=2000)
# Now it should be unblocked
assert proxy.blocked is False
# The second value "samz" should have been forwarded after auto-unblocking
assert proxy_container == [(("samx",),), (("samz",),)]