Beispiel #1
0
 async def test_enable_debug(self, udp_server):
     client: aio_statsd.StatsdClient = aio_statsd.StatsdClient(port=9999,
                                                               debug=True)
     await client.connect()
     client.counter("test.key", 1)
     assert await udp_server.get() == b"test.key:1|c"
     await client.close()
Beispiel #2
0
 async def test_tcp_server(self, tcp_server):
     client: aio_statsd.StatsdClient = aio_statsd.StatsdClient(
         port=9999, protocol=aio_statsd.ProtocolFlag.tcp)
     await client.connect()
     client.counter("test.key", 1)
     assert await tcp_server.get() == b"test.key:1|c"
     await client.close()
Beispiel #3
0
 async def test_protocol_send_msg_timeout(self, udp_server: asyncio.Queue) -> None:
     """TODO ...."""
     client: aio_statsd.StatsdClient = aio_statsd.StatsdClient(port=9999, timeout=1)
     await client.connect()
     client.counter("test.key", 1)
     client.counter("test.key", 1)
     await client.close()
Beispiel #4
0
    async def test_error_transport_layer_protocol(self) -> None:
        with pytest.raises(ConnectionError) as e:
            client: aio_statsd.StatsdClient = aio_statsd.StatsdClient(port=9999, protocol="error")  # type:ignore
            await client.connect()

        exec_msg = e.value.args[0]
        assert exec_msg == "Not support protocol:error"
Beispiel #5
0
    async def test_client_context_manager(self, udp_server):
        async with aio_statsd.StatsdClient(port=9999) as client:
            client.counter("test.key", 1)
            assert await udp_server.get() == b"test.key:1|c"

            # test close client contenxt manager until send all msg
            for i in range(100000):
                client.counter("test.key", i)
Beispiel #6
0
    async def test_connection_refused(self) -> None:
        with pytest.raises(ConnectionError) as e:
            client: aio_statsd.StatsdClient = aio_statsd.StatsdClient(port=9999, timeout=1)
            await client.connect()
            client.counter("test.key", 1)
            await asyncio.sleep(1)
            client.counter("test.key", 1)

            await asyncio.sleep(1)
            client.counter("test.key", 1)

            await asyncio.sleep(1)
            client.counter("test.key", 1)
            await client.close()

        exec_msg = e.value.args[0]
        assert exec_msg == "StatsdClient already close."
Beispiel #7
0
async def statsd_client():
    client: aio_statsd.StatsdClient = aio_statsd.StatsdClient(port=9999)
    await client.connect()
    yield client
    await client.close()
Beispiel #8
0
async def statsd_client() -> AsyncGenerator[aio_statsd.StatsdClient, None]:
    client: aio_statsd.StatsdClient = aio_statsd.StatsdClient(port=9999)
    await client.connect()
    yield client
    await client.close()