Commit eee74faf authored by Julien Muchembled's avatar Julien Muchembled

tests: check case of multiple conflict resolutions for the same (oid, txn)

parent 15bcd495
...@@ -318,40 +318,67 @@ class Test(NEOThreadedTest): ...@@ -318,40 +318,67 @@ class Test(NEOThreadedTest):
t.commit() t.commit()
self.assertEqual(ob._p_changed, 0) self.assertEqual(ob._p_changed, 0)
oid = ob._p_oid oid = ob._p_oid
tid1 = ob._p_serial tid0 = ob._p_serial
self.assertNotEqual(tid1, ZERO_TID) self.assertNotEqual(tid0, ZERO_TID)
del ob, t, c del ob, t, c
# then check resolution # then check resolution
t1, c1 = cluster.getTransaction() t1, c1 = cluster.getTransaction()
t2, c2 = cluster.getTransaction() t2, c2 = cluster.getTransaction()
t3, c3 = cluster.getTransaction()
o1 = c1.root()['with_resolution'] o1 = c1.root()['with_resolution']
o2 = c2.root()['with_resolution'] o2 = c2.root()['with_resolution']
o3 = c3.root()['with_resolution']
self.assertEqual(o1.value, 0) self.assertEqual(o1.value, 0)
self.assertEqual(o2.value, 0) self.assertEqual(o2.value, 0)
o1.value += 1 self.assertEqual(o3.value, 0)
o2.value += 2 o1.value += 3
o2.value += 5
o3.value += 7
t1.commit() t1.commit()
self.assertEqual(o1._p_changed, 0) self.assertEqual(o1._p_changed, 0)
tid2 = o1._p_serial self.assertEqual(o1.value, 3)
self.assertTrue(tid1 < tid2) tid1 = o1._p_serial
self.assertEqual(o1.value, 1)
self.assertEqual(o2.value, 2) resolved = []
t2.commit() last = (t2.get(), t3.get()).index
def _handleConflicts(orig, txn_context, *args):
resolved.append(last(txn_context['txn']))
return orig(txn_context, *args)
def tpc_vote(orig, transaction, *args):
(l3 if last(transaction) else l2)()
return orig(transaction, *args)
with Patch(cluster.client, _handleConflicts=_handleConflicts):
with LockLock() as l3, Patch(cluster.client, tpc_vote=tpc_vote):
with LockLock() as l2:
tt = []
for t, l in (t2, l2), (t3, l3):
tt.append(self.newThread(t.commit))
l()
tt.pop(0).join()
self.assertEqual(o2._p_changed, None) self.assertEqual(o2._p_changed, None)
self.assertEqual(o2.value, 8)
tid2 = o2._p_serial
tt.pop(0).join()
self.assertEqual(o3._p_changed, None)
self.assertEqual(o3.value, 15)
tid3 = o3._p_serial
self.assertEqual(resolved, [0, 1, 1])
self.assertTrue(tid0 < tid1 < tid2 < tid3)
t1.begin() t1.begin()
t2.begin() t2.begin()
self.assertEqual(o2.value, 3) t3.begin()
self.assertEqual(o1.value, 3) self.assertIs(o1._p_changed, None)
tid3 = o1._p_serial self.assertIs(o2._p_changed, None)
self.assertTrue(tid2 < tid3) self.assertEqual(o3._p_changed, 0)
self.assertEqual(tid3, o2._p_serial) self.assertEqual(o1.value, 15)
self.assertEqual(o2.value, 15)
# check history # check history
history = c1.db().history self.assertEqual([x['tid'] for x in c1.db().history(oid, size=10)],
self.assertEqual([x['tid'] for x in history(oid, size=1)], [tid3]) [tid3, tid2, tid1, tid0])
self.assertEqual([x['tid'] for x in history(oid, size=10)],
[tid3, tid2, tid1])
finally: finally:
cluster.stop() cluster.stop()
......
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