diff options
author | Erik Johnston <erik@matrix.org> | 2017-01-13 17:46:17 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2017-01-13 17:46:17 +0000 |
commit | 2fae34bd2ce152b8544d5a90fe3b35281c5fffbc (patch) | |
tree | e921c8cdc97983700794520e5426996ef104a2f7 /tests/util/test_lrucache.py | |
parent | Merge pull request #1810 from matrix-org/erikj/state_auth_splitout_split (diff) | |
download | synapse-2fae34bd2ce152b8544d5a90fe3b35281c5fffbc.tar.xz |
Optionally measure size of cache by sum of length of values
Diffstat (limited to 'tests/util/test_lrucache.py')
-rw-r--r-- | tests/util/test_lrucache.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/util/test_lrucache.py b/tests/util/test_lrucache.py index 1eba5b535e..d888a64d0a 100644 --- a/tests/util/test_lrucache.py +++ b/tests/util/test_lrucache.py @@ -232,3 +232,28 @@ class LruCacheCallbacksTestCase(unittest.TestCase): self.assertEquals(m1.call_count, 1) self.assertEquals(m2.call_count, 0) self.assertEquals(m3.call_count, 1) + + +class LruCacheSizedTestCase(unittest.TestCase): + + def test_evict(self): + cache = LruCache(5, size_callback=len) + cache["key1"] = [0] + cache["key2"] = [1, 2] + cache["key3"] = [3] + cache["key4"] = [4] + + self.assertEquals(cache["key1"], [0]) + self.assertEquals(cache["key2"], [1, 2]) + self.assertEquals(cache["key3"], [3]) + self.assertEquals(cache["key4"], [4]) + self.assertEquals(len(cache), 5) + + cache["key5"] = [5, 6] + + self.assertEquals(len(cache), 4) + self.assertEquals(cache.get("key1"), None) + self.assertEquals(cache.get("key2"), None) + self.assertEquals(cache["key3"], [3]) + self.assertEquals(cache["key4"], [4]) + self.assertEquals(cache["key5"], [5, 6]) |