def test_gauge_delta(self): client = TCPClient("localhost") client._socket = self.mock_socket client.gauge_delta("memory!", 128) self.mock_sendall.assert_called_with("memory:+128|g\n".encode()) client.prefix = "region." client.gauge_delta("cpu percentage%", rate=0.9, delta=-12) self.mock_sendall.assert_called_with( "region.cpu_percentage:-12|g|@0.9\n".encode() ) self.mock_sendall.reset_mock() client.gauge_delta("low.rate", 10, 0.1) self.assertEqual(self.mock_sendall.call_count, 0)
def test_set(self): client = TCPClient("localhost") client._socket = self.mock_socket client.set("ip address", "10.10.10.1") self.mock_sendall.assert_called_with( "ip_address:10.10.10.1|s\n".encode() ) client.prefix = "region." client.set("~username*", rate=0.9, value='first') self.mock_sendall.assert_called_with( "region.username:first|s|@0.9\n".encode() ) self.mock_sendall.reset_mock() client.set("low.rate", 256, 0.1) self.assertEqual(self.mock_sendall.call_count, 0)
def test_gauge(self): client = TCPClient("localhost") client._socket = self.mock_socket client.gauge("memory", 10240) self.mock_sendall.assert_called_with( "memory:10240|g\n".encode() ) client.prefix = "region." client.gauge("cpu percentage%", rate=0.9, value=98.3) self.mock_sendall.assert_called_with( "region.cpu_percentage:98.3|g|@0.9\n".encode() ) self.mock_sendall.reset_mock() client.gauge("low.rate", 128, 0.1) self.assertEqual(self.mock_sendall.call_count, 0) self.assertRaises(AssertionError, client.gauge, "negative", -5)
def test_timing(self): client = TCPClient("localhost") client._socket = self.mock_socket client.timing("event", 10) self.mock_sendall.assert_called_with( "event:10|ms\n".encode() ) client.timing("db.event name", 34.5, 0.5) self.mock_sendall.assert_called_with( "db.event_name:34|ms|@0.5\n".encode(), ) client.prefix = "region.c_" client.timing("db/query", rate=0.7, milliseconds=22.22) self.mock_sendall.assert_called_with( "region.c_db-query:22|ms|@0.7\n".encode(), ) self.mock_sendall.reset_mock() client.timing("low.rate", 12, rate=0.1) self.assertEqual(self.mock_sendall.call_count, 0) self.assertRaises(AssertionError, client.timing, "negative", -2)