diff --git a/CHANGES.txt b/CHANGES.txt index b086f28a..8d76df9a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -17,6 +17,7 @@ To be included in 1.0.0 (unreleased) * Support PyMySQL up to version 1.0.2 #643 * Bump minimal PyMySQL version to 1.0.0 #713 * Align % formatting in Cursor.executemany() with Cursor.execute(), literal % now need to be doubled in Cursor.executemany() #714 +* Fixed unlimited Pool size not working, this is now working as documented by passing maxsize=0 to create_pool #119 0.0.22 (2021-11-14) diff --git a/aiomysql/pool.py b/aiomysql/pool.py index 3eacb47d..47f14bb5 100644 --- a/aiomysql/pool.py +++ b/aiomysql/pool.py @@ -36,13 +36,13 @@ class Pool(asyncio.AbstractServer): def __init__(self, minsize, maxsize, echo, pool_recycle, loop, **kwargs): if minsize < 0: raise ValueError("minsize should be zero or greater") - if maxsize < minsize: + if maxsize < minsize and maxsize != 0: raise ValueError("maxsize should be not less than minsize") self._minsize = minsize self._loop = loop self._conn_kwargs = kwargs self._acquiring = 0 - self._free = collections.deque(maxlen=maxsize) + self._free = collections.deque(maxlen=maxsize or None) self._cond = asyncio.Condition() self._used = set() self._terminated = set() @@ -182,7 +182,7 @@ async def _fill_free_pool(self, override_min): if self._free: return - if override_min and self.size < self.maxsize: + if override_min and (not self.maxsize or self.size < self.maxsize): self._acquiring += 1 try: conn = await connect(echo=self._echo, loop=self._loop, diff --git a/tests/test_pool.py b/tests/test_pool.py index fac5c2d2..c87d0849 100644 --- a/tests/test_pool.py +++ b/tests/test_pool.py @@ -538,3 +538,21 @@ async def test_pool_drops_connection_with_exception(pool_creator, loop): async with pool.get() as conn: cur = await conn.cursor() await cur.execute('SELECT 1;') + + +@pytest.mark.run_loop +async def test_pool_maxsize_unlimited(pool_creator, loop): + pool = await pool_creator(minsize=0, maxsize=0) + + async with pool.acquire() as conn: + cur = await conn.cursor() + await cur.execute('SELECT 1;') + + +@pytest.mark.run_loop +async def test_pool_maxsize_unlimited_minsize_1(pool_creator, loop): + pool = await pool_creator(minsize=1, maxsize=0) + + async with pool.acquire() as conn: + cur = await conn.cursor() + await cur.execute('SELECT 1;')