Commit f1f02e6a authored by Michael Dunstan's avatar Michael Dunstan

- Ensure that tests actually invoke conflict resolution.

- Updated to use transaction.commit() rather than
  get_transaction().commit()
parent 8ce1295b
...@@ -17,18 +17,22 @@ from unittest import TestCase, TestSuite, makeSuite ...@@ -17,18 +17,22 @@ from unittest import TestCase, TestSuite, makeSuite
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from ZODB.FileStorage import FileStorage from ZODB.FileStorage import FileStorage
from ZODB.DB import DB from ZODB.DB import DB
import transaction
from Products.Transience.Transience import Length2, Increaser from Products.Transience.Transience import Length2, Increaser
# Test pattern is copied from BTrees/tests/testConflict.py
class Base(TestCase): class Base(TestCase):
db = None storage = None
def setUp(self): def setUp(self):
pass pass
def tearDown(self): def tearDown(self):
if self.db is not None: transaction.abort()
self.db.close() if self.storage is not None:
self.storage.close()
self.storage.cleanup() self.storage.cleanup()
def openDB(self): def openDB(self):
...@@ -39,15 +43,15 @@ class Base(TestCase): ...@@ -39,15 +43,15 @@ class Base(TestCase):
class TestLength2(Base): class TestLength2(Base):
def testConflict(self): def testConflict(self):
# this test fails on the HEAD (MVCC?) # Set up database connections to provoke conflict.
self.openDB() self.openDB()
length = Length2(0) length = Length2(0)
r1 = self.db.open().root() r1 = self.db.open().root()
r1['ob'] = length r1['ob'] = length
get_transaction().commit() transaction.commit()
r2 = self.db.open().root() r2 = self.db.open(synch=False).root()
copy = r2['ob'] copy = r2['ob']
# The following ensures that copy is loaded. # The following ensures that copy is loaded.
self.assertEqual(copy(),0) self.assertEqual(copy(),0)
...@@ -55,40 +59,42 @@ class TestLength2(Base): ...@@ -55,40 +59,42 @@ class TestLength2(Base):
# First transaction. # First transaction.
length.increment(10) length.increment(10)
length.decrement(1) length.decrement(1)
get_transaction().commit() transaction.commit()
# Second transaction. # Second transaction.
length = copy length = copy
length.increment(20) length.increment(20)
length.decrement(2) length.decrement(2)
get_transaction().commit() transaction.commit()
self.assertEqual(length(), 10+20-max(1,2)) self.assertEqual(length(), 10+20-max(1,2))
class TestIncreaser(Base): class TestIncreaser(Base):
def testConflict(self): def testConflict(self):
# Set up database connections to provoke conflict.
self.openDB() self.openDB()
increaser = Increaser(0) increaser = Increaser(0)
r1 = self.db.open().root() r1 = self.db.open().root()
r1['ob'] = increaser r1['ob'] = increaser
get_transaction().commit() transaction.commit()
r2 = self.db.open().root() r2 = self.db.open(synch=False).root()
copy = r2['ob'] copy = r2['ob']
# The following ensures that copy is loaded. # The following ensures that copy is loaded.
self.assertEqual(copy(),0) self.assertEqual(copy(),0)
# First transaction. # First transaction.
increaser.set(10) increaser.set(10)
get_transaction().commit() transaction.commit()
# Second transaction. # Second transaction.
increaser = copy increaser = copy
increaser.set(20) increaser.set(20)
get_transaction().commit() transaction.commit()
self.assertEqual(increaser(), 20) self.assertEqual(increaser(), 20)
......
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