Skip to content

Commit

Permalink
- elaborate test for the memory leak fix show that things are updated
Browse files Browse the repository at this point in the history
  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
  • Loading branch information
freddrake committed Aug 21, 2008
1 parent 45c2f9f commit 6b4c4ed
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------

Expand Down
11 changes: 8 additions & 3 deletions src/zope/app/testing/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def __init__(self, config_file=None, database_names=None):
BaseDatabaseFactory(name, self._base_storages)
for name in database_names
)[0][0]
self.dbstack = []
self.app = Debugger(self.db, config_file)

self.connection = None
Expand Down Expand Up @@ -234,15 +235,16 @@ def _set_base_storage(self, value):

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
Expand All @@ -256,10 +258,13 @@ def tearDown(self):
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
Expand Down
30 changes: 26 additions & 4 deletions src/zope/app/testing/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,16 +414,38 @@ def doctest_FunctionalTestSetup_clears_global_utilities():
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()
>>> setup.tearDown()
>>> 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:
>>> len(getAllUtilitiesRegisteredFor(IDatabase))
0
>>> setup.tearDown()
>>> list(getAllUtilitiesRegisteredFor(IDatabase)) == [base]
True
Clean up:
Tearing down the fixture causes the base database registration to be
removed:
>>> setup.tearDownCompletely()
>>> list(getAllUtilitiesRegisteredFor(IDatabase))
[]
"""


Expand Down

0 comments on commit 6b4c4ed

Please sign in to comment.