Commit cc707ab6 authored by Jim Fulton's avatar Jim Fulton

Fixed spurious scary intermittent test failure.

parent 8f5a656d
......@@ -144,24 +144,25 @@ class StressThread(FailableThread):
self.commitdict = commitdict
def _testrun(self):
cn = self.db.open()
tm = transaction.TransactionManager()
cn = self.db.open(transaction_manager=tm)
while not self.stop.isSet():
try:
tree = cn.root()["tree"]
break
except (ConflictError, KeyError):
transaction.abort()
tm.abort()
key = self.startnum
while not self.stop.isSet():
try:
tree[key] = self.threadnum
transaction.get().note("add key %s" % key)
transaction.commit()
tm.get().note("add key %s" % key)
tm.commit()
self.commitdict[self] = 1
if self.sleep:
time.sleep(self.sleep)
except (ReadConflictError, ConflictError), msg:
transaction.abort()
tm.abort()
else:
self.added_keys.append(key)
key += self.step
......@@ -338,16 +339,23 @@ class InvalidationTests:
def _check_threads(self, tree, *threads):
# Make sure the thread's view of the world is consistent with
# the actual database state.
expected_keys = []
errormsgs = []
err = errormsgs.append
for t in threads:
if not t.added_keys:
err("thread %d didn't add any keys" % t.threadnum)
expected_keys.extend(t.added_keys)
expected_keys.sort()
actual_keys = list(tree.keys())
if expected_keys != actual_keys:
for i in range(100):
tree._p_jar.sync()
actual_keys = list(tree.keys())
if expected_keys == actual_keys:
break
time.sleep(.1)
else:
errormsgs = []
err = errormsgs.append
err("expected keys != actual keys")
for k in expected_keys:
if k not in actual_keys:
......@@ -355,8 +363,7 @@ class InvalidationTests:
for k in actual_keys:
if k not in expected_keys:
err("key %s in tree but not expected" % k)
if errormsgs:
display(tree)
self.fail('\n'.join(errormsgs))
def go(self, stop, commitdict, *threads):
......@@ -488,10 +495,9 @@ class InvalidationTests:
self.go(stop, cd, t1, t2, t3)
while db1.lastTransaction() != db2.lastTransaction():
db1._storage.sync()
db2._storage.sync()
time.sleep(.1)
time.sleep(.1)
cn = db1.open()
tree = cn.root()["tree"]
self._check_tree(cn, tree)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment