Skip to content

Commit 9f7fcbb

Browse files
committed
Fix for CONPY-250:
With implementation of CONPY-246/247 pool._connections was replaced by _connections_used and _connections_free to the size should be calclulated as len(_connections_used + _connections_free)
1 parent fad6119 commit 9f7fcbb

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

mariadb/connectionpool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def max_size(self):
289289
def connection_count(self):
290290
"Returns the number of connections in connection pool."""
291291

292-
return len(self._connections)
292+
return len(self._connections_free + self._connections_used)
293293

294294
@property
295295
def pool_reset_connection(self):

mariadb/mariadb_cursor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ MrdbCursor_execute_binary(MrdbCursor *self)
10811081

10821082
if ((rc= Mrdb_execute_direct(self, self->parseinfo.statement, self->parseinfo.statement_len)))
10831083
{
1084-
mariadb_throw_exception(self->connection->mysql, NULL, 0, NULL);
1084+
mariadb_throw_exception(self->stmt, NULL, 1, NULL);
10851085
goto error;
10861086
}
10871087

testing/test/integration/test_pooling.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ def test_conpy246(self):
6060
conn.close()
6161
pool.close()
6262

63+
def test_conpy250(self):
64+
default_conf = conf()
65+
pool = mariadb.ConnectionPool(pool_name="CONPY250",
66+
pool_size=16,
67+
pool_reset_connection=False,
68+
pool_validation_interval=0,
69+
**default_conf)
70+
self.assertEqual(pool.connection_count, 16)
71+
pool.close()
72+
6373
def test_conpy247_1(self):
6474
default_conf = conf()
6575
pool = mariadb.ConnectionPool(pool_name="CONPY247_1",
@@ -139,15 +149,13 @@ def test_conpy247_3(self):
139149
pconn = pool.get_connection()
140150
new_ids.append(pconn.connection_id)
141151
self.assertEqual(pconn.connection_id in ids, False)
142-
cursor = pconn.cursor(buffered=False, binary=False)
143-
cursor.callproc("P1")
152+
cursor = pconn.cursor()
153+
cursor.callproc("p1")
154+
cursor.close()
144155
pconn.close()
145156

146-
print("new_ids", new_ids)
147-
148157
for i in range(0, 10):
149158
pconn = pool.get_connection()
150-
print("new_id: ", pconn.connection_id)
151159
self.assertEqual(pconn.connection_id in new_ids, True)
152160
pconn.close()
153161

0 commit comments

Comments
 (0)