diff options
author | Paul "LeoNerd" Evans <paul@matrix.org> | 2015-03-04 17:34:23 +0000 |
---|---|---|
committer | Paul "LeoNerd" Evans <paul@matrix.org> | 2015-03-12 16:24:50 +0000 |
commit | 8664599af77ba0ed6268b3112174dc8e0c91101b (patch) | |
tree | 204e482555e1dbb4a0cf3731442a65d9aad91ed2 /tests/metrics | |
parent | Ensure that exceptions while rendering individual metrics don't stop others f... (diff) | |
download | synapse-8664599af77ba0ed6268b3112174dc8e0c91101b.tar.xz |
Rename CacheCounterMetric to just CacheMetric; add a CallbackMetric component to give the size of the cache
Diffstat (limited to 'tests/metrics')
-rw-r--r-- | tests/metrics/test_metric.py | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/tests/metrics/test_metric.py b/tests/metrics/test_metric.py index b7bb375ce0..32fd178ed4 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, CacheCounterMetric + CounterMetric, CallbackMetric, CacheMetric ) @@ -81,26 +81,32 @@ class CallbackMetricTestCase(unittest.TestCase): ]) -class CacheCounterMetricTestCase(unittest.TestCase): +class CacheMetricTestCase(unittest.TestCase): - def test_cachecounter(self): - counter = CacheCounterMetric("cache") + def test_cache(self): + d = dict() - self.assertEquals(counter.render(), [ + metric = CacheMetric("cache", lambda: len(d)) + + self.assertEquals(metric.render(), [ "cache:hits 0", "cache:misses 0", + "cache:size 0", ]) - counter.inc_misses() + metric.inc_misses() + d["key"] = "value" - self.assertEquals(counter.render(), [ + self.assertEquals(metric.render(), [ "cache:hits 0", "cache:misses 1", + "cache:size 1", ]) - counter.inc_hits() + metric.inc_hits() - self.assertEquals(counter.render(), [ + self.assertEquals(metric.render(), [ "cache:hits 1", "cache:misses 1", + "cache:size 1", ]) |