Ejemplo n.º 1
0
 def test_iterate(self):
     r = Registry()
     r.counter("counter")
     r.timer("timer")
     meters = 0
     for m in r:
         meters += 1
     self.assertEqual(2, meters)
Ejemplo n.º 2
0
    def test_iterate(self):
        """Avoid breaking the API."""
        r = Registry(
            config=SidecarConfig({"sidecar.output-location": "memory"}))

        for _ in r:
            self.fail("registry should be empty")

        r.counter("counter")
        r.timer("timer")

        for _ in r:
            self.fail("registry no longer holds references to MeterIds")
Ejemplo n.º 3
0
 def test_timer(self):
     r = Registry()
     t = r.timer("test")
     self.assertEqual(t.count(), 0)
     t.record(42)
     self.assertEqual(t.count(), 1)
     self.assertEqual(t.total_time(), 42)
Ejemplo n.º 4
0
 def test_timer_with(self):
     clock = ManualClock()
     r = Registry(clock)
     t = r.timer("test")
     with t.stopwatch():
         clock.set_monotonic_time(42)
     self.assertEqual(t.count(), 1)
     self.assertEqual(t.total_time(), 42)
Ejemplo n.º 5
0
    def test_timer(self):
        r = Registry(
            config=SidecarConfig({"sidecar.output-location": "memory"}))

        t = r.timer("test")
        self.assertTrue(t._writer.is_empty())

        t.record(42)
        self.assertEqual("t:test:42", t._writer.last_line())
Ejemplo n.º 6
0
    def test_timer_stopwatch(self):
        clock = ManualClock()
        r = Registry(clock=clock,
                     config=SidecarConfig(
                         {"sidecar.output-location": "memory"}))

        t = r.timer("test")
        with t.stopwatch():
            clock.set_monotonic_time(42)
        self.assertEqual("t:test:42", t._writer.last_line())
Ejemplo n.º 7
0
 def test_do_post_encode(self):
     r = Registry()
     client = HttpClient(r)
     client.post_json(self._uri, {"status": 202})
     tags = {
         "mode": "http-client",
         "method": "POST",
         "client": "spectator-py",
         "status": "2xx",
         "statusCode": "202"
     }
     t = r.timer("http.req.complete", tags)
     self.assertEqual(t.count(), 1)
Ejemplo n.º 8
0
 def test_do_post_bad_json(self):
     r = Registry()
     client = HttpClient(r)
     client.post_json(self._uri, '{"status": ', retry_delay=0)
     tags = {
         "mode": "http-client",
         "method": "POST",
         "client": "spectator-py",
         "status": "4xx",
         "statusCode": "400"
     }
     t = r.timer("http.req.complete", tags)
     self.assertEqual(t.count(), 1)
Ejemplo n.º 9
0
 def test_do_post_network_error(self):
     self.tearDown()
     r = Registry()
     client = HttpClient(r)
     client.post_json(self._uri, "{}")
     tags = {
         "mode": "http-client",
         "method": "POST",
         "client": "spectator-py",
         "status": "URLError",
         "statusCode": "URLError"
     }
     t = r.timer("http.req.complete", tags)
     self.assertEqual(t.count(), 1)
Ejemplo n.º 10
0
 def test_timer_and_counter_same_name_different_tags(self):
     r = Registry()
     c = r.counter("check_value", tags=dict(tag="a"))
     t = r.timer("check_value", tags=dict(tag="b"))
     self.assertIsNot(c, t)
     self.assertIsNot(t, r.noopTimer)
Ejemplo n.º 11
0
 def test_duplicate_timer_different_type(self):
     r = Registry()
     c = r.counter("check_value")
     t = r.timer("check_value")
     self.assertIsNot(c, t)
     self.assertIs(t, r.noopTimer)