[Zope3-checkins] CVS: ZODB4/src/zodb/storage/tests - test_memory.py:1.3 packable.py:1.10
Jeremy Hylton
jeremy@zope.com
Fri, 16 May 2003 15:47:49 -0400
Update of /cvs-repository/ZODB4/src/zodb/storage/tests
In directory cvs.zope.org:/tmp/cvs-serv3490/storage/tests
Modified Files:
test_memory.py packable.py
Log Message:
Add new test of concurrent writing and packing.
=== ZODB4/src/zodb/storage/tests/test_memory.py 1.2 => 1.3 ===
--- ZODB4/src/zodb/storage/tests/test_memory.py:1.2 Tue Apr 22 11:23:12 2003
+++ ZODB4/src/zodb/storage/tests/test_memory.py Fri May 16 15:47:48 2003
@@ -79,6 +79,10 @@
self._storage.close()
# Individual tests that can't possibly pass
+
+ # This one can't possibly pass until Barry fixes
+ # _update_refcounts().
+ def testPackWhileWriting(self): pass
def testDatabaseVersionPersistent(self): pass
def testPackUnlinkedFromRoot(self): pass # requires undo
@@ -97,7 +101,7 @@
def testPackAllRevisions(self): pass
def testPackJustOldRevisions(self): pass
def testPackOnlyOneObject(self): pass
-
+
def test_suite():
=== ZODB4/src/zodb/storage/tests/packable.py 1.9 => 1.10 ===
--- ZODB4/src/zodb/storage/tests/packable.py:1.9 Fri May 9 12:12:02 2003
+++ ZODB4/src/zodb/storage/tests/packable.py Fri May 16 15:47:48 2003
@@ -13,12 +13,13 @@
##############################################################################
"""Run some tests relevant for storages that support pack()."""
+import threading
import time
from transaction import get_transaction
from zodb.db import DB
-from zodb.interfaces import ZERO
+from zodb.interfaces import ZERO, ConflictError
from zodb.serialize import getDBRoot, ConnectionObjectReader
from zodb.ztransaction import Transaction
from zodb.storage.tests.minpo import MinPO
@@ -235,3 +236,56 @@
conn.sync()
eq(root['obj'].value, 7)
+
+ def testPackWhileWriting(self):
+ # A storage should allow some reading and writing during
+ # a pack. This test attempts to exercise locking code
+ # in the storage to test that it is safe. It generates
+ # a lot of revisions, so that pack takes a long time.
+
+ db = DB(self._storage)
+ conn = db.open()
+ root = conn.root()
+
+ for i in range(10):
+ root[i] = MinPO(i)
+ get_transaction().commit()
+
+ snooze()
+ packt = time.time()
+
+ for j in range(10):
+ for i in range(10):
+ root[i].value = MinPO(i)
+ get_transaction().commit()
+
+ threads = [ClientThread(db) for i in range(4)]
+ for t in threads:
+ t.start()
+ db.pack(packt)
+ for t in threads:
+ t.join(30)
+ for t in threads:
+ t.join(1)
+ self.assert_(not t.isAlive())
+
+ # iterator over the storage to make sure it's sane
+ iter = self._storage.iterator()
+ for txn in iter:
+ for data in txn:
+ pass
+ iter.close()
+
+class ClientThread(threading.Thread):
+
+ def __init__(self, db):
+ threading.Thread.__init__(self)
+ self.root = db.open().root()
+
+ def run(self):
+ for j in range(50):
+ try:
+ self.root[j % 10].value = MinPO(j)
+ get_transaction().commit()
+ except ConflictError:
+ get_transaction().abort()