Skip to content

Commit 494d951

Browse files
committed
Fix for CONPY-255:
If a connection pool can't return a connection (all connections in use) a PoolError will be raised instead of returning None object.
1 parent 6afeaa5 commit 494d951

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

mariadb/connectionpool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def get_connection(self):
221221
del self._connections_free[i]
222222
return conn
223223

224-
return None
224+
raise mariadb.PoolError("No connection available")
225225

226226
def _close_connection(self, connection):
227227
"""

testing/test/integration/test_pooling.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,15 @@ def test_connection_pool_conf(self):
207207

208208
def test_connection_pool_maxconn(self):
209209
default_conf = conf()
210-
pool = mariadb.ConnectionPool(pool_name="test_max_size",
210+
pool = mariadb.ConnectionPool(pool_name="test_max_size", pool_size=6,
211211
**default_conf)
212212
connections = []
213-
for i in range(1, 6):
213+
for i in range(0, 6):
214214
connections.append(pool.get_connection())
215-
try:
216-
pool.get_connection()
217-
except mariadb.PoolError:
218-
pass
215+
self.assertRaises(mariadb.PoolError, lambda:pool.get_connection())
216+
219217
for c in connections:
220218
c.close()
221-
pool.get_connection()
222219
pool.close()
223220

224221
def test_connection_pool_add(self):

0 commit comments

Comments
 (0)