Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Add simple test for invalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Jul 20, 2022
1 parent 81b01f0 commit 9d5d72f
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tests/util/test_dict_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class DictCacheTestCase(unittest.TestCase):
def setUp(self):
self.cache = DictionaryCache("foobar")
self.cache = DictionaryCache("foobar", max_entries=10)

def test_simple_cache_hit_full(self):
key = "test_simple_cache_hit_full"
Expand Down Expand Up @@ -91,3 +91,26 @@ def test_multi_insert(self):
c.value,
)
self.assertEqual(c.full, False)

def test_invalidation(self):
"""Test that the partial dict and full dicts get invalidated
separately.
"""
key = "some_key"

seq = self.cache.sequence
self.cache.update(seq, key, {"a": "b", "c": "d"})

for i in range(20):
self.cache.get(key, ["a"])
self.cache.update(seq, f"key{i}", {1: 2})

# We should have evicted the full dict...
r = self.cache.get(key)
self.assertFalse(r.full)
self.assertTrue("c" not in r.value)

# ... but kept the "a" entry that we kept querying.
r = self.cache.get(key, dict_keys=["a"])
self.assertFalse(r.full)
self.assertEqual(r.value, {"a": "b"})

0 comments on commit 9d5d72f

Please sign in to comment.