[Zodb-checkins] SVN: ZODB/branches/jim-3.8-connection/src/ZEO/tests/invalidations_while_connecting.test Added a lock to allow the main thread to pause the database-update

Jim Fulton jim at zope.com
Fri Jul 11 09:46:23 EDT 2008


Log message for revision 88255:
  Added a lock to allow the main thread to pause the database-update
  thread while checking consistency accross clients to avoid spurious
  test failures.
  

Changed:
  U   ZODB/branches/jim-3.8-connection/src/ZEO/tests/invalidations_while_connecting.test

-=-
Modified: ZODB/branches/jim-3.8-connection/src/ZEO/tests/invalidations_while_connecting.test
===================================================================
--- ZODB/branches/jim-3.8-connection/src/ZEO/tests/invalidations_while_connecting.test	2008-07-11 13:40:30 UTC (rev 88254)
+++ ZODB/branches/jim-3.8-connection/src/ZEO/tests/invalidations_while_connecting.test	2008-07-11 13:46:22 UTC (rev 88255)
@@ -26,7 +26,8 @@
     >>> import ZEO.ClientStorage, ZODB.tests.MinPO, transaction
     >>> db = ZODB.DB(ZEO.ClientStorage.ClientStorage(addr, client='x'))
     >>> conn = db.open()
-    >>> for i in range(1000):
+    >>> nobs = 1000
+    >>> for i in range(nobs):
     ...     conn.root()[i] = ZODB.tests.MinPO.MinPO(0)
     >>> transaction.commit()
 
@@ -37,18 +38,25 @@
 - starting a second client that writes objects more or less
   constantly,
 
-    >>> import threading
+    >>> import random, threading
     >>> stop = False
     >>> db2 = ZODB.DB(ZEO.ClientStorage.ClientStorage(addr))
     >>> tm = transaction.TransactionManager()
     >>> conn2 = db2.open(transaction_manager=tm)
+    >>> random = random.Random(0)
+    >>> lock = threading.Lock()
     >>> def run():
     ...     while 1:
-    ...         for i in range(500):
-    ...             if stop:
-    ...                 return
+    ...         i = random.randint(0, nobs-1)
+    ...         if stop:
+    ...             return
+    ...         lock.acquire()
+    ...         try:
     ...             conn2.root()[i].value += 1
     ...             tm.commit()
+    ...         finally:
+    ...             lock.release()
+    ...             time.sleep(0)
     >>> thread = threading.Thread(target=run)
     >>> thread.start()
 
@@ -63,12 +71,16 @@
     >>> for c in range(10):
     ...    time.sleep(.1)
     ...    db = ZODB.DB(ZEO.ClientStorage.ClientStorage(addr, client='x'))
-    ...    time.sleep(.1)
-    ...    conn = db.open()
-    ...    for i in range(1000):
+    ...    _ = lock.acquire()
+    ...    try:
+    ...      time.sleep(.1)
+    ...      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()
 
     >>> stop = True



More information about the Zodb-checkins mailing list