[Checkins] SVN: zope.app.testing/branches/3.4/ - elaborate test for the memory leak fix show that things are updated

Fred L. Drake, Jr. fdrake at gmail.com
Thu Aug 21 14:19:38 EDT 2008


Log message for revision 90088:
  - elaborate test for the memory leak fix show that things are updated
    properly at each stage of the test setup management
  - make it stack the setup and cleanup properly so that generations are not
    lost at the wrong time
  

Changed:
  U   zope.app.testing/branches/3.4/CHANGES.txt
  U   zope.app.testing/branches/3.4/src/zope/app/testing/functional.py
  U   zope.app.testing/branches/3.4/src/zope/app/testing/tests.py

-=-
Modified: zope.app.testing/branches/3.4/CHANGES.txt
===================================================================
--- zope.app.testing/branches/3.4/CHANGES.txt	2008-08-21 17:41:11 UTC (rev 90087)
+++ zope.app.testing/branches/3.4/CHANGES.txt	2008-08-21 18:19:38 UTC (rev 90088)
@@ -2,6 +2,12 @@
 CHANGES
 =======
 
+3.4.4 (2008-08-21)
+------------------
+
+- Repair memory leak fix released in 3.4.3 to be more sane in the presence of
+  generations.
+
 3.4.3 (2008-07-25)
 ------------------
 

Modified: zope.app.testing/branches/3.4/src/zope/app/testing/functional.py
===================================================================
--- zope.app.testing/branches/3.4/src/zope/app/testing/functional.py	2008-08-21 17:41:11 UTC (rev 90087)
+++ zope.app.testing/branches/3.4/src/zope/app/testing/functional.py	2008-08-21 18:19:38 UTC (rev 90088)
@@ -192,6 +192,7 @@
                 BaseDatabaseFactory(name, self._base_storages)
                 for name in database_names
                 )[0][0]
+            self.dbstack = []
             self.app = Debugger(self.db, config_file)
 
             self.connection = None
@@ -234,15 +235,16 @@
 
     def _close_databases(self):
         base = component.getGlobalSiteManager()
-        for name, db in self.db.databases.iteritems():
+        for name, db in component.getUtilitiesFor(IDatabase):
+            ok = base.unregisterUtility(db, IDatabase, name)
+            assert ok
             db.close()
-            base.unregisterUtility(db, IDatabase, name)
 
     def setUp(self):
         """Prepares for a functional test case."""
         # Tear down the old demo storages (if any) and create fresh ones
         abort()
-        self._close_databases()
+        self.dbstack.append(self.db)
         self.db = self.app.db = multi_database(
             DerivedDatabaseFactory(name, self._base_storages)
             for name in self._database_names
@@ -256,10 +258,13 @@
             self.connection.close()
             self.connection = None
         self._close_databases()
+        self.db = self.dbstack.pop()
         setSite(None)
 
     def tearDownCompletely(self):
         """Cleans up the setup done by the constructor."""
+        self._close_databases()
+        assert self.dbstack == []
         zope.app.testing.setup.placefulTearDown()
         self._config_file = False
         self._database_names = None

Modified: zope.app.testing/branches/3.4/src/zope/app/testing/tests.py
===================================================================
--- zope.app.testing/branches/3.4/src/zope/app/testing/tests.py	2008-08-21 17:41:11 UTC (rev 90087)
+++ zope.app.testing/branches/3.4/src/zope/app/testing/tests.py	2008-08-21 18:19:38 UTC (rev 90088)
@@ -414,16 +414,38 @@
     See https://bugs.launchpad.net/zope3/+bug/251273
 
         >>> setup = FunctionalTestSetup(ftesting_zcml)
+
+    At this point, there are registrations for the base databases created by
+    the initialization:
+
+        >>> base, = getAllUtilitiesRegisteredFor(IDatabase)
+
+    Setting up for a test causes overriding registrations to be made:
+
         >>> setup.setUp()
+        >>> dbs = list(getAllUtilitiesRegisteredFor(IDatabase))
+        >>> len(dbs)
+        2
+        >>> base in dbs
+        True
+        >>> dbs.remove(base)
+        >>> override, = dbs
+
+    Tearing down the test context causes the overriding database to be
+    removed:
+
         >>> setup.tearDown()
+        >>> list(getAllUtilitiesRegisteredFor(IDatabase)) == [base]
+        True
 
-        >>> len(getAllUtilitiesRegisteredFor(IDatabase))
-        0
+    Tearing down the fixture causes the base database registration to be
+    removed:
 
-    Clean up:
-
         >>> setup.tearDownCompletely()
 
+        >>> list(getAllUtilitiesRegisteredFor(IDatabase))
+        []
+
     """
 
 



More information about the Checkins mailing list