summary refs log tree commit diff
path: root/tests/util/test_lrucache.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-08-19 15:58:52 +0100
committerErik Johnston <erik@matrix.org>2016-08-19 16:09:16 +0100
commit45fd2c8942009a634cf38a90ca1f306aae7022fc (patch)
treea37d4431236537d669209c10281e3d798fcc21fa /tests/util/test_lrucache.py
parentRename to on_invalidate (diff)
downloadsynapse-45fd2c8942009a634cf38a90ca1f306aae7022fc.tar.xz
Ensure invalidation list does not grow unboundedly
Diffstat (limited to 'tests/util/test_lrucache.py')
-rw-r--r--tests/util/test_lrucache.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/util/test_lrucache.py b/tests/util/test_lrucache.py
index bacec2f465..1eba5b535e 100644
--- a/tests/util/test_lrucache.py
+++ b/tests/util/test_lrucache.py
@@ -50,6 +50,8 @@ class LruCacheTestCase(unittest.TestCase):
         self.assertEquals(cache.get("key"), 1)
         self.assertEquals(cache.setdefault("key", 2), 1)
         self.assertEquals(cache.get("key"), 1)
+        cache["key"] = 2  # Make sure overriding works.
+        self.assertEquals(cache.get("key"), 2)
 
     def test_pop(self):
         cache = LruCache(1)
@@ -84,6 +86,44 @@ class LruCacheTestCase(unittest.TestCase):
 
 
 class LruCacheCallbacksTestCase(unittest.TestCase):
+    def test_get(self):
+        m = Mock()
+        cache = LruCache(1)
+
+        cache.set("key", "value")
+        self.assertFalse(m.called)
+
+        cache.get("key", callback=m)
+        self.assertFalse(m.called)
+
+        cache.get("key", "value")
+        self.assertFalse(m.called)
+
+        cache.set("key", "value2")
+        self.assertEquals(m.call_count, 1)
+
+        cache.set("key", "value")
+        self.assertEquals(m.call_count, 1)
+
+    def test_multi_get(self):
+        m = Mock()
+        cache = LruCache(1)
+
+        cache.set("key", "value")
+        self.assertFalse(m.called)
+
+        cache.get("key", callback=m)
+        self.assertFalse(m.called)
+
+        cache.get("key", callback=m)
+        self.assertFalse(m.called)
+
+        cache.set("key", "value2")
+        self.assertEquals(m.call_count, 1)
+
+        cache.set("key", "value")
+        self.assertEquals(m.call_count, 1)
+
     def test_set(self):
         m = Mock()
         cache = LruCache(1)