From: Daniele Varrazzo Date: Sat, 6 Mar 2021 01:21:30 +0000 (+0100) Subject: retry flaky max lifetime test X-Git-Tag: 3.0.dev0~87^2~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0203be5a18496efb9ba0b42e306f57f89d0d38a1;p=thirdparty%2Fpsycopg.git retry flaky max lifetime test --- diff --git a/tests/pool/test_pool.py b/tests/pool/test_pool.py index 7cfc9435d..b043b86c1 100644 --- a/tests/pool/test_pool.py +++ b/tests/pool/test_pool.py @@ -645,16 +645,18 @@ def test_jitter(): @pytest.mark.slow -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) +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) - assert pids[0] == pids[1] != pids[2] == pids[3] != pids[4], pids + assert pids[0] == pids[1] != pids[2] == pids[3] != pids[4], pids def delay_connection(monkeypatch, sec): diff --git a/tests/pool/test_pool_async.py b/tests/pool/test_pool_async.py index 60c91c126..b0c59db7f 100644 --- a/tests/pool/test_pool_async.py +++ b/tests/pool/test_pool_async.py @@ -679,16 +679,20 @@ def test_jitter(): @pytest.mark.slow -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) +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) - assert pids[0] == pids[1] != pids[2] == pids[3] != pids[4], pids + assert pids[0] == pids[1] != pids[2] == pids[3] != pids[4], pids def delay_connection(monkeypatch, sec):