[Zodb-checkins] SVN: ZODB/trunk/src/ZEO/tests/invalidations_while_connecting.test Make mutating thread daemonic and stop it if there is an error in the

Jim Fulton jim at zope.com
Wed Sep 8 13:23:16 EDT 2010


Log message for revision 116232:
  Make mutating thread daemonic and stop it if there is an error in the
  test thread.
  
  Use with to simplify locking code.
  

Changed:
  U   ZODB/trunk/src/ZEO/tests/invalidations_while_connecting.test

-=-
Modified: ZODB/trunk/src/ZEO/tests/invalidations_while_connecting.test
===================================================================
--- ZODB/trunk/src/ZEO/tests/invalidations_while_connecting.test	2010-09-08 17:21:35 UTC (rev 116231)
+++ ZODB/trunk/src/ZEO/tests/invalidations_while_connecting.test	2010-09-08 17:23:15 UTC (rev 116232)
@@ -50,46 +50,43 @@
     ...         i = random.randint(0, nobs-1)
     ...         if stop:
     ...             return
-    ...         lock.acquire()
-    ...         try:
+    ...         with lock:
     ...             conn2.root()[i].value += 1
     ...             tm.commit()
-    ...         finally:
-    ...             lock.release()
-    ...             time.sleep(0)
+    ...         time.sleep(0)
     >>> thread = threading.Thread(target=run)
+    >>> thread.setDaemon(True)
     >>> thread.start()
 
-- restarting the first client, and 
+- restarting the first client, and
 - testing for cache validity.
 
     >>> import zope.testing.loggingsupport, logging
     >>> handler = zope.testing.loggingsupport.InstalledHandler(
     ...    'ZEO', level=logging.ERROR)
 
-    >>> for c in range(10):
-    ...    time.sleep(.1)
-    ...    db = ZODB.DB(ZEO.ClientStorage.ClientStorage(addr, client='x'))
-    ...    _ = lock.acquire()
-    ...    try:
-    ...      wait_until("connected and we've caught up",
-    ...                 lambda :
-    ...                    db.storage.is_connected()
-    ...                    and db.storage.lastTransaction()
-    ...                        == db.storage._server.lastTransaction()
-    ...                  )
+    >>> try:
+    ...     for c in range(10):
+    ...        time.sleep(.1)
+    ...        db = ZODB.DB(ZEO.ClientStorage.ClientStorage(addr, client='x'))
+    ...        with lock:
+    ...            @wait_until("connected and we've caught up", timeout=199)
+    ...            def _():
+    ...                return (db.storage.is_connected()
+    ...                        and db.storage.lastTransaction()
+    ...                            == db.storage._server.lastTransaction()
+    ...                        )
     ...
-    ...      conn = db.open()
-    ...      for i in range(1000):
-    ...        if conn.root()[i].value != conn2.root()[i].value:
-    ...            print 'bad', c, i, conn.root()[i].value,
-    ...            print  conn2.root()[i].value
-    ...    finally:
-    ...      _ = lock.release()
-    ...    db.close()
+    ...            conn = db.open()
+    ...            for i in range(1000):
+    ...                if conn.root()[i].value != conn2.root()[i].value:
+    ...                    print 'bad', c, i, conn.root()[i].value,
+    ...                    print  conn2.root()[i].value
+    ...        db.close()
+    ... finally:
+    ...     stop = True
+    ...     thread.join(10)
 
-    >>> stop = True
-    >>> thread.join(10)
     >>> thread.isAlive()
     False
 



More information about the Zodb-checkins mailing list