summaryrefslogtreecommitdiff
path: root/test/engine
diff options
context:
space:
mode:
authorTaem Park <wwwee98@gmail.com>2018-08-21 10:54:45 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2018-09-18 21:58:02 -0400
commitb64a3dd87a4204ce6d4f2793a7a3f7fbf72eb01f (patch)
tree8de8e0e60e63228beae54378eae0e990b4a9ce3c /test/engine
parent67a2cd92295bef55d914a5c560b4cead5d456837 (diff)
downloadsqlalchemy-b64a3dd87a4204ce6d4f2793a7a3f7fbf72eb01f.tar.gz
Add LIFO for connection pooling
Added new "lifo" mode to :class:`.QueuePool`, typically enabled by setting the flag :paramref:`.create_engine.pool_use_lifo` to True. "lifo" mode means the same connection just checked in will be the first to be checked out again, allowing excess connections to be cleaned up from the server side during periods of the pool being only partially utilized. Pull request courtesy Taem Park. Change-Id: Idb5e299c5082b3e6b547bd03022acf65fdc34f35 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/467
Diffstat (limited to 'test/engine')
-rw-r--r--test/engine/test_pool.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/test/engine/test_pool.py b/test/engine/test_pool.py
index 61737d253..99e50f582 100644
--- a/test/engine/test_pool.py
+++ b/test/engine/test_pool.py
@@ -1983,6 +1983,83 @@ class QueuePoolTest(PoolTestBase):
rec.checkin
)
+ def test_lifo(self):
+ c1, c2, c3 = Mock(), Mock(), Mock()
+ connections = [c1, c2, c3]
+
+ def creator():
+ return connections.pop(0)
+
+ p = pool.QueuePool(creator, use_lifo=True)
+
+ pc1 = p.connect()
+ pc2 = p.connect()
+ pc3 = p.connect()
+
+ pc1.close()
+ pc2.close()
+ pc3.close()
+
+ for i in range(5):
+ pc1 = p.connect()
+ is_(pc1.connection, c3)
+ pc1.close()
+
+ pc1 = p.connect()
+ is_(pc1.connection, c3)
+
+ pc2 = p.connect()
+ is_(pc2.connection, c2)
+ pc2.close()
+
+ pc3 = p.connect()
+ is_(pc3.connection, c2)
+
+ pc2 = p.connect()
+ is_(pc2.connection, c1)
+
+ pc2.close()
+ pc3.close()
+ pc1.close()
+
+ def test_fifo(self):
+ c1, c2, c3 = Mock(), Mock(), Mock()
+ connections = [c1, c2, c3]
+
+ def creator():
+ return connections.pop(0)
+
+ p = pool.QueuePool(creator)
+
+ pc1 = p.connect()
+ pc2 = p.connect()
+ pc3 = p.connect()
+
+ pc1.close()
+ pc2.close()
+ pc3.close()
+
+ pc1 = p.connect()
+ is_(pc1.connection, c1)
+ pc1.close()
+
+ pc1 = p.connect()
+ is_(pc1.connection, c2)
+
+ pc2 = p.connect()
+ is_(pc2.connection, c3)
+ pc2.close()
+
+ pc3 = p.connect()
+ is_(pc3.connection, c1)
+
+ pc2 = p.connect()
+ is_(pc2.connection, c3)
+
+ pc2.close()
+ pc3.close()
+ pc1.close()
+
class ResetOnReturnTest(PoolTestBase):
def _fixture(self, **kw):