Skip to content

Don't invoke trace_connect callback twice #2670

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

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
2 changes: 0 additions & 2 deletions pymodbus/server/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ def __init__( # pylint: disable=too-many-arguments

def callback_new_connection(self):
"""Handle incoming connect."""
if self.trace_connect:
self.trace_connect(True)
return ServerRequestHandler(
self,
self.trace_packet,
Expand Down
13 changes: 13 additions & 0 deletions test/server/test_server_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,19 @@ async def test_async_server_file_descriptors(self): # pragma: no cover
assert not response.isError()
client.close()

async def test_async_server_trace_connect_disconnect(self):
"""Test connect/disconnect trace handler."""
trace_connect = mock.Mock()
await self.start_server()
self.server.trace_connect = trace_connect
await self.connect_server()
trace_connect.assert_called_once_with(True)
trace_connect.reset_mock()

BasicClient.transport.close()
await asyncio.sleep(0.2) # so we have to wait a bit
trace_connect.assert_called_once_with(False)

async def test_async_tcp_server_connection_lost(self):
"""Test tcp stream interruption."""
await self.start_server()
Expand Down
19 changes: 19 additions & 0 deletions test/transaction/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,25 @@ async def test_transaction_sync_pdu_send(self, use_clc):
transact.pdu_send(ExceptionResponse(0xff), (0,0))
assert transact.sent_buffer == b'\x01\xff\x00a\xf0'

async def test_transaction_connect(self, use_clc):
"""Test tracers in disconnect."""
transact = TransactionManager(
use_clc,
FramerRTU(DecodePDU(False)),
5,
False,
None,
None,
None,
)
transact.trace_packet = mock.Mock()
transact.trace_pdu = mock.Mock()
transact.trace_connect = mock.Mock()
transact.callback_connected()
transact.trace_connect.assert_called_once_with(True)
transact.trace_packet.assert_not_called()
transact.trace_pdu.assert_not_called()

async def test_transaction_disconnect(self, use_clc):
"""Test tracers in disconnect."""
transact = TransactionManager(
Expand Down