Beispiel #1
0
    def test_buffered_exception_is_caught(self):
        raw_transport = metrics.RawTransport(EXAMPLE_ENDPOINT)
        transport = metrics.BufferedTransport(raw_transport)
        transport.send(b"x" * 65536)

        with self.assertRaises(metrics.MessageTooBigTransportError):
            transport.flush()
Beispiel #2
0
    def test_sent_immediately(self, mock_make_socket):
        mocket = mock_make_socket.return_value
        transport = metrics.RawTransport(EXAMPLE_ENDPOINT)

        self.assertEqual(mocket.connect.call_args, mock.call(("127.0.0.1", 1234)))

        transport.send(b"metric")

        self.assertEqual(mocket.sendall.call_count, 1)
        self.assertEqual(mocket.sendall.call_args, mock.call(b"metric"))
Beispiel #3
0
    def test_buffered(self, mock_make_socket):
        mocket = mock_make_socket.return_value
        raw_transport = metrics.RawTransport(EXAMPLE_ENDPOINT)
        transport = metrics.BufferedTransport(raw_transport)
        transport.send(b"a")
        transport.send(b"b")
        transport.send(b"c")
        self.assertEqual(mocket.sendall.call_count, 0)
        transport.flush()

        self.assertEqual(mocket.sendall.call_count, 1)
        self.assertEqual(mocket.sendall.call_args, mock.call(b"a\nb\nc"))