Пример #1
0
 def test_measure(self):
     g = Gauge(GaugeTest.tid)
     g.set(42)
     ms = g._measure()
     self.assertEqual(42, g.get())
     self.assertEqual(1, len(ms))
     self.assertEqual(42, ms[GaugeTest.tid.with_stat('gauge')])
Пример #2
0
 def test_measure(self):
     g = Gauge(GaugeTest.tid)
     g.set(42)
     ms = g._measure()
     self.assertTrue(math.isnan(g.get()))
     self.assertEqual(len(ms), 1)
     self.assertEqual(ms[GaugeTest.tid.with_stat('gauge')], 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 gauge(self, name, tags=None):
     return self._new_meter(name, tags, lambda id: Gauge(id), Gauge,
                            self.noopGauge)
Пример #5
0
 def test_set(self):
     g = Gauge(GaugeTest.tid)
     self.assertTrue(math.isnan(g.get()))
     g.set(1)
     self.assertEqual(g.get(), 1)
Пример #6
0
 def test_get(self):
     """Avoid breaking the API."""
     g = Gauge(self.tid, writer=MemoryWriter())
     g.set(1)
     self.assertEqual(0, g.get())
Пример #7
0
 def test_custom_ttl(self):
     g = Gauge(self.tid, ttl_seconds=120, writer=MemoryWriter())
     g.set(42)
     self.assertEqual("g,120:test:42", g._writer.last_line())
Пример #8
0
    def test_set(self):
        g = Gauge(self.tid, writer=MemoryWriter())
        self.assertTrue(g._writer.is_empty())

        g.set(1)
        self.assertEqual("g:test:1", g._writer.last_line())
Пример #9
0
 def gauge(self, name: str, tags: Optional[dict] = None,
           ttl_seconds: Optional[int] = None) -> Gauge:
     return Gauge(self._new_meter(name, tags), ttl_seconds=ttl_seconds, writer=self._writer)
Пример #10
0
 def test_user_statistic(self):
     g = Gauge(GaugeTest.tid.with_stat('duration'))
     g.set(42)
     for id in g._measure().keys():
         self.assertEqual('duration', id.tags()['statistic'])