def test_is_meter_registered_returning_true_for_meter_that_exists(self): registry.MeterRegistry._meters = dict() test_counter = meters.Counter("test_counter") registry.MeterRegistry._meters = dict() registry.MeterRegistry.add_meter(test_counter) self.assertTrue( registry.MeterRegistry.is_meter_registered(test_counter))
def test_add_meter_enters_new_meter_into_meters_dictionary(self): registry.MeterRegistry._meters = dict() test_counter = meters.Counter("test_counter") registry.MeterRegistry._meters = dict() registry.MeterRegistry.add_meter(test_counter) self.assertEqual(registry.MeterRegistry._meters, {(meters.Counter, "test_counter"): test_counter})
def test_counters_increment_as_expected(self): test_counter = meters.Counter("test_counter") test_counter.increment() test_counter.increment() loop = asyncio.get_event_loop() actual = loop.run_until_complete( loop.create_task(test_counter.get_metrics())) expected = [ meters.Metric(name='test_counter', tags=(), value=2, prometheus_type='counter') ] self.assertEqual(actual, expected)
def test_counters_wrap_functions_as_expected(self): test_counter = meters.Counter("test_counter") @test_counter.auto_count_method def bogus_function(): pass bogus_function() loop = asyncio.get_event_loop() actual = loop.run_until_complete( loop.create_task(test_counter.get_metrics())) expected = [ meters.Metric(name='test_counter', tags=(), value=1, prometheus_type='counter') ] self.assertEqual(actual, expected)
def test_that_meters_are_auto_registering_themselves(self): registry.MeterRegistry._meters = dict() test_counter = meters.Counter("test_counter") self.assertTrue( registry.MeterRegistry.is_meter_registered(test_counter))