Skip to content

Commit

Permalink
Fix retransmission of packets.
Browse files Browse the repository at this point in the history
Previously the padding bytes were being included twice in retransmitted
packets. This fixes that bug and introduces a test to ensure that
retransmitted packets are transmitted exactly.
  • Loading branch information
mundya committed May 14, 2015
1 parent 915698e commit f25c795
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 1 addition & 2 deletions rig/machine_control/scp_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ def __init__(self, callback, packet, expected_args, extra_timeout):
raise TimeoutError(self.n_tries)

# Otherwise we retransmit it
self.sock.send(b"\x00\x00" + outstanding.packet)
# self.sock.send(outstanding.packet)
self.sock.send(outstanding.packet)
outstanding.n_tries += 1
outstanding.time_sent = current_time

Expand Down
15 changes: 15 additions & 0 deletions tests/machine_control/test_scp_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,21 @@ def test_single_packet_times_out(self, mock_conn):
"""Test correct operation for transmitting a single packet which is
never acknowledged.
"""
# Create a callable for the socket send that asserts that we always
# send the same packet.
class Send(object):
def __init__(self):
self.last_packet = None

def __call__(self, packet):
if self.last_packet is None:
self.last_packet = packet
else:
assert self.last_packet == packet

mock_conn.sock.send.side_effect = Send()

# Create a generator of packets to send
def packets():
# Yield a single packet
yield scpcall(3, 5, 0, 12)
Expand Down

0 comments on commit f25c795

Please sign in to comment.