diff options
Diffstat (limited to 'statsd/tests.py')
-rw-r--r-- | statsd/tests.py | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/statsd/tests.py b/statsd/tests.py index da52182..751815c 100644 --- a/statsd/tests.py +++ b/statsd/tests.py @@ -236,20 +236,28 @@ def test_timer_manager(): def test_timer_decorator(): - """StatsClient.timer is a decorator.""" + """StatsClient.timer is a thread-safe decorator.""" sc = _client() + @sc.timer('foo') + def foo(a, b): + return [a, b] + @sc.timer('bar') - def bar(): - pass + def bar(a, b): + return [b, a] - bar() - _timer_check(sc, 1, 'bar', 'ms') + # make sure it works with more than one decorator, called multiple times, + # and that parameters are handled correctly + eq_([4, 2], foo(4, 2)) + _timer_check(sc, 1, 'foo', 'ms') - # Make sure the decorator works more than once: - bar() + eq_([2, 4], bar(4, 2)) _timer_check(sc, 2, 'bar', 'ms') + eq_([6, 5], bar(5, 6)) + _timer_check(sc, 3, 'bar', 'ms') + def test_timer_capture(): """You can capture the output of StatsClient.timer.""" @@ -273,13 +281,19 @@ def test_timer_context_rate(): def test_timer_decorator_rate(): sc = _client() - @sc.timer('bar', rate=0.1) - def bar(): - pass + @sc.timer('foo', rate=0.1) + def foo(a, b): + return [b, a] + + @sc.timer('bar', rate=0.2) + def bar(a, b=2, c=3): + return [c, b, a] - bar() + eq_([2, 4], foo(4, 2)) + _timer_check(sc, 1, 'foo', 'ms|@0.1') - _timer_check(sc, 1, 'bar', 'ms|@0.1') + eq_([3, 2, 5], bar(5)) + _timer_check(sc, 2, 'bar', 'ms|@0.2') def test_timer_context_exceptions(): |