Skip to content

Commit

Permalink
Test receiving FIN packet while disconnected.
Browse files Browse the repository at this point in the history
  • Loading branch information
Renelvon committed Jun 10, 2015
1 parent f94c8c6 commit c6d2f56
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
16 changes: 16 additions & 0 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,19 @@ def test_syn_repeat(self):

self.assertEqual(json.loads(m_calls[-1][0][0]), expected_fin_packet)
self.assertEqual(m_calls[-1][0][1], address)

def test_receive_fin_packet_while_disconnected(self):
fin_rudp_packet = packet.RUDPPacket(
0,
self.own_addr,
self.addr1,
fin=True
)

self.proto_mock.reset_mock()
self.handler_mock.reset_mock()

self.con.receive_packet(fin_rudp_packet)
connection.REACTOR.runUntilCurrent()

self.handler_mock.handle_shutdown.assert_not_called()
9 changes: 5 additions & 4 deletions txrudp/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ def receive_packet(self, rudp_packet):
that the packet had already been validated against
packet.RUDP_PACKET_JSON_SCHEMA.
"""
if rudp_packet.fin:
self.shutdown()
elif self.connected:
self._process_casual_packet(rudp_packet)
if self.connected:
if rudp_packet.fin:
self.shutdown()
else:
self._process_casual_packet(rudp_packet)
elif rudp_packet.syn:
self._process_syn_packet(rudp_packet)

Expand Down

0 comments on commit c6d2f56

Please sign in to comment.