Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix eiger stream data publish #93

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dev = [
"pre-commit",
"pydata-sphinx-theme>=0.12",
"pytest-cov",
"pytest-mock",
"pytest-mypy",
"pytest-flake8",
"pytest-black",
Expand Down
4 changes: 2 additions & 2 deletions src/tickit_devices/eiger/eiger_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,5 +430,5 @@ def __init__(self, device: EigerDevice) -> None:

def after_update(self) -> None:
"""Updates IOC values immediately following a device update."""
buffered_data = self.device.stream.consume_data()
self.add_message_to_stream([list(buffered_data)])
if buffered_data := list(self.device.stream.consume_data()):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good patch but I think the proper fix is in the ZMQ adapter itself, have made an issue: DiamondLightSource/tickit#196

self.add_message_to_stream(buffered_data)
21 changes: 21 additions & 0 deletions tests/eiger/test_eiger_adapters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from pytest_mock import MockerFixture

from tickit_devices.eiger.eiger_adapters import EigerZMQAdapter


def test_after_update(mocker: MockerFixture) -> None:
test_data = [b"data", b"some more data"]

# Mock consume_data to return with data the first time and nothing the second time
device_mock = mocker.MagicMock()
device_mock.stream.consume_data.side_effect = [test_data, []]

zmq_adapter = EigerZMQAdapter(device_mock)
add_mock = mocker.patch.object(zmq_adapter, "add_message_to_stream")

# Test after_update only calls add_message_to_stream with non-empty data
zmq_adapter.after_update()
add_mock.assert_called_once_with(test_data)
add_mock.reset_mock()
zmq_adapter.after_update()
add_mock.assert_not_called()