[Checkins] SVN: zope.app.testing/trunk/ merge fix for the memory leak fix from the 3.4 branch
Fred L. Drake, Jr.
fdrake at gmail.com
Thu Aug 21 17:10:22 EDT 2008
Log message for revision 90098:
merge fix for the memory leak fix from the 3.4 branch
Changed:
U zope.app.testing/trunk/CHANGES.txt
U zope.app.testing/trunk/src/zope/app/testing/functional.py
U zope.app.testing/trunk/src/zope/app/testing/tests.py
-=-
Modified: zope.app.testing/trunk/CHANGES.txt
===================================================================
--- zope.app.testing/trunk/CHANGES.txt 2008-08-21 20:58:57 UTC (rev 90097)
+++ zope.app.testing/trunk/CHANGES.txt 2008-08-21 21:10:21 UTC (rev 90098)
@@ -6,8 +6,12 @@
------------------
- Added missing dependency information in setup.py.
+
- Added missing import.
+- Repair memory leak fix released in 3.4.3 to be more sane in the presence of
+ generations.
+
3.5.1 (2008-08-20)
------------------
Modified: zope.app.testing/trunk/src/zope/app/testing/functional.py
===================================================================
--- zope.app.testing/trunk/src/zope/app/testing/functional.py 2008-08-21 20:58:57 UTC (rev 90097)
+++ zope.app.testing/trunk/src/zope/app/testing/functional.py 2008-08-21 21:10:21 UTC (rev 90098)
@@ -203,6 +203,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
@@ -249,33 +250,44 @@
base_storage = property(_get_base_storage, _set_base_storage)
def _close_databases(self):
+ # This is really careful to unregister the databases before attempting
+ # to close anything. Zope Corporation has a couple of large
+ # multi-database applications that get bitten if we're not careful
+ # like this, but we've not been able to write a concise test case yet.
base = component.getGlobalSiteManager()
- for name, db in self.db.databases.iteritems():
+ dbs = []
+ for name, db in list(component.getUtilitiesFor(IDatabase)):
+ ok = base.unregisterUtility(db, IDatabase, name)
+ assert ok
+ dbs.append(db)
+ if self.connection:
+ self.connection.close()
+ self.connection = None
+ for db in dbs:
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.connection))
+ self.connection = None
self.db = self.app.db = multi_database(
DerivedDatabaseFactory(name, self._base_storages)
for name in self._database_names
)[0][0]
- self.connection = None
def tearDown(self):
"""Cleans up after a functional test case."""
abort()
- if self.connection:
- self.connection.close()
- self.connection = None
self._close_databases()
+ self.db, self.connection = 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._product_config = None
Modified: zope.app.testing/trunk/src/zope/app/testing/tests.py
===================================================================
--- zope.app.testing/trunk/src/zope/app/testing/tests.py 2008-08-21 20:58:57 UTC (rev 90097)
+++ zope.app.testing/trunk/src/zope/app/testing/tests.py 2008-08-21 21:10:21 UTC (rev 90098)
@@ -413,16 +413,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