[Zope-Checkins] CVS: ZODB3/ZEO/tests - InvalidationTests.py:1.1.4.5

Tim Peters tim.one@comcast.net
Thu, 12 Jun 2003 21:17:43 -0400


Update of /cvs-repository/ZODB3/ZEO/tests
In directory cvs.zope.org:/tmp/cvs-serv32727/ZEO/tests

Modified Files:
      Tag: ZODB3-3_1-branch
	InvalidationTests.py 
Log Message:
Added high-level comments.

_check_threads():  Beefed up to test that the set of keys in the tree is
exactly the union of the sets of keys the threads thought they added.  If
a key gets into a tree that a thread didn't believe it added (due to
commit() raising an exception), that would not have been caught before,
but would also be a bug.


=== ZODB3/ZEO/tests/InvalidationTests.py 1.1.4.4 => 1.1.4.5 ===
--- ZODB3/ZEO/tests/InvalidationTests.py:1.1.4.4	Thu Jun 12 20:53:30 2003
+++ ZODB3/ZEO/tests/InvalidationTests.py	Thu Jun 12 21:17:42 2003
@@ -24,8 +24,27 @@
 from ZODB.POSException \
      import ReadConflictError, ConflictError, VersionLockError
 
+# 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)
@@ -142,10 +161,10 @@
 class InvalidationTests:
 
     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
@@ -165,11 +184,15 @@
     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