From: Daniele Varrazzo Date: Mon, 8 Mar 2021 01:59:05 +0000 (+0100) Subject: Simpler, more approximative, more reliable pool max lifetime test X-Git-Tag: 3.0.dev0~87^2~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=faef422d03ab9070cebaf22eac97776d4a0777ee;p=thirdparty%2Fpsycopg.git Simpler, more approximative, more reliable pool max lifetime test --- diff --git a/tests/pool/test_pool.py b/tests/pool/test_pool.py index 219541754..ea15d5cb3 100644 --- a/tests/pool/test_pool.py +++ b/tests/pool/test_pool.py @@ -686,18 +686,16 @@ def test_jitter(): @pytest.mark.slow -def test_max_lifetime(dsn, retries): - for retry in retries: - with retry: - with pool.ConnectionPool(dsn, minconn=1, max_lifetime=0.2) as p: - sleep(0.1) - pids = [] - for i in range(5): - with p.connection() as conn: - pids.append(conn.pgconn.backend_pid) - sleep(0.2) +def test_max_lifetime(dsn): + with pool.ConnectionPool(dsn, minconn=1, max_lifetime=0.2) as p: + sleep(0.1) + pids = [] + for i in range(5): + with p.connection() as conn: + pids.append(conn.pgconn.backend_pid) + sleep(0.2) - assert pids[0] == pids[1] != pids[2] == pids[3] != pids[4], pids + assert pids[0] == pids[1] != pids[4], pids def test_check(dsn, caplog): diff --git a/tests/pool/test_pool_async.py b/tests/pool/test_pool_async.py index 7c4842cc1..24eb38e67 100644 --- a/tests/pool/test_pool_async.py +++ b/tests/pool/test_pool_async.py @@ -710,20 +710,16 @@ def test_jitter(): @pytest.mark.slow -async def test_max_lifetime(dsn, retries): - async for retry in retries: - with retry: - async with pool.AsyncConnectionPool( - dsn, minconn=1, max_lifetime=0.2 - ) as p: - await asyncio.sleep(0.1) - pids = [] - for i in range(5): - async with p.connection() as conn: - pids.append(conn.pgconn.backend_pid) - await asyncio.sleep(0.2) +async def test_max_lifetime(dsn): + async with pool.AsyncConnectionPool(dsn, minconn=1, max_lifetime=0.2) as p: + await asyncio.sleep(0.1) + pids = [] + for i in range(5): + async with p.connection() as conn: + pids.append(conn.pgconn.backend_pid) + await asyncio.sleep(0.2) - assert pids[0] == pids[1] != pids[2] == pids[3] != pids[4], pids + assert pids[0] == pids[1] != pids[4], pids def delay_connection(monkeypatch, sec):