Exemplo n.º 1
0
 def test_publish_retry(self):
     # raise two errors and then return a mock response
     self.session.post.side_effect = [
         requests.HTTPError(504), IOError,
         mock.Mock()
     ]
     spans = b"[]"
     self.publisher.publish(SerializedBatch(count=1, bytes=spans))
     self.assertEqual(self.session.post.call_count, 3)
Exemplo n.º 2
0
    def test_client_error(self):
        self.session.post.side_effect = [
            requests.HTTPError(400, response=mock.Mock(status_code=400))
        ]
        spans = b"[]"

        with self.assertRaises(requests.HTTPError):
            self.publisher.publish(SerializedBatch(count=1, bytes=spans))

        self.assertEqual(self.session.post.call_count, 1)
Exemplo n.º 3
0
    def test_fail_on_client_error(self, mock_sleep):
        self.session.post.side_effect = [
            requests.HTTPError(400, response=mock.Mock(status_code=400))
        ]
        events = b'[{"example": "value"}]'

        with self.assertRaises(requests.HTTPError):
            self.publisher.publish(SerializedBatch(count=1, bytes=events))

        self.assertEqual(mock_sleep.call_count, 0)
        self.assertEqual(self.session.post.call_count, 1)
Exemplo n.º 4
0
    def test_publish_retry(self, mock_sleep):
        self.session.post.side_effect = [
            requests.HTTPError(504), IOError,
            mock.Mock()
        ]
        events = b'[{"example": "value"}]'

        self.publisher.publish(SerializedBatch(count=1, bytes=events))

        self.assertEqual(mock_sleep.call_count, 2)
        self.assertEqual(self.session.post.call_count, 3)
Exemplo n.º 5
0
    def test_publish_success(self):
        events = b'[{"example": "value"}]'

        self.publisher.publish(SerializedBatch(count=1, bytes=events))

        self.assertEqual(self.session.post.call_count, 1)

        args, kwargs = self.session.post.call_args
        headers = kwargs.get("headers", {})
        self.assertEqual(args[0], "https://test.local/v1")
        self.assertEqual(headers["Content-Type"], "application/json")
        self.assertEqual(
            headers["X-Signature"],
            "key=TestKey, mac=7c46d56b99cd4cb05e08238c1d4c10a2f330795e9d7327f17cc66fd206bf1179"
        )
Exemplo n.º 6
0
 def test_empty_batch(self):
     self.publisher.publish(SerializedBatch(count=0, bytes=b''))
     self.assertEqual(self.session.post.call_count, 0)
Exemplo n.º 7
0
 def serialize(self):
     header = (self._header % len(self._items)).encode()
     return SerializedBatch(count=len(self._items),
                            bytes=header + b",".join(self._items) +
                            self._end)