summaryrefslogtreecommitdiff
path: root/test/engine/test_pool.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-04-03 10:03:17 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-04-03 10:12:57 -0400
commita326869cf9c166afea43b1bd7d7f5dbab27abb75 (patch)
tree657c26947834a98a754be1ec8c2064e36750e4c5 /test/engine/test_pool.py
parentfd2ecb5f87c1c0132263b5a35067c4bb76160fb2 (diff)
downloadsqlalchemy-a326869cf9c166afea43b1bd7d7f5dbab27abb75.tar.gz
Restore use_threadlocal equivalent behavior to SingletonThreadPool
Fixed behavioral regression as a result of deprecating the "use_threadlocal" flag for :class:`.Pool`, where the :class:`.SingletonThreadPool` no longer makes use of this option which causes the "rollback on return" logic to take place when the same :class:`.Engine` is used multiple times in the context of a transaction to connect or implicitly execute, thereby cancelling the transaction. While this is not the recommended way to work with engines and connections, it is nonetheless a confusing behavioral change as when using :class:`.SingletonThreadPool`, the transaction should stay open regardless of what else is done with the same engine in the same thread. The ``use_threadlocal`` flag remains deprecated however the :class:`.SingletonThreadPool` now implements its own version of the same logic. Fixes: #4585 Change-Id: I906293f2d0a5d14ed46cd9e64305a6481505a5a3
Diffstat (limited to 'test/engine/test_pool.py')
-rw-r--r--test/engine/test_pool.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/engine/test_pool.py b/test/engine/test_pool.py
index 3722ce9b9..6cd2e4572 100644
--- a/test/engine/test_pool.py
+++ b/test/engine/test_pool.py
@@ -1818,6 +1818,31 @@ class SingletonThreadPoolTest(PoolTestBase):
still_opened = len([c for c in sr if not c.close.call_count])
eq_(still_opened, 3)
+ def test_no_rollback_from_nested_connections(self):
+ dbapi = MockDBAPI()
+
+ lock = threading.Lock()
+
+ def creator():
+ # the mock iterator isn't threadsafe...
+ with lock:
+ return dbapi.connect()
+
+ p = pool.SingletonThreadPool(creator=creator, pool_size=3)
+
+ c1 = p.connect()
+ mock_conn = c1.connection
+
+ c2 = p.connect()
+ is_(c1, c2)
+
+ c2.close()
+
+ eq_(mock_conn.mock_calls, [])
+ c1.close()
+
+ eq_(mock_conn.mock_calls, [call.rollback()])
+
class AssertionPoolTest(PoolTestBase):
def test_connect_error(self):