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)
This commit is contained in:
Georg Richter
2023-02-08 16:04:20 +01:00
parent fad6119fd0
commit 9f7fcbb356
3 changed files with 15 additions and 7 deletions

View File

@ -289,7 +289,7 @@ class ConnectionPool(object):
def connection_count(self):
"Returns the number of connections in connection pool."""
return len(self._connections)
return len(self._connections_free + self._connections_used)
@property
def pool_reset_connection(self):

View File

@ -1081,7 +1081,7 @@ MrdbCursor_execute_binary(MrdbCursor *self)
if ((rc= Mrdb_execute_direct(self, self->parseinfo.statement, self->parseinfo.statement_len)))
{
mariadb_throw_exception(self->connection->mysql, NULL, 0, NULL);
mariadb_throw_exception(self->stmt, NULL, 1, NULL);
goto error;
}

View File

@ -60,6 +60,16 @@ class TestPooling(unittest.TestCase):
conn.close()
pool.close()
def test_conpy250(self):
default_conf = conf()
pool = mariadb.ConnectionPool(pool_name="CONPY250",
pool_size=16,
pool_reset_connection=False,
pool_validation_interval=0,
**default_conf)
self.assertEqual(pool.connection_count, 16)
pool.close()
def test_conpy247_1(self):
default_conf = conf()
pool = mariadb.ConnectionPool(pool_name="CONPY247_1",
@ -139,15 +149,13 @@ class TestPooling(unittest.TestCase):
pconn = pool.get_connection()
new_ids.append(pconn.connection_id)
self.assertEqual(pconn.connection_id in ids, False)
cursor = pconn.cursor(buffered=False, binary=False)
cursor.callproc("P1")
cursor = pconn.cursor()
cursor.callproc("p1")
cursor.close()
pconn.close()
print("new_ids", new_ids)
for i in range(0, 10):
pconn = pool.get_connection()
print("new_id: ", pconn.connection_id)
self.assertEqual(pconn.connection_id in new_ids, True)
pconn.close()