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): ...@@ -144,24 +144,25 @@ class StressThread(FailableThread):
self.commitdict = commitdict self.commitdict = commitdict
def _testrun(self): def _testrun(self):
cn = self.db.open() tm = transaction.TransactionManager()
cn = self.db.open(transaction_manager=tm)
while not self.stop.isSet(): while not self.stop.isSet():
try: try:
tree = cn.root()["tree"] tree = cn.root()["tree"]
break break
except (ConflictError, KeyError): except (ConflictError, KeyError):
transaction.abort() tm.abort()
key = self.startnum key = self.startnum
while not self.stop.isSet(): while not self.stop.isSet():
try: try:
tree[key] = self.threadnum tree[key] = self.threadnum
transaction.get().note("add key %s" % key) tm.get().note("add key %s" % key)
transaction.commit() tm.commit()
self.commitdict[self] = 1 self.commitdict[self] = 1
if self.sleep: if self.sleep:
time.sleep(self.sleep) time.sleep(self.sleep)
except (ReadConflictError, ConflictError), msg: except (ReadConflictError, ConflictError), msg:
transaction.abort() tm.abort()
else: else:
self.added_keys.append(key) self.added_keys.append(key)
key += self.step key += self.step
...@@ -338,16 +339,23 @@ class InvalidationTests: ...@@ -338,16 +339,23 @@ class InvalidationTests:
def _check_threads(self, tree, *threads): def _check_threads(self, tree, *threads):
# Make sure the thread's view of the world is consistent with # Make sure the thread's view of the world is consistent with
# the actual database state. # the actual database state.
expected_keys = [] expected_keys = []
errormsgs = []
err = errormsgs.append
for t in threads: for t in threads:
if not t.added_keys: if not t.added_keys:
err("thread %d didn't add any keys" % t.threadnum) err("thread %d didn't add any keys" % t.threadnum)
expected_keys.extend(t.added_keys) expected_keys.extend(t.added_keys)
expected_keys.sort() 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") err("expected keys != actual keys")
for k in expected_keys: for k in expected_keys:
if k not in actual_keys: if k not in actual_keys:
...@@ -355,8 +363,7 @@ class InvalidationTests: ...@@ -355,8 +363,7 @@ class InvalidationTests:
for k in actual_keys: for k in actual_keys:
if k not in expected_keys: if k not in expected_keys:
err("key %s in tree but not expected" % k) err("key %s in tree but not expected" % k)
if errormsgs:
display(tree)
self.fail('\n'.join(errormsgs)) self.fail('\n'.join(errormsgs))
def go(self, stop, commitdict, *threads): def go(self, stop, commitdict, *threads):
...@@ -488,10 +495,9 @@ class InvalidationTests: ...@@ -488,10 +495,9 @@ class InvalidationTests:
self.go(stop, cd, t1, t2, t3) self.go(stop, cd, t1, t2, t3)
while db1.lastTransaction() != db2.lastTransaction(): while db1.lastTransaction() != db2.lastTransaction():
db1._storage.sync() time.sleep(.1)
db2._storage.sync()
time.sleep(.1)
cn = db1.open() cn = db1.open()
tree = cn.root()["tree"] tree = cn.root()["tree"]
self._check_tree(cn, 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