4
4
from binascii import Error as BinError
5
5
from decoy import Decoy
6
6
from mock import AsyncMock , MagicMock
7
+ from opentrons .drivers .asyncio .communication .errors import NoResponse
7
8
from opentrons .drivers .asyncio .communication .serial_connection import (
8
9
AsyncResponseSerialConnection ,
9
10
)
@@ -591,7 +592,7 @@ async def test_get_tof_histogram_frame(
591
592
get_measurement = types .GCODE .GET_TOF_MEASUREMENT .build_command ().add_element (
592
593
types .TOFSensor .X .name
593
594
)
594
- connection .send_command .assert_any_call (get_measurement )
595
+ connection .send_command .assert_any_call (get_measurement , retries = 0 )
595
596
connection .reset_mock ()
596
597
597
598
# Test cancel transfer
@@ -611,7 +612,7 @@ async def test_get_tof_histogram_frame(
611
612
.add_element (types .TOFSensor .X .name )
612
613
.add_element ("R" )
613
614
)
614
- connection .send_command .assert_any_call (get_measurement )
615
+ connection .send_command .assert_any_call (get_measurement , retries = 0 )
615
616
connection .reset_mock ()
616
617
617
618
# Test invalid index response
@@ -675,7 +676,7 @@ async def test_get_tof_histogram(
675
676
types .TOFSensor .X .name
676
677
)
677
678
connection .send_command .assert_any_call (manage_measurement )
678
- connection .send_command .assert_any_call (get_measurement )
679
+ connection .send_command .assert_any_call (get_measurement , retries = 0 )
679
680
connection .reset_mock ()
680
681
681
682
# Test invalid frame_id
@@ -699,7 +700,33 @@ async def test_get_tof_histogram(
699
700
types .TOFSensor .X .name
700
701
)
701
702
connection .send_command .assert_any_call (manage_measurement )
702
- connection .send_command .assert_any_call (get_measurement )
703
+ connection .send_command .assert_any_call (get_measurement , retries = 0 )
704
+ connection .reset_mock ()
705
+
706
+ # Test resend mechanism
707
+ get_measurement = (
708
+ types .GCODE .GET_TOF_MEASUREMENT .build_command ()
709
+ .add_element (types .TOFSensor .X .name )
710
+ .add_element ("R" )
711
+ )
712
+ payload = [p for p in get_histogram_payload (30 )]
713
+ connection .send_command .side_effect = [
714
+ "M215 X:1 T:2 M:3" ,
715
+ "M225 X K:0 C:1 L:3840" ,
716
+ payload [0 ],
717
+ payload [1 ],
718
+ # We raise NoResponse on frame 3 to simulate a timeout and force a resend
719
+ NoResponse ("" , "Timeout" ),
720
+ # After the timeout we expect the same packet to be resent
721
+ payload [2 ]
722
+ # Then the rest of the packets
723
+ ] + payload [3 :]
724
+
725
+ response = await subject .get_tof_histogram (types .TOFSensor .X )
726
+
727
+ connection .send_command .assert_any_call (manage_measurement )
728
+ # Assert that the M226 GCODE with `R` (resend) element was sent
729
+ connection .send_command .assert_any_call (get_measurement , retries = 0 )
703
730
connection .reset_mock ()
704
731
705
732
0 commit comments