Commit e9c7492a authored by Adam Groszer's avatar Adam Groszer Committed by Jim Fulton

Clean DB properties on close (#123)

* clean up references to DBs and Connections in pools
* Implement an explicit clear() method for clearing all the items in the pool.
parent e714f515
......@@ -107,6 +107,10 @@ class AbstractConnectionPool(object):
size = property(getSize, lambda self, v: self.setSize(v))
def clear(self):
pass
class ConnectionPool(AbstractConnectionPool):
def __init__(self, size, timeout=1<<31):
......@@ -230,6 +234,11 @@ class ConnectionPool(AbstractConnectionPool):
self.available[:] = [i for i in self.available
if i[1] not in to_remove]
def clear(self):
while self.pop():
pass
class KeyedConnectionPool(AbstractConnectionPool):
# this pool keeps track of keyed connections all together. It makes
# it possible to make assertions about total numbers of keyed connections.
......@@ -285,6 +294,11 @@ class KeyedConnectionPool(AbstractConnectionPool):
if not pool.all:
del self.pools[key]
def clear(self):
for pool in self.pools.values():
pool.clear()
self.pools.clear()
@property
def test_all(self):
result = set()
......@@ -645,6 +659,11 @@ class DB(object):
self._mvcc_storage.close()
del self.storage
del self._mvcc_storage
# clean up references to other DBs
self.databases = {}
# clean up the connection pool
self.pool.clear()
self.historical_pool.clear()
def getCacheSize(self):
"""Get the configured cache size (objects).
......
......@@ -137,7 +137,7 @@ an exception:
Clean up:
>>> for a_db in dbmap.values():
>>> for a_db in list(dbmap.values()):
... a_db.close()
......
......@@ -397,6 +397,31 @@ def minimally_test_connection_timeout():
"""
def cleanup_on_close():
"""Verify that various references are cleared on close
>>> db = ZODB.DB(None)
>>> conn = db.open()
>>> conn.root.x = 'x'
>>> transaction.commit()
>>> conn.close()
>>> historical_conn = db.open(at=db.lastTransaction())
>>> historical_conn.close()
>>> db.close()
>>> db.databases
{}
>>> db.pool.pop() is None
True
>>> [pool is None for pool in db.historical_pool.pools.values()]
[]
"""
def test_suite():
s = unittest.makeSuite(DBTests)
s.addTest(doctest.DocTestSuite(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment