Commit badd9de3 authored by Julien Muchembled's avatar Julien Muchembled

client: add assertion in cache to detect wrong invalidation

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