From bebf30e34d669a5ede54e512e55ee5186fe015f6 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 13 Jan 2014 03:22:11 -0500 Subject: - continue with [ticket:2907] and further clean up how we set up _reset_agent, so that it's local to the various begin_impl(), rollback_impl(), etc. this allows setting/resetting of the flag to be symmetric. - don't set _reset_agent if it's not None, don't unset it if it isn't our own transaction. - make sure we clean it out in close(). - basically, we're dealing here with pools using "threadlocal" that have a counter, other various mismatches that the tests bring up - test for recover() now has to invalidate() the previous connection, because closing it actually rolls it back (e.g. this test was relying on the broken behavior). --- lib/sqlalchemy/testing/engines.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/testing') diff --git a/lib/sqlalchemy/testing/engines.py b/lib/sqlalchemy/testing/engines.py index d240645a8..a74bffe26 100644 --- a/lib/sqlalchemy/testing/engines.py +++ b/lib/sqlalchemy/testing/engines.py @@ -32,6 +32,9 @@ class ConnectionKiller(object): def checkout(self, dbapi_con, con_record, con_proxy): self.proxy_refs[con_proxy] = True + def invalidate(self, dbapi_con, con_record, exception): + self.conns.discard((dbapi_con, con_record)) + def _safe(self, fn): try: fn() @@ -49,7 +52,7 @@ class ConnectionKiller(object): def close_all(self): for rec in list(self.proxy_refs): - if rec is not None: + if rec is not None and rec.is_valid: self._safe(rec._close) def _after_test_ctx(self): @@ -226,6 +229,7 @@ def testing_engine(url=None, options=None): 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 -- cgit v1.2.1