]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test(pool): make sure that returned connection have the pool set
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 4 May 2025 20:57:10 +0000 (22:57 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 6 Aug 2025 13:13:12 +0000 (15:13 +0200)
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
tests/pool/test_pool_common_async.py
tests/pool/test_pool_null.py
tests/pool/test_pool_null_async.py

index 3c21c098009e5a3c2cd698588d23871768cad2a9..f4a36196aa431af75cb3b14677069528595dc8e2 100644 (file)
@@ -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()
index 068064d684e9bb5bd012bffc65dd5834bd768df4..07a234fe80ce96eaebab6bc4aff28ed5a14ed6e1 100644 (file)
@@ -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()
index 9d84e4ae725deb73671f60c6901466b05692df72..ace66a641ee4f2d79d160c922aba45f1458489e1 100644 (file)
@@ -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()
index 1d40c6dd55a41670a4b5d5395d6246651d4b3835..9ecbbff278d06d5d8c8a796abb170c37253d4e58 100644 (file)
@@ -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()