[Zope-Checkins] CVS: ZODB3/ZODB/tests - StorageTestBase.py:1.22 RecoveryStorage.py:1.6
Jeremy Hylton
jeremy@zope.com
Fri, 6 Dec 2002 18:04:37 -0500
Update of /cvs-repository/ZODB3/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv17662/ZODB/tests
Modified Files:
StorageTestBase.py RecoveryStorage.py
Log Message:
Fix subtle bug in restore().
The _txn_find() must not stop at the pack boundary when it is called
by restore(). It was originally written for _txn_undo() which isn't
supposed to undo to a transaction across a pack. But it should be
legal to restore() a transaction with a reference to a data record in
a transaction that was packed.
Fix by adding stop_at_pack flag to _txn_find() and add tests of this
behavior for FileStorage.
=== ZODB3/ZODB/tests/StorageTestBase.py 1.21 => 1.22 ===
--- ZODB3/ZODB/tests/StorageTestBase.py:1.21 Thu Dec 5 19:00:53 2002
+++ ZODB3/ZODB/tests/StorageTestBase.py Fri Dec 6 18:04:36 2002
@@ -196,7 +196,7 @@
# The following methods depend on optional storage features.
- def _undo(self, tid, oid):
+ def _undo(self, tid, oid=None):
# Undo a tid that affects a single object (oid).
# XXX This is very specialized
t = Transaction()
@@ -205,8 +205,9 @@
oids = self._storage.transactionalUndo(tid, t)
self._storage.tpc_vote(t)
self._storage.tpc_finish(t)
- self.assertEqual(len(oids), 1)
- self.assertEqual(oids[0], oid)
+ if oid is not None:
+ self.assertEqual(len(oids), 1)
+ self.assertEqual(oids[0], oid)
return self._storage.lastTransaction()
def _commitVersion(self, src, dst):
=== ZODB3/ZODB/tests/RecoveryStorage.py 1.5 => 1.6 ===
--- ZODB3/ZODB/tests/RecoveryStorage.py:1.5 Fri Dec 6 16:17:43 2002
+++ ZODB3/ZODB/tests/RecoveryStorage.py Fri Dec 6 18:04:36 2002
@@ -16,8 +16,11 @@
from ZODB.Transaction import Transaction
from ZODB.tests.IteratorStorage import IteratorDeepCompare
from ZODB.tests.StorageTestBase import MinPO, zodb_unpickle, removefs
+from ZODB import DB
+from ZODB.referencesf import referencesf
from ZODB.FileStorage import FileStorage
+import time
class RecoveryStorage(IteratorDeepCompare):
# Requires a setUp() that creates a self._dst destination storage
@@ -126,3 +129,27 @@
self._dst = FileStorage('Dest.fs')
self._dst.copyTransactionsFrom(self._storage)
self.compare(self._storage, self._dst)
+
+ def checkRestoreAcrossPack(self):
+ db = DB(self._storage)
+ c = db.open()
+ r = c.root()
+ obj1 = r["obj1"] = MinPO(1)
+ get_transaction().commit()
+ obj1 = r["obj2"] = MinPO(1)
+ get_transaction().commit()
+
+ self._dst.copyTransactionsFrom(self._storage)
+ self._dst.pack(time.time(), referencesf)
+
+ self._undo(self._storage.undoInfo()[0]['id'])
+
+ # copy the final transaction manually. even though there
+ # was a pack, the restore() ought to succeed.
+ final = list(self._storage.iterator())[-1]
+ self._dst.tpc_begin(final, final.tid, final.status)
+ for r in final:
+ self._dst.restore(r.oid, r.serial, r.data, r.version, r.data_txn,
+ final)
+ self._dst.tpc_vote(final)
+ self._dst.tpc_finish(final)