Re-establish the OSError being raised to match former behavior, but still reconnect. TBD if this is quite the right approach.

This commit is contained in:
Ian McEwen
2026-05-31 14:53:46 -07:00
parent 12509bef30
commit 435e53eae2
2 changed files with 9 additions and 7 deletions

View File

@@ -86,9 +86,9 @@ def test_TCPInterface_reconnect():
iface = TCPInterface(hostname="localhost", noProto=True)
old_socket = iface.socket
assert old_socket is not None
iface._reconnect()
assert old_socket.close.called
# We expect socket class to be instantiated at least twice (init + reconnect)
assert mock_socket.call_count >= 2
@@ -96,13 +96,14 @@ def test_TCPInterface_reconnect():
@pytest.mark.unit
def test_TCPInterface_writeBytes_reconnects():
"""Test that _writeBytes calls _reconnect on OSError"""
"""Test that _writeBytes reconnects and re-raises on OSError."""
with patch("socket.socket"):
iface = TCPInterface(hostname="localhost", noProto=True)
iface.socket.sendall.side_effect = OSError("Broken pipe")
with patch.object(iface, '_reconnect') as mock_reconnect:
iface._writeBytes(b"some data")
with patch.object(iface, "_reconnect") as mock_reconnect:
with pytest.raises(OSError, match="Broken pipe"):
iface._writeBytes(b"some data")
mock_reconnect.assert_called_once()
@@ -113,7 +114,7 @@ def test_TCPInterface_readBytes_reconnects():
iface = TCPInterface(hostname="localhost", noProto=True)
# Mock the socket instance on the interface
iface.socket.recv.return_value = b''
with patch.object(iface, '_reconnect') as mock_reconnect:
iface._readBytes(10)
mock_reconnect.assert_called_once()