Skip to content

Commit

Permalink
Fix traversal of the python picklecache ring when invalidating if the…
Browse files Browse the repository at this point in the history
… order doesn't exactly match the ring
  • Loading branch information
jamadden committed Feb 18, 2014
1 parent 690441d commit 7ba32a9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion persistent/picklecache.py
Expand Up @@ -122,7 +122,7 @@ def mru(self, oid):
# splice into new
self.ring.prev.next, node.prev = node, self.ring.prev
self.ring.prev, node.next = node, self.ring

def ringlen(self):
""" See IPickleCache.
"""
Expand Down Expand Up @@ -257,5 +257,6 @@ def _invalidate(self, oid):
if node.object is value:
node.prev.next, node.next.prev = node.next, node.prev
break
node = node.next
elif oid in self.persistent_classes:
del self.persistent_classes[oid]
19 changes: 19 additions & 0 deletions persistent/tests/test_picklecache.py
Expand Up @@ -661,6 +661,25 @@ def test_invalidate_hit_multiple_mixed(self):
self.assertEqual(c1._p_state, GHOST)
self.assertEqual(c2._p_state, GHOST)

def test_invalidate_hit_multiple_non_ghost(self):
from persistent.interfaces import UPTODATE
from persistent.interfaces import GHOST
from persistent._compat import _b
KEY = _b('123')
KEY2 = _b('456')
cache = self._makeOne()
c1 = self._makePersist(oid=KEY, jar=cache.jar, state=UPTODATE)
cache[KEY] = c1
c2 = self._makePersist(oid=KEY2, jar=cache.jar, state=UPTODATE)
cache[KEY2] = c2
self.assertEqual(cache.ringlen(), 2)
# These should be in the opposite order of how they were
# added to the ring to ensure ring traversal works
cache.invalidate([KEY2, KEY])
self.assertEqual(cache.ringlen(), 0)
self.assertEqual(c1._p_state, GHOST)
self.assertEqual(c2._p_state, GHOST)

def test_invalidate_hit_pclass(self):
from persistent._compat import _b
KEY = _b('123')
Expand Down

0 comments on commit 7ba32a9

Please sign in to comment.