summary refs log tree commit diff
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2015-03-25 18:50:43 +0000
committerPaul "LeoNerd" Evans <paul@matrix.org>2015-03-25 18:50:43 +0000
commit7ab9f91a605d501cadee1c212eca2ef0467adc50 (patch)
treedc6a16aae510ddf562c7e83c933020b3004d95a0
parentReduce activity timer granularity to avoid too many quick updates (SYN-247) (diff)
downloadsynapse-7ab9f91a605d501cadee1c212eca2ef0467adc50.tar.xz
Unit-test that Cache() key eviction is ordered
Diffstat (limited to '')
-rw-r--r--tests/storage/test__base.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/storage/test__base.py b/tests/storage/test__base.py
index 783abc2b00..b6853ba2d4 100644
--- a/tests/storage/test__base.py
+++ b/tests/storage/test__base.py
@@ -51,6 +51,24 @@ class CacheTestCase(unittest.TestCase):
 
         self.assertTrue(failed)
 
+    def test_eviction(self):
+        cache = Cache("test", max_entries=2)
+
+        cache.prefill(1, "one")
+        cache.prefill(2, "two")
+        cache.prefill(3, "three")  # 1 will be evicted
+
+        failed = False
+        try:
+            cache.get(1)
+        except KeyError:
+            failed = True
+
+        self.assertTrue(failed)
+
+        cache.get(2)
+        cache.get(3)
+
 
 class CacheDecoratorTestCase(unittest.TestCase):