[Zodb-checkins] CVS: ZODB3/ZODB/tests - PackableStorage.py:1.14
Barry Warsaw
barry@wooz.org
Tue, 5 Nov 2002 16:54:32 -0500
Update of /cvs-repository/ZODB3/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv16258
Modified Files:
PackableStorage.py
Log Message:
checkPackUnlinkFromRoot(): Add another test that might illustrate some
interesting root reachability properties.
=== ZODB3/ZODB/tests/PackableStorage.py 1.13 => 1.14 ===
--- ZODB3/ZODB/tests/PackableStorage.py:1.13 Wed Aug 14 18:07:09 2002
+++ ZODB3/ZODB/tests/PackableStorage.py Tue Nov 5 16:54:31 2002
@@ -13,6 +13,8 @@
from StringIO import StringIO
import time
+from ZODB import DB
+from Persistence import Persistent
from ZODB.referencesf import referencesf
@@ -42,6 +44,9 @@
return self._oid
+class C(Persistent):
+ pass
+
# Here's where all the magic occurs. Sadly, the pickle module is a bit
# underdocumented, but here's what happens: by setting the persistent_id
# attribute to getpersid() on the pickler, that function gets called for every
@@ -159,8 +164,10 @@
eq(pobj.value, 3)
# Now pack all transactions; need to sleep a second to make
# sure that the pack time is greater than the last commit time.
- time.sleep(1)
- self._storage.pack(time.time(), referencesf)
+ now = packtime = time.time()
+ while packtime <= now:
+ packtime = time.time()
+ self._storage.pack(packtime, referencesf)
# All revisions of the object should be gone, since there is no
# reference from the root object to this object.
raises(KeyError, self._storage.loadSerial, oid, revid1)
@@ -210,8 +217,10 @@
eq(pobj.value, 3)
# Now pack just revisions 1 and 2. The object's current revision
# should stay alive because it's pointed to by the root.
- time.sleep(1)
- self._storage.pack(time.time(), referencesf)
+ now = packtime = time.time()
+ while packtime <= now:
+ packtime = time.time()
+ self._storage.pack(packtime, referencesf)
# Make sure the revisions are gone, but that object zero and revision
# 3 are still there and correct
data, revid = self._storage.load(ZERO, '')
@@ -287,8 +296,10 @@
# Now pack just revisions 1 and 2 of object1. Object1's current
# revision should stay alive because it's pointed to by the root, as
# should Object2's current revision.
- time.sleep(1)
- self._storage.pack(time.time(), referencesf)
+ now = packtime = time.time()
+ while packtime <= now:
+ packtime = time.time()
+ self._storage.pack(packtime, referencesf)
# Make sure the revisions are gone, but that object zero, object2, and
# revision 3 of object1 are still there and correct.
data, revid = self._storage.load(ZERO, '')
@@ -312,3 +323,43 @@
pobj = pickle.loads(data)
eq(pobj.getoid(), oid2)
eq(pobj.value, 11)
+
+ def checkPackUnlinkedFromRoot(self):
+ eq = self.assertEqual
+ db = DB(self._storage)
+ conn = db.open()
+ root = conn.root()
+
+ txn = get_transaction()
+ txn.note('root')
+ txn.commit()
+
+ now = packtime = time.time()
+ while packtime <= now:
+ packtime = time.time()
+
+ obj = C()
+ obj.value = 7
+
+ root['obj'] = obj
+ txn = get_transaction()
+ txn.note('root -> o1')
+ txn.commit()
+
+ del root['obj']
+ txn = get_transaction()
+ txn.note('root -x-> o1')
+ txn.commit()
+
+ self._storage.pack(packtime, referencesf)
+
+ log = self._storage.undoLog()
+ tid = log[0]['id']
+ db.undo(tid)
+ txn = get_transaction()
+ txn.note('undo root -x-> o1')
+ txn.commit()
+
+ conn.sync()
+
+ eq(root['obj'].value, 7)