[Zodb-checkins] SVN: ZODB/branches/3.8/src/ZEO/tests/InvalidationTests.py Fixed spurious scary intermittent test failure.

Jim Fulton jim at zope.com
Thu Jul 24 17:27:56 EDT 2008


Log message for revision 88800:
  Fixed spurious scary intermittent test failure.
  

Changed:
  U   ZODB/branches/3.8/src/ZEO/tests/InvalidationTests.py

-=-
Modified: ZODB/branches/3.8/src/ZEO/tests/InvalidationTests.py
===================================================================
--- ZODB/branches/3.8/src/ZEO/tests/InvalidationTests.py	2008-07-24 18:42:55 UTC (rev 88799)
+++ ZODB/branches/3.8/src/ZEO/tests/InvalidationTests.py	2008-07-24 21:27:53 UTC (rev 88800)
@@ -144,24 +144,25 @@
         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 @@
     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 @@
             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 @@
         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)



More information about the Zodb-checkins mailing list