summaryrefslogtreecommitdiff
path: root/test/engine/test_pool.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-04-08 00:10:54 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2015-04-08 00:10:54 -0400
commit44a9820b4e02f65b3884fa2c016efce9663e4910 (patch)
tree2cb1712d382edabff895c73fc42648e6a4996298 /test/engine/test_pool.py
parent72329433e78e57c8589e4797df523bb598190b64 (diff)
downloadsqlalchemy-44a9820b4e02f65b3884fa2c016efce9663e4910.tar.gz
- add some teardown for connections that are held open after tests
in some cases, interfering with tests that check pool._refs
Diffstat (limited to 'test/engine/test_pool.py')
-rw-r--r--test/engine/test_pool.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/test/engine/test_pool.py b/test/engine/test_pool.py
index 0c4557d49..44336b15c 100644
--- a/test/engine/test_pool.py
+++ b/test/engine/test_pool.py
@@ -9,6 +9,7 @@ from sqlalchemy.testing.engines import testing_engine
from sqlalchemy.testing import fixtures
import random
from sqlalchemy.testing.mock import Mock, call
+import weakref
join_timeout = 10
@@ -35,11 +36,22 @@ def MockDBAPI():
class PoolTestBase(fixtures.TestBase):
def setup(self):
pool.clear_managers()
+ self._teardown_conns = []
+
+ def teardown(self):
+ for ref in self._teardown_conns:
+ conn = ref()
+ if conn:
+ conn.close()
@classmethod
def teardown_class(cls):
pool.clear_managers()
+ def _with_teardown(self, connection):
+ self._teardown_conns.append(weakref.ref(connection))
+ return connection
+
def _queuepool_fixture(self, **kw):
dbapi, pool = self._queuepool_dbapi_fixture(**kw)
return pool
@@ -960,9 +972,9 @@ class QueuePoolTest(PoolTestBase):
return creator()
p = pool.QueuePool(creator=create, pool_size=2, max_overflow=3)
- c1 = p.connect()
- c2 = p.connect()
- c3 = p.connect()
+ c1 = self._with_teardown(p.connect())
+ c2 = self._with_teardown(p.connect())
+ c3 = self._with_teardown(p.connect())
eq_(p._overflow, 1)
creator = failing_dbapi
assert_raises(Exception, p.connect)
@@ -1293,13 +1305,13 @@ class QueuePoolTest(PoolTestBase):
dbapi.shutdown(False)
- c1 = p.connect()
+ c1 = self._with_teardown(p.connect())
assert p._pool.empty() # poolsize is one, so we're empty OK
- c2 = p.connect()
+ c2 = self._with_teardown(p.connect())
eq_(p._overflow, 1) # and not 2
# this hangs if p._overflow is 2
- c3 = p.connect()
+ c3 = self._with_teardown(p.connect())
def test_error_on_pooled_reconnect_cleanup_invalidate(self):
dbapi, p = self._queuepool_dbapi_fixture(pool_size=1, max_overflow=2)