Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pool maxsize unlimited #426

Merged
merged 8 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions aiomysql/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions tests/test_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;')