Example #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()
    def test_buffered_exception_is_caught(self, mock_make_socket):
        mocket = mock_make_socket.return_value
        mocket.sendall.side_effect = mock.Mock(
            side_effect=socket.error("Test"))
        raw_transport = metrics.RawTransport(EXAMPLE_ENDPOINT)
        transport = metrics.BufferedTransport(raw_transport)
        for i in range(10000):
            transport.send(b"a")

        self.assertEqual(mocket.sendall.call_count, 0)
        transport.flush()
Example #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"))