fix(controller): add configurable timeout, en/disable controller axes on on/off

This commit is contained in:
2025-11-25 09:34:06 +01:00
committed by Christian Appel
parent 69f7a353cf
commit 2fb64e995e
6 changed files with 176 additions and 46 deletions

View File

@@ -1,4 +1,7 @@
import socket
from unittest import mock
import pytest
from ophyd_devices.utils.socket import SocketIO
@@ -62,6 +65,21 @@ def test_open():
assert socketio.sock.port == socketio.port
def test_socket_open_with_timeout():
dsocket = DummySocket()
socketio = SocketIO("localhost", 8080)
socketio.sock = dsocket
with mock.patch.object(dsocket, "connect") as mock_connect:
socketio.open(timeout=0.1)
mock_connect.assert_called_once()
mock_connect.reset_mock()
# There is a 1s sleep in the retry loop, mock_connect should be called only once
mock_connect.side_effect = Exception("Connection failed")
with pytest.raises(ConnectionError):
socketio.open(timeout=0.4)
mock_connect.assert_called_once()
def test_close():
socketio = SocketIO("localhost", 8080)
socketio.close()