Skip to content

Commit 837750d

Browse files
committed
TestBasicModbusProtocol: Add tests for broadcast and local echo
Broadcast packets do not wait for a response and thus any local echo will be stuck in the recieve buffer. Test to ensure a subsequent packet can be sent after the broadcast and that the local echo is handled correctly. Three tests are done: one where the broadcast echo and the subsequent message echo are returned in two calls to datagram_recieved(), one where the entire response is in one call, and one where the echo for the message packet is split over two datagram_received() calls.
1 parent f08af1e commit 837750d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/sub_transport/test_basic.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,31 @@ async def test_handle_local_echo(self, client):
162162
assert client.recv_buffer == b"response"
163163
assert not client.sent_buffer
164164

165+
async def test_broadcast_local_echo(self, client):
166+
"""Test transport_send() with broadcast and echo packets"""
167+
client.comm_params.handle_local_echo = True
168+
client.transport = mock.Mock()
169+
client.recv_buffer = b""
170+
client.transport_send(b"broadcast")
171+
client.transport_send(b"message")
172+
client.datagram_received(b"broadcast", ("127.0.0.1", 502))
173+
client.datagram_received(b"messageresponse", ("127.0.0.1", 502))
174+
assert client.recv_buffer == b"response"
175+
assert not client.sent_buffer
176+
client.recv_buffer = b""
177+
client.transport_send(b"broadcast")
178+
client.transport_send(b"message")
179+
client.datagram_received(b"broadcastmessageresponse", ("127.0.0.1", 502))
180+
assert client.recv_buffer == b"response"
181+
assert not client.sent_buffer
182+
client.recv_buffer = b""
183+
client.transport_send(b"broadcast")
184+
client.transport_send(b"message")
185+
client.datagram_received(b"broadcastmessa", ("127.0.0.1", 502))
186+
client.datagram_received(b"geresponse", ("127.0.0.1", 502))
187+
assert client.recv_buffer == b"response"
188+
assert not client.sent_buffer
189+
165190
async def test_transport_close(self, server, dummy_protocol):
166191
"""Test transport_close()."""
167192
dummy_protocol.abort = mock.MagicMock()

0 commit comments

Comments
 (0)