diff options
author | David Baker <dave@matrix.org> | 2016-01-21 19:16:25 +0000 |
---|---|---|
committer | David Baker <dave@matrix.org> | 2016-01-21 19:16:25 +0000 |
commit | f1f81221205cf2ec101f96234050569d6419fd6b (patch) | |
tree | 8cd4e21847d0c63ae70c869ac08575dcc441931e /tests | |
parent | Merge pull request #517 from matrix-org/erikj/push_only_room (diff) | |
download | synapse-f1f81221205cf2ec101f96234050569d6419fd6b.tar.xz |
Change LRUCache to be tree-based so we can delete subtrees.
Diffstat (limited to '')
-rw-r--r-- | tests/storage/test__base.py | 26 | ||||
-rw-r--r-- | tests/util/test_lrucache.py | 44 |
2 files changed, 35 insertions, 35 deletions
diff --git a/tests/storage/test__base.py b/tests/storage/test__base.py index 219288621d..c4e4c9b4bf 100644 --- a/tests/storage/test__base.py +++ b/tests/storage/test__base.py @@ -56,42 +56,42 @@ class CacheTestCase(unittest.TestCase): 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 + cache.prefill((1,), "one") + cache.prefill((2,), "two") + cache.prefill((3,), "three") # 1 will be evicted failed = False try: - cache.get(1) + cache.get((1,)) except KeyError: failed = True self.assertTrue(failed) - cache.get(2) - cache.get(3) + 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") + cache.prefill((1,), "one") + cache.prefill((2,), "two") # Now access 1 again, thus causing 2 to be least-recently used - cache.get(1) + cache.get((1,)) - cache.prefill(3, "three") + cache.prefill((3,), "three") failed = False try: - cache.get(2) + cache.get((2,)) except KeyError: failed = True self.assertTrue(failed) - cache.get(1) - cache.get(3) + cache.get((1,)) + cache.get((3,)) class CacheDecoratorTestCase(unittest.TestCase): diff --git a/tests/util/test_lrucache.py b/tests/util/test_lrucache.py index fbbc5eed15..80c19b944a 100644 --- a/tests/util/test_lrucache.py +++ b/tests/util/test_lrucache.py @@ -21,34 +21,34 @@ from synapse.util.caches.lrucache import LruCache class LruCacheTestCase(unittest.TestCase): def test_get_set(self): - cache = LruCache(1) - cache["key"] = "value" - self.assertEquals(cache.get("key"), "value") - self.assertEquals(cache["key"], "value") + cache = LruCache(1, 1) + cache[("key",)] = "value" + self.assertEquals(cache.get(("key",)), "value") + self.assertEquals(cache[("key",)], "value") def test_eviction(self): - cache = LruCache(2) - cache[1] = 1 - cache[2] = 2 + cache = LruCache(2, 1) + cache[(1,)] = 1 + cache[(2,)] = 2 - self.assertEquals(cache.get(1), 1) - self.assertEquals(cache.get(2), 2) + self.assertEquals(cache.get((1,)), 1) + self.assertEquals(cache.get((2,)), 2) - cache[3] = 3 + cache[(3,)] = 3 - self.assertEquals(cache.get(1), None) - self.assertEquals(cache.get(2), 2) - self.assertEquals(cache.get(3), 3) + self.assertEquals(cache.get((1,)), None) + self.assertEquals(cache.get((2,)), 2) + self.assertEquals(cache.get((3,)), 3) def test_setdefault(self): - cache = LruCache(1) - self.assertEquals(cache.setdefault("key", 1), 1) - self.assertEquals(cache.get("key"), 1) - self.assertEquals(cache.setdefault("key", 2), 1) - self.assertEquals(cache.get("key"), 1) + cache = LruCache(1, 1) + self.assertEquals(cache.setdefault(("key",), 1), 1) + self.assertEquals(cache.get(("key",)), 1) + self.assertEquals(cache.setdefault(("key",), 2), 1) + self.assertEquals(cache.get(("key",)), 1) def test_pop(self): - cache = LruCache(1) - cache["key"] = 1 - self.assertEquals(cache.pop("key"), 1) - self.assertEquals(cache.pop("key"), None) + cache = LruCache(1, 1) + cache[("key",)] = 1 + self.assertEquals(cache.pop(("key",)), 1) + self.assertEquals(cache.pop(("key",)), None) |