]> 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>
Sun, 19 Oct 2025 01:20:17 +0000 (03:20 +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 d70e7ade36b1350929400959d1205d6e31f6147a..6d1726a43e708cfc0bdff2c2a72d5b534c288cf2 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 beaa7f65fbf3b44fadf3b5062f6aba22b327ef8b..c61cb0ffbf355fb38c6eada4c9c394e86f729247 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 c462a19d5822cf671dc582763be24776e31dd75c..ac0ab05f861526c9f9e4de39475fb22c825834b1 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 a66982b2329c7b50ca50cc2acb9a49a706e3f947..0a7fbc7c405a88a0d3a51a3782b3d25e37415527 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()