From: Daniele Varrazzo Date: Sun, 4 May 2025 20:57:10 +0000 (+0200) Subject: test(pool): make sure that returned connection have the pool set X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=59e2cc4390fbca5069bc3292d3938c5c5229cc7f;p=thirdparty%2Fpsycopg.git test(pool): make sure that returned connection have the pool set The flow where we set _pool = None or _pool = self is a bit complex. Make sure we don't mess it up. --- diff --git a/tests/pool/test_pool_common.py b/tests/pool/test_pool_common.py index 3c21c0980..f4a36196a 100644 --- a/tests/pool/test_pool_common.py +++ b/tests/pool/test_pool_common.py @@ -166,6 +166,7 @@ def test_queue(pool_cls, dsn): def worker(n): t0 = time() with p.connection() as conn: + assert conn._pool is p conn.execute("select pg_sleep(0.2)") pid = conn.info.backend_pid t1 = time() diff --git a/tests/pool/test_pool_common_async.py b/tests/pool/test_pool_common_async.py index 068064d68..07a234fe8 100644 --- a/tests/pool/test_pool_common_async.py +++ b/tests/pool/test_pool_common_async.py @@ -176,6 +176,7 @@ async def test_queue(pool_cls, dsn): async def worker(n): t0 = time() async with p.connection() as conn: + assert conn._pool is p await conn.execute("select pg_sleep(0.2)") pid = conn.info.backend_pid t1 = time() diff --git a/tests/pool/test_pool_null.py b/tests/pool/test_pool_null.py index 9d84e4ae7..ace66a641 100644 --- a/tests/pool/test_pool_null.py +++ b/tests/pool/test_pool_null.py @@ -175,6 +175,7 @@ def test_reset(dsn): cur = conn.execute("show timezone") assert cur.fetchone() == ("UTC",) pids.append(conn.info.backend_pid) + assert conn._pool is p with pool.NullConnectionPool(dsn, max_size=1, reset=reset) as p: with p.connection() as conn: @@ -186,6 +187,7 @@ def test_reset(dsn): assert resets == 0 conn.execute("set timezone to '+2:00'") pids.append(conn.info.backend_pid) + assert conn._pool is p gather(t) p.wait() diff --git a/tests/pool/test_pool_null_async.py b/tests/pool/test_pool_null_async.py index 1d40c6dd5..9ecbbff27 100644 --- a/tests/pool/test_pool_null_async.py +++ b/tests/pool/test_pool_null_async.py @@ -174,6 +174,7 @@ async def test_reset(dsn): cur = await conn.execute("show timezone") assert (await cur.fetchone()) == ("UTC",) pids.append(conn.info.backend_pid) + assert conn._pool is p async with pool.AsyncNullConnectionPool(dsn, max_size=1, reset=reset) as p: async with p.connection() as conn: @@ -185,6 +186,7 @@ async def test_reset(dsn): assert resets == 0 await conn.execute("set timezone to '+2:00'") pids.append(conn.info.backend_pid) + assert conn._pool is p await gather(t) await p.wait()