summary refs log tree commit diff
path: root/tests/storage/test__base.py
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2015-03-25 19:05:34 +0000
committerPaul "LeoNerd" Evans <paul@matrix.org>2015-03-25 19:05:34 +0000
commit9ba6487b3fe985c4ec84b02d9804aea7e2df6c40 (patch)
tree031159b1398664dc27ed6bc7a0d6917924258312 /tests/storage/test__base.py
parentImplement the 'key in dict' test for LruCache() (diff)
downloadsynapse-9ba6487b3fe985c4ec84b02d9804aea7e2df6c40.tar.xz
Allow a choice of LRU behaviour for Cache() by using LruCache() or OrderedDict()
Diffstat (limited to 'tests/storage/test__base.py')
-rw-r--r--tests/storage/test__base.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/storage/test__base.py b/tests/storage/test__base.py
index b6853ba2d4..96caf8c4c1 100644
--- a/tests/storage/test__base.py
+++ b/tests/storage/test__base.py
@@ -69,6 +69,28 @@ class CacheTestCase(unittest.TestCase):
         cache.get(2)
         cache.get(3)
 
+    def test_eviction_lru(self):
+        cache = Cache("test", max_entries=2, lru=True)
+
+        cache.prefill(1, "one")
+        cache.prefill(2, "two")
+
+        # Now access 1 again, thus causing 2 to be least-recently used
+        cache.get(1)
+
+        cache.prefill(3, "three")
+
+        failed = False
+        try:
+            cache.get(2)
+        except KeyError:
+            failed = True
+
+        self.assertTrue(failed)
+
+        cache.get(1)
+        cache.get(3)
+
 
 class CacheDecoratorTestCase(unittest.TestCase):