Skip to content

Commit bb41048

Browse files
author
sanjay
committed
Fix failing tests
1 parent 67ab76a commit bb41048

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

pymodbus/transaction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ def execute(self, request):
171171
mbap = self.client.framer.decode_data(response)
172172
if (mbap.get('unit') == request.unit_id):
173173
break
174-
if ('lenght' in mbap and expected_response_length and
175-
mbap.get('lenght') == expected_response_length):
174+
if ('length' in mbap and expected_response_length and
175+
mbap.get('length') == expected_response_length):
176176
break
177177
_logger.debug("Retry on invalid - {}".format(retries))
178178
if hasattr(self.client, "state"):

test/test_transaction.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ def testExecute(self):
123123
response = tm.execute(request)
124124
self.assertIsInstance(response, ModbusIOException)
125125

126+
# retry on invalid response
127+
tm.retry_on_invalid = True
128+
tm._recv = MagicMock(side_effect=iter([b'', b'abcdef', b'deadbe', b'123456']))
129+
# tm._transact.side_effect = [(b'', None), (b'abcdef', None)]
130+
response = tm.execute(request)
131+
self.assertIsInstance(response, ModbusIOException)
132+
126133
# Unable to decode response
127134
tm._recv = MagicMock(side_effect=ModbusIOException())
128135
# tm._transact.side_effect = [(b'abcdef', None)]

0 commit comments

Comments
 (0)