Fixes prometheus start metric

This commit is contained in:
Evan Cordell 2016-09-30 12:56:53 -04:00
parent 2d9ce6dbe3
commit 68c5384473
2 changed files with 17 additions and 4 deletions

View file

@ -2,7 +2,7 @@ import time
import unittest
from mock import Mock
from trollius import coroutine, Return, get_event_loop
from trollius import coroutine, Return, get_event_loop, From
from util.metrics.metricqueue import duration_collector_async
@ -25,6 +25,10 @@ def duration_decorated():
def duration_decorated_error():
raise NonReturn("not a Return error")
@coroutine
def calls_decorated():
yield From(duration_decorated())
class DurationDecoratorTestCase(unittest.TestCase):
def __init__(self, *args, **kwargs):
@ -44,7 +48,15 @@ class DurationDecoratorTestCase(unittest.TestCase):
with self.assertRaises(NonReturn):
self.loop.run_until_complete(duration_decorated_error())
assert not mock_histogram.Observe.called
def test_duration_decorator_caller(self):
mock_histogram.reset_mock()
self.loop.run_until_complete(calls_decorated())
assert mock_histogram.Observe.called
assert 1 - mock_histogram.Observe.call_args[0][0] < 1 # duration should be close to 1s
assert mock_histogram.Observe.call_args[1]["labelvalues"] == ["testlabel"]
if __name__ == '__main__':
unittest.main()