diff options
author | Olivier Wilkinson (reivilibre) <oliverw@matrix.org> | 2021-12-14 14:22:01 +0000 |
---|---|---|
committer | Olivier Wilkinson (reivilibre) <oliverw@matrix.org> | 2021-12-14 14:22:01 +0000 |
commit | 4dd9ea8f4fc002f35fa604361a792ea1d3d6671c (patch) | |
tree | 1690b0d4658301b51907afeacf9e46bda7ce1152 /tests/util/test_lrucache.py | |
parent | Revert accidental fast-forward merge from v1.49.0rc1 (diff) | |
download | synapse-4dd9ea8f4fc002f35fa604361a792ea1d3d6671c.tar.xz |
Revert "Revert accidental fast-forward merge from v1.49.0rc1"
This reverts commit 158d73ebdd61eef33831ae5f6990acf07244fc55.
Diffstat (limited to '')
-rw-r--r-- | tests/util/test_lrucache.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/util/test_lrucache.py b/tests/util/test_lrucache.py index 6578f3411e..291644eb7d 100644 --- a/tests/util/test_lrucache.py +++ b/tests/util/test_lrucache.py @@ -13,6 +13,7 @@ # limitations under the License. +from typing import List from unittest.mock import Mock from synapse.util.caches.lrucache import LruCache, setup_expire_lru_cache_entries @@ -261,6 +262,17 @@ class LruCacheSizedTestCase(unittest.HomeserverTestCase): self.assertEquals(cache["key4"], [4]) self.assertEquals(cache["key5"], [5, 6]) + def test_zero_size_drop_from_cache(self) -> None: + """Test that `drop_from_cache` works correctly with 0-sized entries.""" + cache: LruCache[str, List[int]] = LruCache(5, size_callback=lambda x: 0) + cache["key1"] = [] + + self.assertEqual(len(cache), 0) + cache.cache["key1"].drop_from_cache() + self.assertIsNone( + cache.pop("key1"), "Cache entry should have been evicted but wasn't" + ) + class TimeEvictionTestCase(unittest.HomeserverTestCase): """Test that time based eviction works correctly.""" |