Commit badd9de3 by Julien Muchembled

client: add assertion in cache to detect wrong invalidation

1 parent 9682722b
......@@ -205,6 +205,7 @@ class ClientCache(object):
insort(item_list, item)
else:
prev = item_list[-1]
assert prev.next_tid <= tid, (prev, item)
item.counter = prev.counter
prev.counter = 0
if prev.level > 1:
......@@ -275,6 +276,7 @@ def test(self):
cache.store(1, '10', 10, 15)
cache.store(1, '20', 20, 21)
self.assertEqual([5, 10, 15, 20], [x.tid for x in cache._oid_dict[1]])
self.assertRaises(AssertionError, cache.store, 1, '20', 20, None)
if __name__ == '__main__':
import unittest
......
......@@ -697,8 +697,6 @@ class Test(NEOThreadedTest):
t1, c1 = cluster.getTransaction()
c1.root()['x'] = x = PCounter()
t1.commit()
t1.begin()
x._p_deactivate()
# We need a second client for external invalidations.
t2 = transaction.TransactionManager()
db = DB(storage=cluster.getZODBStorage(client=cluster.newClient()))
......@@ -720,10 +718,12 @@ class Test(NEOThreadedTest):
self.assertFalse(storage.tm._transaction_dict)
finally:
db.close()
# Clearing cache is the easiest way to check we did't get an
# invalidation, which would cause a failure in _setstate_noncurrent
c1._storage._cache.clear()
self.assertFalse(x.value)
# Check we did't get an invalidation, which would cause an
# assertion failure in the cache. Connection does the same check in
# _setstate_noncurrent so this could be also done by starting a
# transaction before the last one, and clearing the cache before
# reloading x.
c1._storage.load(x._p_oid)
t0, t1, t2 = c1._storage.iterator()
self.assertEqual(map(u64, t0.oid_list), [0])
self.assertEqual(map(u64, t1.oid_list), [0, 1])
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!