@@ -151,8 +151,8 @@ async def test_transaction_execute(self, use_clc, scenario):
151151 transact .trace_pdu = mock .Mock (return_value = request )
152152 transact .trace_packet = mock .Mock (return_value = b'123' )
153153 await transact .execute (True , request )
154- # transact.trace_pdu.assert_called_once_with(True, request)
155- # transact.trace_packet.assert_called_once_with(True, b'\x00 \x01\x00u\x00\x05\xec\x02 ')
154+ transact .trace_pdu .assert_called_once_with (True , request )
155+ transact .trace_packet .assert_called_once_with (True , b'\x01 \x01 \x00 u\x00 \x05 \xed \xd3 ' )
156156 elif scenario == 3 : # wait receive,timeout, no_responses
157157 transact .comm_params .timeout_connect = 0.1
158158 transact .count_no_responses = 10
@@ -212,7 +212,7 @@ async def test_client_protocol_execute_outside(self, use_clc, no_resp):
212212 transact .transport .write = mock .Mock ()
213213 resp = asyncio .create_task (transact .execute (no_resp , request ))
214214 await asyncio .sleep (0.2 )
215- data = b"\x00 \x00 \x12 \x34 \x00 \x06 \xff \x01 \x01 \x02 \x00 \x04 "
215+ data = b"\x00 \x00 \x12 \x34 \x00 \x06 \x01 \x01 \x01 \x02 \x00 \x04 "
216216 transact .data_received (data )
217217 result = await resp
218218 if no_resp :
@@ -417,3 +417,76 @@ def test_sync_client_protocol_execute_no_pdu(self, use_clc):
417417 transact .sync_client .send = mock .Mock ()
418418 with pytest .raises (ModbusIOException ):
419419 transact .sync_execute (False , request )
420+
421+ def test_transaction_sync_id0 (self , use_clc ):
422+ """Test id 0 in sync."""
423+ client = ModbusBaseSyncClient (
424+ FramerType .SOCKET ,
425+ 5 ,
426+ use_clc ,
427+ None ,
428+ None ,
429+ None ,
430+ )
431+ transact = TransactionManager (
432+ use_clc ,
433+ FramerRTU (DecodePDU (False )),
434+ 5 ,
435+ False ,
436+ None ,
437+ None ,
438+ None ,
439+ sync_client = client ,
440+ )
441+ transact .sync_client .connect = mock .Mock (return_value = True )
442+ transact .sync_client .send = mock .Mock ()
443+ request = ReadCoilsRequest (address = 117 , count = 5 , dev_id = 0 )
444+ response = ReadCoilsResponse (bits = [True , False , True , True , False , False , False , False ], dev_id = 1 )
445+ transact .retries = 0
446+ transact .transport = 1
447+ resp_bytes = transact .framer .buildFrame (response )
448+ transact .sync_client .recv = mock .Mock (return_value = resp_bytes )
449+ transact .sync_client .send = mock .Mock ()
450+ transact .comm_params .timeout_connect = 0.2
451+ with pytest .raises (ModbusIOException ):
452+ transact .sync_execute (False , request )
453+ response = ReadCoilsResponse (bits = [True , False , True , True , False , False , False , False ], dev_id = 0 )
454+ resp_bytes = transact .framer .buildFrame (response )
455+ transact .sync_client .recv = mock .Mock (return_value = resp_bytes )
456+ resp = transact .sync_execute (False , request )
457+ assert not resp .isError ()
458+
459+ async def test_transaction_id0 (self , use_clc ):
460+ """Test tracers in disconnect."""
461+ transact = TransactionManager (
462+ use_clc ,
463+ FramerRTU (DecodePDU (False )),
464+ 5 ,
465+ False ,
466+ None ,
467+ None ,
468+ None ,
469+ )
470+ transact .send = mock .Mock ()
471+ request = ReadCoilsRequest (address = 117 , count = 5 , dev_id = 1 )
472+ response = ReadCoilsResponse (bits = [True , False , True , True , False ], dev_id = 0 )
473+ transact .retries = 0
474+ transact .connection_made (mock .AsyncMock ())
475+ transact .transport .write = mock .Mock ()
476+ transact .comm_params .timeout_connect = 0.2
477+ resp = asyncio .create_task (transact .execute (False , request ))
478+ await asyncio .sleep (0.1 )
479+ transact .response_future .set_result (response )
480+ await asyncio .sleep (0.1 )
481+ with pytest .raises (ModbusIOException ):
482+ await resp
483+ response = ReadCoilsResponse (bits = [True , False , True , True , False ], dev_id = 1 )
484+ transact .retries = 0
485+ transact .connection_made (mock .AsyncMock ())
486+ transact .transport .write = mock .Mock ()
487+ transact .comm_params .timeout_connect = 0.2
488+ resp = asyncio .create_task (transact .execute (False , request ))
489+ await asyncio .sleep (0.1 )
490+ transact .response_future .set_result (response )
491+ await asyncio .sleep (0.1 )
492+ assert response == await resp
0 commit comments