[Zodb-checkins] CVS: ZODB3/ZODB/tests - testFileStorage.py:1.19.8.2 StorageTestBase.py:1.17.8.2
Jeremy Hylton
jeremy@zope.com
Fri, 6 Dec 2002 18:00:02 -0500
Update of /cvs-repository/ZODB3/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv16902/ZODB/tests
Modified Files:
Tag: ZODB3-3_1-branch
testFileStorage.py StorageTestBase.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/testFileStorage.py 1.19.8.1 => 1.19.8.2 ===
--- ZODB3/ZODB/tests/testFileStorage.py:1.19.8.1 Fri Nov 15 12:18:55 2002
+++ ZODB3/ZODB/tests/testFileStorage.py Fri Dec 6 17:59:30 2002
@@ -1,8 +1,11 @@
from __future__ import nested_scopes
-import ZODB.FileStorage
import sys, os, unittest
+import time
import errno
+
+import ZODB.FileStorage
+from ZODB.referencesf import referencesf
from ZODB.Transaction import Transaction
from ZODB import POSException
@@ -13,6 +16,8 @@
IteratorStorage, Corruption, RevisionStorage, PersistentStorage, \
MTStorage, ReadOnlyStorage
from ZODB.tests.StorageTestBase import MinPO, zodb_unpickle
+from PersistentMapping import PersistentMapping
+from ZODB import DB
class FileStorageTests(
StorageTestBase.StorageTestBase,
@@ -174,6 +179,30 @@
self._dst = ZODB.FileStorage.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)
def test_suite():
=== ZODB3/ZODB/tests/StorageTestBase.py 1.17.8.1 => 1.17.8.2 ===
--- ZODB3/ZODB/tests/StorageTestBase.py:1.17.8.1 Fri Nov 15 12:18:55 2002
+++ ZODB3/ZODB/tests/StorageTestBase.py Fri Dec 6 17:59:30 2002
@@ -184,7 +184,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()
@@ -193,8 +193,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):