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 16:46:44 +0000
committerPaul "LeoNerd" Evans <paul@matrix.org>2015-03-12 16:24:50 +0000
commitd8caa5454d781a76a65fa4ce75336541b973f624 (patch)
tree949ce9f638861c360722fbbb3161193c4dabec7c /tests/metrics/test_metric.py
parentSprinkle some CacheCounterMetrics around the synapse.storage layer (diff)
downloadsynapse-d8caa5454d781a76a65fa4ce75336541b973f624.tar.xz
Initial attempt at a scalar callback-based metric to give instantaneous snapshot gauges
Diffstat (limited to '')
-rw-r--r--tests/metrics/test_metric.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/tests/metrics/test_metric.py b/tests/metrics/test_metric.py
index 93e8e27e4f..b7bb375ce0 100644
--- a/tests/metrics/test_metric.py
+++ b/tests/metrics/test_metric.py
@@ -15,7 +15,9 @@
 
 from tests import unittest
 
-from synapse.metrics.metric import CounterMetric, CacheCounterMetric
+from synapse.metrics.metric import (
+    CounterMetric, CallbackMetric, CacheCounterMetric
+)
 
 
 class CounterMetricTestCase(unittest.TestCase):
@@ -61,6 +63,24 @@ class CounterMetricTestCase(unittest.TestCase):
         ])
 
 
+class CallbackMetricTestCase(unittest.TestCase):
+
+    def test_callback(self):
+        d = dict()
+
+        metric = CallbackMetric("size", lambda: len(d))
+
+        self.assertEquals(metric.render(), [
+            "size 0",
+        ])
+
+        d["key"] = "value"
+
+        self.assertEquals(metric.render(), [
+            "size 1",
+        ])
+
+
 class CacheCounterMetricTestCase(unittest.TestCase):
 
     def test_cachecounter(self):