summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/testing')
-rw-r--r--lib/sqlalchemy/testing/assertions.py46
-rw-r--r--lib/sqlalchemy/testing/engines.py12
2 files changed, 8 insertions, 50 deletions
diff --git a/lib/sqlalchemy/testing/assertions.py b/lib/sqlalchemy/testing/assertions.py
index a465bedd4..c74259bdf 100644
--- a/lib/sqlalchemy/testing/assertions.py
+++ b/lib/sqlalchemy/testing/assertions.py
@@ -13,13 +13,12 @@ import warnings
from . import assertsql
from . import config
+from . import engines
from . import mock
-from . import util as testutil
from .exclusions import db_spec
from .util import fail
from .. import exc as sa_exc
from .. import orm
-from .. import pool
from .. import schema
from .. import types as sqltypes
from .. import util
@@ -183,49 +182,8 @@ def global_cleanup_assertions():
_assert_no_stray_pool_connections()
-_STRAY_CONNECTION_FAILURES = 0
-
-
def _assert_no_stray_pool_connections():
- global _STRAY_CONNECTION_FAILURES
-
- # lazy gc on cPython means "do nothing." pool connections
- # shouldn't be in cycles, should go away.
- testutil.lazy_gc()
-
- # however, once in awhile, on an EC2 machine usually,
- # there's a ref in there. usually just one.
- if pool._refs:
-
- # OK, let's be somewhat forgiving.
- _STRAY_CONNECTION_FAILURES += 1
-
- print(
- "Encountered a stray connection in test cleanup: %s"
- % str(pool._refs)
- )
- # then do a real GC sweep. We shouldn't even be here
- # so a single sweep should really be doing it, otherwise
- # there's probably a real unreachable cycle somewhere.
- testutil.gc_collect()
-
- # if we've already had two of these occurrences, or
- # after a hard gc sweep we still have pool._refs?!
- # now we have to raise.
- if pool._refs:
- err = str(pool._refs)
-
- # but clean out the pool refs collection directly,
- # reset the counter,
- # so the error doesn't at least keep happening.
- pool._refs.clear()
- _STRAY_CONNECTION_FAILURES = 0
- warnings.warn(
- "Stray connection refused to leave " "after gc.collect(): %s" % err
- )
- elif _STRAY_CONNECTION_FAILURES > 10:
- assert False, "Encountered more than 10 stray connections"
- _STRAY_CONNECTION_FAILURES = 0
+ engines.testing_reaper.assert_all_closed()
def eq_regex(a, b, msg=None):
diff --git a/lib/sqlalchemy/testing/engines.py b/lib/sqlalchemy/testing/engines.py
index ff4f89606..4f413915a 100644
--- a/lib/sqlalchemy/testing/engines.py
+++ b/lib/sqlalchemy/testing/engines.py
@@ -12,7 +12,6 @@ import warnings
import weakref
from . import config
-from . import uses_deprecated
from .util import decorator
from .. import event
from .. import pool
@@ -24,7 +23,13 @@ class ConnectionKiller(object):
self.testing_engines = weakref.WeakKeyDictionary()
self.conns = set()
+ def add_pool(self, pool):
+ event.listen(pool, "connect", self.connect)
+ event.listen(pool, "checkout", self.checkout)
+ event.listen(pool, "invalidate", self.invalidate)
+
def add_engine(self, engine):
+ self.add_pool(engine.pool)
self.testing_engines[engine] = True
def connect(self, dbapi_conn, con_record):
@@ -75,7 +80,6 @@ class ConnectionKiller(object):
else:
self._stop_test_ctx_aggressive()
- @uses_deprecated()
def _stop_test_ctx_minimal(self):
self.close_all()
@@ -85,7 +89,6 @@ class ConnectionKiller(object):
if rec is not config.db:
rec.dispose()
- @uses_deprecated()
def _stop_test_ctx_aggressive(self):
self.close_all()
for conn, rec in list(self.conns):
@@ -265,9 +268,6 @@ def testing_engine(url=None, options=None):
engine.pool._timeout = 0
engine.pool._max_overflow = 0
if use_reaper:
- event.listen(engine.pool, "connect", testing_reaper.connect)
- event.listen(engine.pool, "checkout", testing_reaper.checkout)
- event.listen(engine.pool, "invalidate", testing_reaper.invalidate)
testing_reaper.add_engine(engine)
return engine