0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-13 11:11:49 +02:00
This commit is contained in:
2025-04-18 14:19:35 +02:00
parent c0e4ddf435
commit ebab4d5d2f
2 changed files with 9 additions and 8 deletions

View File

@ -1191,7 +1191,7 @@ class Waveform(PlotBase):
logger.info(f"Setup async curve {name}") logger.info(f"Setup async curve {name}")
@SafeSlot(dict, dict) @SafeSlot(dict, dict)
def on_async_readback(self, msg, metadata): def on_async_readback(self, msg, metadata, skip_sender_validation: bool = False):
""" """
Get async data readback. This code needs to be fast, therefor we try Get async data readback. This code needs to be fast, therefor we try
to reduce the number of copies in between cycles. Be careful when refactoring to reduce the number of copies in between cycles. Be careful when refactoring
@ -1208,6 +1208,7 @@ class Waveform(PlotBase):
Args: Args:
msg(dict): Message with the async data. msg(dict): Message with the async data.
metadata(dict): Metadata of the message. metadata(dict): Metadata of the message.
skip_sender_validation(bool): Skip sender validation. Used for testing. Default is False.
""" """
sender = self.sender() sender = self.sender()
if sender and hasattr(sender, "cb_info"): if sender and hasattr(sender, "cb_info"):
@ -1216,9 +1217,10 @@ class Waveform(PlotBase):
logger.warning("Scan ID mismatch, ignoring async readback.") logger.warning("Scan ID mismatch, ignoring async readback.")
return return
logger.info(f"Async readback for scan ID {scan_id}.") logger.info(f"Async readback for scan ID {scan_id}.")
else: elif not skip_sender_validation:
stack_trace = traceback.extract_stack() stack_trace = traceback.extract_stack()
logger.warning(f"Async readback without scan ID, stack trace: {stack_trace}") logger.warning(f"Async readback without scan ID, stack trace: {stack_trace}")
return
instruction = metadata.get("async_update", {}).get("type") instruction = metadata.get("async_update", {}).get("type")
if instruction not in ["add", "add_slice", "replace"]: if instruction not in ["add", "add_slice", "replace"]:
logger.warning(f"Invalid async update instruction: {instruction}") logger.warning(f"Invalid async update instruction: {instruction}")

View File

@ -541,7 +541,7 @@ def test_on_async_readback_add_update(qtbot, mocked_client):
msg = {"signals": {"async_device": {"value": [100, 200], "timestamp": [1001, 1002]}}} msg = {"signals": {"async_device": {"value": [100, 200], "timestamp": [1001, 1002]}}}
metadata = {"async_update": {"max_shape": [None], "type": "add"}} metadata = {"async_update": {"max_shape": [None], "type": "add"}}
wf.on_async_readback(msg, metadata) wf.on_async_readback(msg, metadata, skip_sender_validation=True)
x_data, y_data = c.get_data() x_data, y_data = c.get_data()
assert len(x_data) == 5 assert len(x_data) == 5
@ -553,7 +553,7 @@ def test_on_async_readback_add_update(qtbot, mocked_client):
# instruction='replace' # instruction='replace'
msg2 = {"signals": {"async_device": {"value": [999], "timestamp": [555]}}} msg2 = {"signals": {"async_device": {"value": [999], "timestamp": [555]}}}
metadata2 = {"async_update": {"max_shape": [None], "type": "replace"}} metadata2 = {"async_update": {"max_shape": [None], "type": "replace"}}
wf.on_async_readback(msg2, metadata2) wf.on_async_readback(msg2, metadata2, skip_sender_validation=True)
x_data2, y_data2 = c.get_data() x_data2, y_data2 = c.get_data()
np.testing.assert_array_equal(x_data2, [0]) np.testing.assert_array_equal(x_data2, [0])
@ -568,7 +568,7 @@ def test_on_async_readback_add_update(qtbot, mocked_client):
metadata = { metadata = {
"async_update": {"max_shape": [None, waveform_shape], "index": 0, "type": "add_slice"} "async_update": {"max_shape": [None, waveform_shape], "index": 0, "type": "add_slice"}
} }
wf.on_async_readback(msg, metadata) wf.on_async_readback(msg, metadata, skip_sender_validation=True)
# Old data should be deleted since the slice_index did not match # Old data should be deleted since the slice_index did not match
x_data, y_data = c.get_data() x_data, y_data = c.get_data()
@ -595,7 +595,7 @@ def test_on_async_readback_add_update(qtbot, mocked_client):
metadata = { metadata = {
"async_update": {"max_shape": [None, waveform_shape], "index": 0, "type": "add_slice"} "async_update": {"max_shape": [None, waveform_shape], "index": 0, "type": "add_slice"}
} }
wf.on_async_readback(msg, metadata) wf.on_async_readback(msg, metadata, skip_sender_validation=True)
x_data, y_data = c.get_data() x_data, y_data = c.get_data()
assert len(y_data) == waveform_shape assert len(y_data) == waveform_shape
assert len(x_data) == waveform_shape assert len(x_data) == waveform_shape
@ -616,8 +616,7 @@ def test_on_async_readback_add_update(qtbot, mocked_client):
} }
} }
metadata = {"async_update": {"type": "replace"}} metadata = {"async_update": {"type": "replace"}}
wf.on_async_readback(msg, metadata) wf.on_async_readback(msg, metadata, skip_sender_validation=True)
x_data, y_data = c.get_data() x_data, y_data = c.get_data()
assert np.array_equal(y_data, np.array(range(waveform_shape))) assert np.array_equal(y_data, np.array(range(waveform_shape)))
assert len(x_data) == waveform_shape assert len(x_data) == waveform_shape