async def test_sample_rate(self, mocker, telegraf_statsd_client: aio_statsd.TelegrafStatsdClient): telegraf_statsd_client_deque = telegraf_statsd_client._deque mocked_deque = mocker.patch.object(telegraf_statsd_client, "_deque") telegraf_statsd_client.increment("test.key", 1, sample_rate=1) mocked_deque.appendleft.assert_called_once_with("test.key:+1|g") mocked_deque = mocker.patch.object(telegraf_statsd_client, "_deque") mocker.patch("aio_statsd.client.random", return_value=0.9) telegraf_statsd_client.increment("test.key", 2, sample_rate=0.8) mocked_deque.appendleft.assert_called_once_with("test.key:+2|g|@0.8") mocked_deque = mocker.patch.object(telegraf_statsd_client, "_deque") mocker.patch("aio_statsd.client.random", return_value=0.3) telegraf_statsd_client.increment("test.key", 3, sample_rate=0.5) mocked_deque.appendleft.assert_not_called() telegraf_statsd_client._deque = telegraf_statsd_client_deque
async def test_increment(self, telegraf_statsd_client: aio_statsd.TelegrafStatsdClient, udp_server): telegraf_statsd_client.increment("test.key", 1) assert await udp_server.get() == b"test.key:+1|g"