Beispiel #1
0
    def run(self):
        """Runs the UDP server.

        While running, the server receives, processes, and replies to
        messages. Only a proportion of messages, equal to the server's
        reliability, are successfully processed.

        Returns
        -------
        None

        """
        super().run()
        while self.is_running():
            message, addr = self._server_socket.recvfrom(1024)
            if not utils.will_drop_message(self._reliability):
                self._server_socket.sendto(
                    utils.process_message(message.decode()).encode(), addr)
def test_unreliable(mock_random):
    assert will_drop_message(0)
    mock_random.assert_called_once_with(1, 100)
def test_mostly_reliable_above_threshold(mock_random):
    assert not will_drop_message(0.7)
    mock_random.assert_called_once_with(1, 100)