Пример #1
0
 def test_stopwatch(self):
     clock = ManualClock()
     r = Registry(clock=clock)
     t = PercentileTimer(r, "test", min=0, max=100)
     with t.stopwatch():
         clock.set_monotonic_time(1.0)
     self._check_percentiles(t, 0)
Пример #2
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)
Пример #3
0
 def test_ttl_reset(self):
     clock = ManualClock()
     g = Gauge(GaugeTest.tid, clock=clock)
     g.set(42)
     clock.set_wall_time(g.ttl + 1)
     ms = g._measure()
     self.assertTrue(math.isnan(g.get()))
     self.assertEqual(1, len(ms))
     self.assertEqual(42, ms[GaugeTest.tid.with_stat('gauge')])
Пример #4
0
    def test_stopwatch(self):
        clock = ManualClock()
        r = Registry(clock=clock,
                     config=SidecarConfig(
                         {"sidecar.output-location": "memory"}))

        t = PercentileTimer(r, "test")
        with t.stopwatch():
            clock.set_monotonic_time(42)
        self.assertEqual("T:test:42", t._pct_timer._writer.last_line())
Пример #5
0
    def test_get_measurements_gauge_deleted_after_ttl(self):
        clock = ManualClock()
        r = Registry(clock=clock)

        with r.start():
            r.gauge('gauge').set(1)
            ms = r._get_measurements()
            self.assertEqual(1, len(ms))

            clock.set_wall_time(60 * 15 + 1)

            # two cycles are required to delete a gauge after it expires
            ms = r._get_measurements()
            self.assertEqual(1, len(ms))
            ms = r._get_measurements()
            self.assertEqual(0, len(ms))
Пример #6
0
 def test_stopwatch(self):
     clock = ManualClock()
     t = Timer(self.tid, clock=clock, meter_type="T", writer=MemoryWriter())
     with t.stopwatch():
         clock.set_monotonic_time(42)
     self.assertEqual("T:test:42", t._writer.last_line())