コード例 #1
0
def test_api_request_size_dynamic(mock_flush, caplog, zuqa_client):
    zuqa_client.config.update(version="1", api_request_size="100b")
    transport = Transport(client=zuqa_client, metadata={}, queue_chill_count=1)
    transport.start_thread()
    try:
        with caplog.at_level("DEBUG", "zuqa.transport"):
            # we need to add lots of uncompressible data to fill up the gzip-internal buffer
            for i in range(12):
                transport.queue(
                    "error", "".join(
                        random.choice(string.ascii_letters)
                        for i in range(2000)))
            transport._flushed.wait(timeout=0.1)
        assert mock_flush.call_count == 1
        zuqa_client.config.update(version="1", api_request_size="1mb")
        with caplog.at_level("DEBUG", "zuqa.transport"):
            # we need to add lots of uncompressible data to fill up the gzip-internal buffer
            for i in range(12):
                transport.queue(
                    "error", "".join(
                        random.choice(string.ascii_letters)
                        for i in range(2000)))
            transport._flushed.wait(timeout=0.1)
        # Should be unchanged because our buffer limit is much higher.
        assert mock_flush.call_count == 1
    finally:
        transport.close()
コード例 #2
0
def test_forced_flush(mock_send, caplog, zuqa_client):
    transport = Transport(client=zuqa_client, metadata={}, compress_level=0)
    transport.start_thread()
    try:
        with caplog.at_level("DEBUG", "zuqa.transport"):
            transport.queue("error", "x", flush=True)
    finally:
        transport.close()
    assert mock_send.call_count == 1
    assert transport._queued_data is None
コード例 #3
0
def test_flush_time_size(mock_flush, caplog, zuqa_client):
    transport = Transport(client=zuqa_client, metadata={}, queue_chill_count=1)
    transport.start_thread()
    try:
        with caplog.at_level("DEBUG", "zuqa.transport"):
            # we need to add lots of uncompressible data to fill up the gzip-internal buffer
            for i in range(12):
                transport.queue(
                    "error", "".join(
                        random.choice(string.ascii_letters)
                        for i in range(2000)))
            transport._flushed.wait(timeout=0.1)
        assert mock_flush.call_count == 1
    finally:
        transport.close()
コード例 #4
0
def test_metadata_prepended(mock_send, zuqa_client):
    transport = Transport(client=zuqa_client,
                          metadata={"x": "y"},
                          compress_level=0)
    transport.start_thread()
    transport.queue("error", {}, flush=True)
    transport.close()
    assert mock_send.call_count == 1
    args, kwargs = mock_send.call_args
    if compat.PY2:
        data = gzip.GzipFile(fileobj=compat.StringIO(args[0])).read()
    else:
        data = gzip.decompress(args[0])
    data = data.decode("utf-8").split("\n")
    assert "metadata" in data[0]
コード例 #5
0
def test_sync_transport_fail_and_recover(mock_send, caplog):
    transport = Transport(client=None)
    transport.start_thread()
    try:
        mock_send.side_effect = TransportException("meh")
        transport.queue("x", {})
        transport.flush()
        assert transport.state.did_fail()
        # first retry should be allowed immediately
        assert transport.state.should_try()

        # recover
        mock_send.side_effect = None
        transport.queue("x", {})
        transport.flush()
        assert not transport.state.did_fail()
    finally:
        transport.close()