[Zodb-checkins] SVN: ZODB/trunk/src/ZEO/tests/ Moved a test into a docstring to make a future import work.

Jim Fulton jim at zope.com
Wed Sep 8 15:20:33 EDT 2010


Log message for revision 116235:
  Moved a test into a docstring to make a future import work.
  

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

-=-
Deleted: ZODB/trunk/src/ZEO/tests/invalidations_while_connecting.test
===================================================================
--- ZODB/trunk/src/ZEO/tests/invalidations_while_connecting.test	2010-09-08 18:00:33 UTC (rev 116234)
+++ ZODB/trunk/src/ZEO/tests/invalidations_while_connecting.test	2010-09-08 19:20:33 UTC (rev 116235)
@@ -1,102 +0,0 @@
-Invalidations while connecting
-==============================
-
-As soon as a client registers with a server, it will recieve
-invalidations from the server.  The client must be careful to queue
-these invalidations until it is ready to deal with them.  At the time
-of the writing of this test, clients weren't careful enough about
-queing invalidations.  This led to cache corruption in the form of
-both low-level file corruption as well as out-of-date records marked
-as current.
-
-This tests tries to provoke this bug by:
-
-- starting a server
-
-    >>> import ZEO.tests.testZEO, ZEO.tests.forker
-    >>> addr = 'localhost', ZEO.tests.testZEO.get_port()
-    >>> zconf = ZEO.tests.forker.ZEOConfig(addr)
-    >>> sconf = '<filestorage 1>\npath Data.fs\n</filestorage>\n'
-    >>> _, adminaddr, pid, conf_path = ZEO.tests.forker.start_zeo_server(
-    ...     sconf, zconf, addr[1])
-
-- opening a client to the server that writes some objects, filling
-  it's cache at the same time,
-
-    >>> import ZEO.ClientStorage, ZODB.tests.MinPO, transaction
-    >>> db = ZODB.DB(ZEO.ClientStorage.ClientStorage(addr, client='x'))
-    >>> conn = db.open()
-    >>> nobs = 1000
-    >>> for i in range(nobs):
-    ...     conn.root()[i] = ZODB.tests.MinPO.MinPO(0)
-    >>> transaction.commit()
-
-- disconnecting the first client (closing it with a persistent cache),
-
-    >>> db.close()
-
-- starting a second client that writes objects more or less
-  constantly,
-
-    >>> import random, threading, time
-    >>> 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:
-    ...         i = random.randint(0, nobs-1)
-    ...         if stop:
-    ...             return
-    ...         with lock:
-    ...             conn2.root()[i].value += 1
-    ...             tm.commit()
-    ...         time.sleep(0)
-    >>> thread = threading.Thread(target=run)
-    >>> thread.setDaemon(True)
-    >>> thread.start()
-
-- restarting the first client, and
-- testing for cache validity.
-
-    >>> import zope.testing.loggingsupport, logging
-    >>> handler = zope.testing.loggingsupport.InstalledHandler(
-    ...    'ZEO', level=logging.ERROR)
-
-    >>> 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
-    ...        db.close()
-    ... finally:
-    ...     stop = True
-    ...     thread.join(10)
-
-    >>> thread.isAlive()
-    False
-
-    >>> for record in handler.records:
-    ...     print record.name, record.levelname
-    ...     print handler.format(record)
-
-    >>> handler.uninstall()
-
-    >>> db.close()
-    >>> db2.close()
-    >>> ZEO.tests.forker.shutdown_zeo_server(adminaddr)
-

Modified: ZODB/trunk/src/ZEO/tests/testConnection.py
===================================================================
--- ZODB/trunk/src/ZEO/tests/testConnection.py	2010-09-08 18:00:33 UTC (rev 116234)
+++ ZODB/trunk/src/ZEO/tests/testConnection.py	2010-09-08 19:20:33 UTC (rev 116235)
@@ -16,6 +16,9 @@
 The actual tests are in ConnectionTests.py; this file provides the
 platform-dependent scaffolding.
 """
+
+from __future__ import with_statement
+
 from ZEO.tests import ConnectionTests, InvalidationTests
 from zope.testing import setupstack
 import doctest
@@ -128,18 +131,117 @@
                 MonitorTests,
                 ]
 
+def invalidations_while_connecting():
+    r"""
+As soon as a client registers with a server, it will recieve
+invalidations from the server.  The client must be careful to queue
+these invalidations until it is ready to deal with them.  At the time
+of the writing of this test, clients weren't careful enough about
+queing invalidations.  This led to cache corruption in the form of
+both low-level file corruption as well as out-of-date records marked
+as current.
+
+This tests tries to provoke this bug by:
+
+- starting a server
+
+    >>> import ZEO.tests.testZEO, ZEO.tests.forker
+    >>> addr = 'localhost', ZEO.tests.testZEO.get_port()
+    >>> zconf = ZEO.tests.forker.ZEOConfig(addr)
+    >>> sconf = '<filestorage 1>\npath Data.fs\n</filestorage>\n'
+    >>> _, adminaddr, pid, conf_path = ZEO.tests.forker.start_zeo_server(
+    ...     sconf, zconf, addr[1])
+
+- opening a client to the server that writes some objects, filling
+  it's cache at the same time,
+
+    >>> import ZEO.ClientStorage, ZODB.tests.MinPO, transaction
+    >>> db = ZODB.DB(ZEO.ClientStorage.ClientStorage(addr, client='x'))
+    >>> conn = db.open()
+    >>> nobs = 1000
+    >>> for i in range(nobs):
+    ...     conn.root()[i] = ZODB.tests.MinPO.MinPO(0)
+    >>> transaction.commit()
+
+- disconnecting the first client (closing it with a persistent cache),
+
+    >>> db.close()
+
+- starting a second client that writes objects more or less
+  constantly,
+
+    >>> import random, threading, time
+    >>> 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:
+    ...         i = random.randint(0, nobs-1)
+    ...         if stop:
+    ...             return
+    ...         with lock:
+    ...             conn2.root()[i].value += 1
+    ...             tm.commit()
+    ...         time.sleep(0)
+    >>> thread = threading.Thread(target=run)
+    >>> thread.setDaemon(True)
+    >>> thread.start()
+
+- restarting the first client, and
+- testing for cache validity.
+
+    >>> import zope.testing.loggingsupport, logging
+    >>> handler = zope.testing.loggingsupport.InstalledHandler(
+    ...    'ZEO', level=logging.ERROR)
+
+    >>> 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
+    ...        db.close()
+    ... finally:
+    ...     stop = True
+    ...     thread.join(10)
+
+    >>> thread.isAlive()
+    False
+
+    >>> for record in handler.records:
+    ...     print record.name, record.levelname
+    ...     print handler.format(record)
+
+    >>> handler.uninstall()
+
+    >>> db.close()
+    >>> db2.close()
+    >>> ZEO.tests.forker.shutdown_zeo_server(adminaddr)
+
+
+    """ # '
+
 def test_suite():
     suite = unittest.TestSuite()
     for klass in test_classes:
         sub = unittest.makeSuite(klass, 'check')
         suite.addTest(sub)
-    suite.addTest(doctest.DocFileSuite(
-        'invalidations_while_connecting.test',
+    suite.addTest(doctest.DocTestSuite(
         setUp=ZEO.tests.forker.setUp, tearDown=setupstack.tearDown,
         ))
     suite.layer = ZODB.tests.util.MininalTestLayer('ZEO Connection Tests')
     return suite
-
-
-if __name__ == "__main__":
-    unittest.main(defaultTest='test_suite')



More information about the Zodb-checkins mailing list