Commit c25e00b1 authored by Shane Hathaway's avatar Shane Hathaway

Windows tests exposed a bug in MVCCMappingStorage: the transaction ID

did not necessarily increase for every transaction.  Fixed and tested.
parent e627eaea
......@@ -280,7 +280,11 @@ class MappingStorage(object):
self._transaction = transaction
self._tdata = {}
if tid is None:
tid = ZODB.utils.newTid(self._ltid)
if self._transactions:
old_tid = self._transactions.maxKey()
else:
old_tid = None
tid = ZODB.utils.newTid(old_tid)
self._tid = tid
# ZODB.interfaces.IStorage
......
......@@ -50,7 +50,10 @@ class MVCCMappingStorage(MappingStorage):
def poll_invalidations(self):
"""Poll the storage for changes by other connections.
"""
new_tid = self._transactions.maxKey()
if self._transactions:
new_tid = self._transactions.maxKey()
else:
new_tid = ''
if self._polled_tid:
if not self._transactions.has_key(self._polled_tid):
......
......@@ -45,16 +45,10 @@ class MVCCTests:
r2 = c2.root()
self.assert_('myobj' not in r2)
old_tid = c1._storage._polled_tid
c1.transaction_manager.commit()
new_tid = c1._storage._polled_tid
self.assertNotEqual(new_tid, old_tid)
self.assertEqual(c2._storage._polled_tid, old_tid)
self.assert_('myobj' not in r2)
c2.sync()
self.assertEqual(new_tid, c2._storage._polled_tid)
self.assert_('myobj' in r2)
self.assert_(r2['myobj'] == 'yes')
finally:
......@@ -153,6 +147,26 @@ class MVCCMappingStorageTests(
pass # we don't support undo yet
checkUndoZombie = checkLoadBeforeUndo
def checkTransactionIdIncreases(self):
import time
from ZODB.utils import newTid
from ZODB.TimeStamp import TimeStamp
t = transaction.Transaction()
self._storage.tpc_begin(t)
self._storage.tpc_vote(t)
self._storage.tpc_finish(t)
# Add a fake transaction
transactions = self._storage._transactions
self.assertEqual(1, len(transactions))
fake_timestamp = 'zzzzzzzy' # the year 5735 ;-)
transactions[fake_timestamp] = transactions.values()[0]
# Verify the next transaction comes after the fake transaction
t = transaction.Transaction()
self._storage.tpc_begin(t)
self.assertEqual(self._storage._tid, 'zzzzzzzz')
def test_suite():
suite = unittest.makeSuite(MVCCMappingStorageTests, 'check')
......
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