Commit 2a8691c1 authored by Tim Peters's avatar Tim Peters

An obsolete version of this file got added from the 3.1 branch. Bringing

it up to date.
parent 2742c58f
......@@ -27,8 +27,27 @@ from ZODB.POSException \
import ReadConflictError, ConflictError, VersionLockError
import zLOG
# The tests here let several threads have a go at one or more database
# instances simultaneously. Each thread appends a disjoint (from the
# other threads) sequence of increasing integers to an OOBTree, one at
# at time (per thread). This provokes lots of conflicts, and BTrees
# work hard at conflict resolution too. An OOBTree is used because
# that flavor has the smallest maximum bucket size, and so splits buckets
# more often than other BTree flavors.
#
# When these tests were first written, they provoked an amazing number
# of obscure timing-related bugs in cache consistency logic, revealed
# by failure of the BTree to pass internal consistency checks at the end,
# and/or by failure of the BTree to contain all the keys the threads
# thought they added (i.e., the keys for which get_transaction().commit()
# did not raise any exception).
class StressThread(TestThread):
# Append integers startnum, startnum + step, startnum + 2*step, ...
# to 'tree' until Event stop is set. If sleep is given, sleep
# that long after each append. At the end, instance var .added_keys
# is a list of the ints the thread believes it added successfully.
def __init__(self, testcase, db, stop, threadnum, startnum,
step=2, sleep=None):
TestThread.__init__(self, testcase)
......@@ -154,10 +173,10 @@ class VersionStressThread(TestThread):
class InvalidationTests(CommonSetupTearDown):
level = 2
DELAY = 15
DELAY = 15 # number of seconds the main thread lets the workers run
def _check_tree(self, cn, tree):
# Make sure the BTree is sane and that all the updates persisted
# Make sure the BTree is sane and that all the updates persisted.
retries = 3
while retries:
retries -= 1
......@@ -177,11 +196,15 @@ class InvalidationTests(CommonSetupTearDown):
def _check_threads(self, tree, *threads):
# Make sure the thread's view of the world is consistent with
# the actual database state.
all_keys = []
for t in threads:
# If the test didn't add any keys, it didn't do what we expected.
self.assert_(t.added_keys)
for key in t.added_keys:
self.assert_(tree.has_key(key), key)
all_keys.extend(t.added_keys)
all_keys.sort()
self.assertEqual(all_keys, list(tree.keys()))
def go(self, stop, *threads):
# Run the threads
......
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