[Zodb-checkins] CVS: ZODB3/ZEO/tests - InvalidationTests.py:1.6.2.1
Jeremy Hylton
cvs-admin at zope.org
Wed Nov 19 16:09:20 EST 2003
Update of /cvs-repository/ZODB3/ZEO/tests
In directory cvs.zope.org:/tmp/cvs-serv18966
Modified Files:
Tag: ZODB3-mvcc-2-branch
InvalidationTests.py
Log Message:
Make tests fail right away when one thread has an uncaught exception.
=== ZODB3/ZEO/tests/InvalidationTests.py 1.6 => 1.6.2.1 ===
--- ZODB3/ZEO/tests/InvalidationTests.py:1.6 Thu Oct 2 14:17:21 2003
+++ ZODB3/ZEO/tests/InvalidationTests.py Wed Nov 19 16:09:17 2003
@@ -39,7 +39,23 @@
# thought they added (i.e., the keys for which get_transaction().commit()
# did not raise any exception).
-class StressThread(TestThread):
+class FailableThread(TestThread):
+
+ # mixin class
+ # subclass must provide
+ # - self.stop attribute (an event)
+ # - self._testrun() method
+
+ def testrun(self):
+ try:
+ self._testrun()
+ except:
+ # Report the failure here to all the other threads, so
+ # that they stop quickly.
+ self.stop.set()
+ raise
+
+class StressThread(FailableThread):
# Append integers startnum, startnum + step, startnum + 2*step, ...
# to 'tree' until Event stop is set. If sleep is given, sleep
@@ -57,7 +73,7 @@
self.added_keys = []
self.commitdict = commitdict
- def testrun(self):
+ def _testrun(self):
cn = self.db.open()
while not self.stop.isSet():
try:
@@ -87,7 +103,7 @@
key += self.step
cn.close()
-class LargeUpdatesThread(TestThread):
+class LargeUpdatesThread(FailableThread):
# A thread that performs a lot of updates. It attempts to modify
# more than 25 objects so that it can test code that runs vote
@@ -106,6 +122,15 @@
self.commitdict = commitdict
def testrun(self):
+ try:
+ self._testrun()
+ except:
+ # Report the failure here to all the other threads, so
+ # that they stop quickly.
+ self.stop.set()
+ raise
+
+ def _testrun(self):
cn = self.db.open()
while not self.stop.isSet():
try:
@@ -162,7 +187,7 @@
self.added_keys = keys_added.keys()
cn.close()
-class VersionStressThread(TestThread):
+class VersionStressThread(FailableThread):
def __init__(self, testcase, db, stop, threadnum, commitdict, startnum,
step=2, sleep=None):
@@ -177,6 +202,15 @@
self.commitdict = commitdict
def testrun(self):
+ try:
+ self._testrun()
+ except:
+ # Report the failure here to all the other threads, so
+ # that they stop quickly.
+ self.stop.set()
+ raise
+
+ def _testrun(self):
commit = 0
key = self.startnum
while not self.stop.isSet():
@@ -302,7 +336,10 @@
delay = self.MINTIME
start = time.time()
while time.time() - start <= self.MAXTIME:
- time.sleep(delay)
+ stop.wait(delay)
+ if stop.isSet():
+ # Some thread failed. Stop right now.
+ break
delay = 2.0
if len(commitdict) >= len(threads):
break
More information about the Zodb-checkins
mailing list