def test_timing(self): mock_gevent_pool = mock(gevent_pool) when(mock_gevent_pool).full().thenReturn(False) when(mock_gevent_pool).spawn(any(), any(), any()).thenReturn(None) client = gevent_statsd.GEventStatsdClient('localhost', 8125, prefix='', sample_rate=None) client._send_pool = mock_gevent_pool client.timing('buck.timing', 100) verify(mock_gevent_pool).spawn(any(), b'buck.timing:100|ms', any())
def test_send_sample_rate(self): mock_gevent_pool = mock(gevent_pool) when(mock_gevent_pool).full().thenReturn(False) when(mock_gevent_pool).spawn(any(), any(), any()).thenReturn(None) client = gevent_statsd.GEventStatsdClient('localhost', 8125, prefix='', sample_rate=0.999) client._send_pool = mock_gevent_pool client._send(b'buck', b'50|c') verify(mock_gevent_pool).spawn(any(), b'buck:50|c|@0.999', any())
def test_incr(self): mock_gevent_pool = mock(gevent_pool) when(mock_gevent_pool).full().thenReturn(False) when(mock_gevent_pool).spawn(any(), any(), any()).thenReturn(None) client = gevent_statsd.GEventStatsdClient('localhost', 8125, prefix='', sample_rate=None) client._send_pool = mock_gevent_pool client.incr('buck.counter', 5) verify(mock_gevent_pool).spawn(any(), b'buck.counter:5|c', any())
def test_sub(self): mock_gevent_pool = mock(gevent_pool) when(mock_gevent_pool).full().thenReturn(False) when(mock_gevent_pool).spawn(any(), any(), any()).thenReturn(None) client = gevent_statsd.GEventStatsdClient('localhost', 8125, prefix='', sample_rate=None) client._send_pool = mock_gevent_pool counter = statsd.StatsdCounter('counted', client) counter -= 1 verify(mock_gevent_pool).spawn(any(), b'counted:-1|c', any()) counter -= 5 verify(mock_gevent_pool).spawn(any(), b'counted:-5|c', any())
def test_with(self): mock_gevent_pool = mock(gevent_pool) when(mock_gevent_pool).full().thenReturn(False) when(mock_gevent_pool).spawn(any(), any(), any()).thenReturn(None) client = gevent_statsd.GEventStatsdClient('localhost', 8125, prefix='', sample_rate=None) client._send_pool = mock_gevent_pool timer = statsd.StatsdTimer('timeit', client) with timer: time.sleep(0.25) verify(mock_gevent_pool).spawn(any(), contains(b'timeit.total:'), any())
def test_prefix(self): mock_gevent_pool = mock(gevent_pool) when(mock_gevent_pool).full().thenReturn(False) when(mock_gevent_pool).spawn(any(), any(), any()).thenReturn(None) client = gevent_statsd.GEventStatsdClient('localhost', 8125, prefix='main.bucket', sample_rate=None) client._send_pool = mock_gevent_pool client._send(b'subname', b'100|c') verify(mock_gevent_pool).spawn(any(), b'main.bucket.subname:100|c', any()) client = gevent_statsd.GEventStatsdClient('localhost', 8125, prefix='main', sample_rate=None) client._send_pool = mock_gevent_pool client._send(b'subname', b'100|c') verify(mock_gevent_pool).spawn(any(), b'main.subname:100|c', any()) client._send(b'subname.subsubname', b'100|c') verify(mock_gevent_pool).spawn(any(), b'main.subname.subsubname:100|c', any())