From 8b16509ac897506f8de1267c785c49e9aef124e5 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sun, 4 May 2025 22:57:10 +0200 Subject: [PATCH] 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. --- tests/pool/test_pool_common.py | 1 + tests/pool/test_pool_common_async.py | 1 + tests/pool/test_pool_null.py | 2 ++ tests/pool/test_pool_null_async.py | 2 ++ 4 files changed, 6 insertions(+) diff --git a/tests/pool/test_pool_common.py b/tests/pool/test_pool_common.py index d70e7ade3..6d1726a43 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 beaa7f65f..c61cb0ffb 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 c462a19d5..ac0ab05f8 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 a66982b23..0a7fbc7c4 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() -- 2.47.3