summaryrefslogtreecommitdiff
path: root/test/engine/test_pool.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-02-19 10:48:32 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2014-02-19 10:48:32 -0500
commitdd32540dabbee0678530fb1b0868d1eb41572dca (patch)
tree52f11b69d3639762d52c83c7482efb8a79f368d0 /test/engine/test_pool.py
parent185938e7b7467a364fc8df5bee2597b4fee91bac (diff)
downloadsqlalchemy-dd32540dabbee0678530fb1b0868d1eb41572dca.tar.gz
- Fixed a critical regression caused by :ticket:`2880` where the newly
concurrent ability to return connections from the pool means that the "first_connect" event is now no longer synchronized either, thus leading to dialect mis-configurations under even minimal concurrency situations.
Diffstat (limited to 'test/engine/test_pool.py')
-rw-r--r--test/engine/test_pool.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/engine/test_pool.py b/test/engine/test_pool.py
index 2e4c2dc48..fc6f3dcea 100644
--- a/test/engine/test_pool.py
+++ b/test/engine/test_pool.py
@@ -525,6 +525,44 @@ class PoolEventsTest(PoolTestBase):
# going
pool.Pool.dispatch._clear()
+class PoolFirstConnectSyncTest(PoolTestBase):
+ # test [ticket:2964]
+
+ def test_sync(self):
+ pool = self._queuepool_fixture(pool_size=3, max_overflow=0)
+
+ evt = Mock()
+
+ @event.listens_for(pool, 'first_connect')
+ def slow_first_connect(dbapi_con, rec):
+ time.sleep(1)
+ evt.first_connect()
+
+ @event.listens_for(pool, 'connect')
+ def on_connect(dbapi_con, rec):
+ evt.connect()
+
+ def checkout():
+ for j in range(2):
+ c1 = pool.connect()
+ time.sleep(.02)
+ c1.close()
+ time.sleep(.02)
+
+ threads = []
+ for i in range(5):
+ th = threading.Thread(target=checkout)
+ th.start()
+ threads.append(th)
+ for th in threads:
+ th.join(join_timeout)
+
+ eq_(evt.mock_calls,
+ [call.first_connect(), call.connect(), call.connect(), call.connect()]
+ )
+
+
+
class DeprecatedPoolListenerTest(PoolTestBase):
@testing.requires.predictable_gc
@testing.uses_deprecated(r".*Use event.listen")