summary refs log tree commit diff
path: root/tests/metrics/test_metric.py
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2015-03-04 17:58:10 +0000
committerPaul "LeoNerd" Evans <paul@matrix.org>2015-03-12 16:24:50 +0000
commit23ab0c68c28e60e0f8774ee4099b2abe876374d0 (patch)
treefe26017e4b235653aaa99cfb48e348094c8c0838 /tests/metrics/test_metric.py
parentNeater introspection methods on BaseMetric so that subclasses don't need to t... (diff)
downloadsynapse-23ab0c68c28e60e0f8774ee4099b2abe876374d0.tar.xz
Implement vector CallbackMetrics
Diffstat (limited to 'tests/metrics/test_metric.py')
-rw-r--r--tests/metrics/test_metric.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/tests/metrics/test_metric.py b/tests/metrics/test_metric.py
index 32fd178ed4..b7facb8587 100644
--- a/tests/metrics/test_metric.py
+++ b/tests/metrics/test_metric.py
@@ -65,7 +65,7 @@ class CounterMetricTestCase(unittest.TestCase):
 
 class CallbackMetricTestCase(unittest.TestCase):
 
-    def test_callback(self):
+    def test_scalar(self):
         d = dict()
 
         metric = CallbackMetric("size", lambda: len(d))
@@ -80,6 +80,22 @@ class CallbackMetricTestCase(unittest.TestCase):
             "size 1",
         ])
 
+    def test_vector(self):
+        vals = dict()
+
+        metric = CallbackMetric("values", lambda: vals, keys=["type"])
+
+        self.assertEquals(metric.render(), [])
+
+        # Keys have to be tuples, even if they're 1-element
+        vals[("foo",)] = 1
+        vals[("bar",)] = 2
+
+        self.assertEquals(metric.render(), [
+            "values{type=bar} 2",
+            "values{type=foo} 1",
+        ])
+
 
 class CacheMetricTestCase(unittest.TestCase):