summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/metrics/test_metric.py36
1 files changed, 35 insertions, 1 deletions
diff --git a/tests/metrics/test_metric.py b/tests/metrics/test_metric.py
index b7facb8587..b25520821d 100644
--- a/tests/metrics/test_metric.py
+++ b/tests/metrics/test_metric.py
@@ -16,7 +16,7 @@
 from tests import unittest
 
 from synapse.metrics.metric import (
-    CounterMetric, CallbackMetric, CacheMetric
+    CounterMetric, CallbackMetric, TimerMetric, CacheMetric
 )
 
 
@@ -97,6 +97,40 @@ class CallbackMetricTestCase(unittest.TestCase):
         ])
 
 
+class TimerMetricTestCase(unittest.TestCase):
+
+    def test_scalar(self):
+        metric = TimerMetric("thing")
+
+        self.assertEquals(metric.render(), [
+            "thing:count 0",
+            "thing:msec 0",
+        ])
+
+        metric.inc_time(500)
+
+        self.assertEquals(metric.render(), [
+            "thing:count 1",
+            "thing:msec 500",
+        ])
+
+    def test_vector(self):
+        metric = TimerMetric("queries", keys=["verb"])
+
+        self.assertEquals(metric.render(), [])
+
+        metric.inc_time(300, "SELECT")
+        metric.inc_time(200, "SELECT")
+        metric.inc_time(800, "INSERT")
+
+        self.assertEquals(metric.render(), [
+            "queries{verb=INSERT}:count 1",
+            "queries{verb=INSERT}:msec 800",
+            "queries{verb=SELECT}:count 2",
+            "queries{verb=SELECT}:msec 500",
+        ])
+
+
 class CacheMetricTestCase(unittest.TestCase):
 
     def test_cache(self):