summary refs log tree commit diff
path: root/tests/storage/test__base.py
diff options
context:
space:
mode:
authorDavid Baker <dave@matrix.org>2015-04-17 13:51:10 +0100
committerDavid Baker <dave@matrix.org>2015-04-17 13:51:10 +0100
commitcb03fafdf150cb97d494c1a12efb730e01309fb2 (patch)
tree5c6994f2ec826599984d7a621caeb889aeef4c57 /tests/storage/test__base.py
parentRegister the 3pid servlet (diff)
parentFilter typing nofication events to only those rooms the requesting user is a ... (diff)
downloadsynapse-cb03fafdf150cb97d494c1a12efb730e01309fb2.tar.xz
Merge branch 'develop' into csauth
Diffstat (limited to 'tests/storage/test__base.py')
-rw-r--r--tests/storage/test__base.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/storage/test__base.py b/tests/storage/test__base.py
index 783abc2b00..96caf8c4c1 100644
--- a/tests/storage/test__base.py
+++ b/tests/storage/test__base.py
@@ -51,6 +51,46 @@ 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)
+
+    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):