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

Tim Peters tim.one at comcast.net
Sat Aug 23 19:40:23 EDT 2003


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

Modified Files:
      Tag: ZODB3-3_1-branch
	InvalidationTests.py 
Log Message:
InvalidationTests._check_threads():  When this failed, it didn't give any
useful information.  Backported the ZODB4 version, which, upon failure,
displays the whole damaged tree and spells out what's wrong with it.


=== ZODB3/ZEO/tests/InvalidationTests.py 1.1.4.7 => 1.1.4.8 ===
--- ZODB3/ZEO/tests/InvalidationTests.py:1.1.4.7	Fri Aug 22 16:45:28 2003
+++ ZODB3/ZEO/tests/InvalidationTests.py	Sat Aug 23 18:40:22 2003
@@ -120,7 +120,7 @@
             # The test picks 50 keys spread across many buckets.  The
             # three threads start with different offsets to minimize
             # conflict errors.
-            
+
             nkeys = len(tkeys)
             if nkeys < 50:
                 tkeys = range(self.threadnum, 3000)
@@ -252,15 +252,26 @@
     def _check_threads(self, tree, *threads):
         # Make sure the thread's view of the world is consistent with
         # the actual database state.
-        all_keys = []
+        expected_keys = []
+        errormsgs = []
+        err = errormsgs.append
         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()))
+            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:
+            err("expected keys != actual keys")
+            for k in expected_keys:
+                if k not in actual_keys:
+                    err("key %s expected but not in tree" % k)
+            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, *threads):
         # Run the threads
@@ -384,7 +395,7 @@
         for i in range(0, 3000, 2):
             tree[i] = 0
         get_transaction().commit()
-        
+
         # Run three threads that update the BTree.
         # Two of the threads share a single storage so that it
         # is possible for both threads to read the same object
@@ -406,7 +417,7 @@
                 self.assert_(tree[k] != 0)
                 if tree[k] != t.threadnum:
                     self.assert_(k in L[tree[k]].added_keys)
-                    
+
 
         cn.close()
         db1.close()




More information about the Zope-Checkins mailing list