Refactor radar system
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
"""The locator test client's framing survives fragmented timeout polls."""
|
||||
|
||||
import socket
|
||||
import threading
|
||||
import unittest
|
||||
from unittest.mock import Mock
|
||||
|
||||
from locator_test_client import encode_packet, read_packet, recv_exactly
|
||||
|
||||
|
||||
class LocatorClientTest(unittest.TestCase):
|
||||
def test_partial_header_and_payload_survive_timeouts(self) -> None:
|
||||
payload = {"vlc": 5.5}
|
||||
packet = encode_packet(payload, 7)
|
||||
sock = Mock()
|
||||
sock.recv.side_effect = [packet[:3], socket.timeout(), packet[3:8],
|
||||
packet[8:10], socket.timeout(), packet[10:]]
|
||||
self.assertEqual(read_packet(sock), (7, payload))
|
||||
|
||||
def test_timeout_wait_can_be_stopped_without_losing_thread(self) -> None:
|
||||
stop = threading.Event()
|
||||
sock = Mock()
|
||||
|
||||
def receive(_size):
|
||||
stop.set()
|
||||
raise socket.timeout()
|
||||
|
||||
sock.recv.side_effect = receive
|
||||
with self.assertRaisesRegex(ConnectionError, "stopped"):
|
||||
recv_exactly(sock, 8, stop)
|
||||
|
||||
def test_eof_in_the_middle_of_packet_is_reported(self) -> None:
|
||||
sock = Mock()
|
||||
sock.recv.side_effect = [b"123", b""]
|
||||
with self.assertRaisesRegex(ConnectionError, "closed"):
|
||||
read_packet(sock)
|
||||
Reference in New Issue
Block a user