Before it would have created a broken pool, blocking forever on getconn.
(:ticket:`#151`).
+psycopg_pool 3.0.3 (unreleased)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- Throw `!ValueError` if the pool `!min_size` is set to 0 (instead of
+ hanging).
+
+
Current release
---------------
def _check_size(
self, min_size: int, max_size: Optional[int]
) -> Tuple[int, int]:
+ if min_size <= 0:
+ raise ValueError("min_size must be greater than 0")
+
if max_size is None:
max_size = min_size
if max_size < min_size:
assert p.min_size == 2
assert p.max_size == 4
+
+@pytest.mark.parametrize("min_size, max_size", [(0, 0), (-1, None), (4, 2)])
+def test_bad_size(dsn, min_size, max_size):
with pytest.raises(ValueError):
- pool.ConnectionPool(dsn, min_size=4, max_size=2)
+ pool.ConnectionPool(min_size=min_size, max_size=max_size)
def test_connection_class(dsn):
assert size == [2, 1, 3, 4, 3, 2, 2]
+@pytest.mark.parametrize("min_size, max_size", [(0, 0), (-1, None), (4, 2)])
+def test_bad_resize(dsn, min_size, max_size):
+ with pool.ConnectionPool() as p:
+ with pytest.raises(ValueError):
+ p.resize(min_size=min_size, max_size=max_size)
+
+
def test_jitter():
rnds = [pool.ConnectionPool._jitter(30, -0.1, +0.2) for i in range(100)]
assert 27 <= min(rnds) <= 28
assert p.min_size == 2
assert p.max_size == 4
+
+@pytest.mark.parametrize("min_size, max_size", [(0, 0), (-1, None), (4, 2)])
+async def test_bad_size(dsn, min_size, max_size):
with pytest.raises(ValueError):
- pool.AsyncConnectionPool(dsn, min_size=4, max_size=2)
+ pool.AsyncConnectionPool(min_size=min_size, max_size=max_size)
async def test_connection_class(dsn):
assert size == [2, 1, 3, 4, 3, 2, 2]
+@pytest.mark.parametrize("min_size, max_size", [(0, 0), (-1, None), (4, 2)])
+async def test_bad_resize(dsn, min_size, max_size):
+ async with pool.AsyncConnectionPool() as p:
+ with pytest.raises(ValueError):
+ await p.resize(min_size=min_size, max_size=max_size)
+
+
def test_jitter():
rnds = [
pool.AsyncConnectionPool._jitter(30, -0.1, +0.2) for i in range(100)