Fix noop metrics timed decorator
Previously if you did not have the monasca statds available, the @timed decorator would result in a NoneType error because timed was returning None instead of acting as a noop function wrapper. This change updates the NoopTimer to properly handle timed being used as a function. Change-Id: Ic5543b3503b24aaef960d8b7c0cb38940241cbcb Closes-Bug: #1659638
This commit is contained in:
parent
9a466ed738
commit
dc34ed43dd
|
@ -69,7 +69,9 @@ class NoopTimer(object):
|
|||
pass
|
||||
|
||||
def timed(self, *a, **kw):
|
||||
pass
|
||||
def wrapper(func):
|
||||
return func
|
||||
return wrapper
|
||||
|
||||
|
||||
class Client(object):
|
||||
|
|
|
@ -53,6 +53,15 @@ class TestNoopMetrics(TestCase):
|
|||
self.assertIsInstance(self.metrics.timer(), noop.NoopTimer)
|
||||
self.assertIsNotNone(self.metrics.timed.__self__)
|
||||
|
||||
def test_noop_metrics_client_timed(self):
|
||||
timer = self.metrics._client.get_timer()
|
||||
|
||||
@timer.timed('timed.test')
|
||||
def func(a):
|
||||
return a
|
||||
result = func(1)
|
||||
self.assertEqual(result, 1)
|
||||
|
||||
|
||||
class TestMonascaMetrics(TestCase):
|
||||
|
||||
|
@ -86,3 +95,12 @@ class TestMonascaMetrics(TestCase):
|
|||
self.assertIsInstance(self.metrics.timer(),
|
||||
monascastatsd.timer.Timer)
|
||||
self.assertIsNotNone(self.metrics.timed.__self__)
|
||||
|
||||
def test_monasca_metrics_client_timed(self):
|
||||
timer = self.metrics._client.get_timer()
|
||||
|
||||
@timer.timed('timed.test')
|
||||
def func(a):
|
||||
return a
|
||||
result = func(1)
|
||||
self.assertEqual(result, 1)
|
||||
|
|
Loading…
Reference in New Issue