]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test(crdb): don't use pg_backend_pid in pool tests
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 8 Jun 2022 01:35:03 +0000 (03:35 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 12 Jul 2022 11:58:34 +0000 (12:58 +0100)
You can express the same test using info.backend_pid, which is supported
from CRDB 22.1.

tests/fix_crdb.py
tests/pool/test_null_pool.py
tests/pool/test_null_pool_async.py
tests/pool/test_pool.py
tests/pool/test_pool_async.py

index 0098f2b8183e8306cc6ae369a6a5ce4790284158..0700395c906e8d23f278182cb89d1cd0bb4920bd 100644 (file)
@@ -112,7 +112,6 @@ _crdb_reasons = {
     "no col query": None,
     "notify": 41522,
     "password_encryption": 42519,
-    "pg_backend_pid": 35897,
     "pg_terminate_backend": 35897,
     "range": 41282,
     "scroll cursor": 77102,
index 385be5519416ee2f4bbab8dacfa6f23bc77d0bde..c0e80603f7f932fa7cf24d11115fff1657ff9e31 100644 (file)
@@ -54,16 +54,14 @@ def test_kwargs(dsn):
             assert conn.autocommit
 
 
-@pytest.mark.crdb_skip("pg_backend_pid")
+@pytest.mark.crdb_skip("backend pid")
 def test_its_no_pool_at_all(dsn):
     with NullConnectionPool(dsn, max_size=2) as p:
         with p.connection() as conn:
-            with conn.execute("select pg_backend_pid()") as cur:
-                (pid1,) = cur.fetchone()  # type: ignore[misc]
+            pid1 = conn.info.backend_pid
 
             with p.connection() as conn2:
-                with conn2.execute("select pg_backend_pid()") as cur:
-                    (pid2,) = cur.fetchone()  # type: ignore[misc]
+                pid2 = conn2.info.backend_pid
 
         with p.connection() as conn:
             assert conn.info.backend_pid not in (pid1, pid2)
@@ -285,14 +283,14 @@ def test_no_queue_timeout(deaf_port):
 
 @pytest.mark.slow
 @pytest.mark.timing
-@pytest.mark.crdb_skip("pg_backend_pid")
+@pytest.mark.crdb_skip("backend pid")
 def test_queue(dsn):
     def worker(n):
         t0 = time()
         with p.connection() as conn:
-            (pid,) = conn.execute(
-                "select pg_backend_pid() from pg_sleep(0.2)"
-            ).fetchone()  # type: ignore[misc]
+            conn.execute("select pg_sleep(0.2)")
+            pid = conn.info.backend_pid
+
         t1 = time()
         results.append((n, t1 - t0, pid))
 
@@ -352,15 +350,14 @@ def test_queue_size(dsn):
 
 @pytest.mark.slow
 @pytest.mark.timing
-@pytest.mark.crdb_skip("pg_backend_pid")
+@pytest.mark.crdb_skip("backend pid")
 def test_queue_timeout(dsn):
     def worker(n):
         t0 = time()
         try:
             with p.connection() as conn:
-                (pid,) = conn.execute(  # type: ignore[misc]
-                    "select pg_backend_pid() from pg_sleep(0.2)"
-                ).fetchone()
+                conn.execute("select pg_sleep(0.2)")
+                pid = conn.info.backend_pid
         except PoolTimeout as e:
             t1 = time()
             errors.append((n, t1 - t0, e))
@@ -413,16 +410,15 @@ def test_dead_client(dsn):
 
 @pytest.mark.slow
 @pytest.mark.timing
-@pytest.mark.crdb_skip("pg_backend_pid")
+@pytest.mark.crdb_skip("backend pid")
 def test_queue_timeout_override(dsn):
     def worker(n):
         t0 = time()
         timeout = 0.25 if n == 3 else None
         try:
             with p.connection(timeout=timeout) as conn:
-                (pid,) = conn.execute(  # type: ignore[misc]
-                    "select pg_backend_pid() from pg_sleep(0.2)"
-                ).fetchone()
+                conn.execute("select pg_sleep(0.2)")
+                pid = conn.info.backend_pid
         except PoolTimeout as e:
             t1 = time()
             errors.append((n, t1 - t0, e))
@@ -446,17 +442,15 @@ def test_queue_timeout_override(dsn):
         assert 0.1 < e[1] < 0.15
 
 
-@pytest.mark.crdb_skip("pg_backend_pid")
+@pytest.mark.crdb_skip("backend pid")
 def test_broken_reconnect(dsn):
     with NullConnectionPool(dsn, max_size=1) as p:
         with p.connection() as conn:
-            with conn.execute("select pg_backend_pid()") as cur:
-                (pid1,) = cur.fetchone()  # type: ignore[misc]
+            pid1 = conn.info.backend_pid
             conn.close()
 
         with p.connection() as conn2:
-            with conn2.execute("select pg_backend_pid()") as cur:
-                (pid2,) = cur.fetchone()  # type: ignore[misc]
+            pid2 = conn2.info.backend_pid
 
     assert pid1 != pid2
 
index 71e0475f5953eceefc26d57e6626eb663765b57a..23a1a5221fb70f0b9fac547fd564d75d6c346d21 100644 (file)
@@ -56,16 +56,14 @@ async def test_kwargs(dsn):
             assert conn.autocommit
 
 
-@pytest.mark.crdb_skip("pg_backend_pid")
+@pytest.mark.crdb_skip("backend pid")
 async def test_its_no_pool_at_all(dsn):
     async with AsyncNullConnectionPool(dsn, max_size=2) as p:
         async with p.connection() as conn:
-            cur = await conn.execute("select pg_backend_pid()")
-            (pid1,) = await cur.fetchone()  # type: ignore[misc]
+            pid1 = conn.info.backend_pid
 
             async with p.connection() as conn2:
-                cur = await conn2.execute("select pg_backend_pid()")
-                (pid2,) = await cur.fetchone()  # type: ignore[misc]
+                pid2 = conn2.info.backend_pid
 
         async with p.connection() as conn:
             assert conn.info.backend_pid not in (pid1, pid2)
@@ -286,13 +284,13 @@ async def test_no_queue_timeout(deaf_port):
 
 @pytest.mark.slow
 @pytest.mark.timing
-@pytest.mark.crdb_skip("pg_backend_pid")
+@pytest.mark.crdb_skip("backend pid")
 async def test_queue(dsn):
     async def worker(n):
         t0 = time()
         async with p.connection() as conn:
-            cur = await conn.execute("select pg_backend_pid() from pg_sleep(0.2)")
-            (pid,) = await cur.fetchone()  # type: ignore[misc]
+            await conn.execute("select pg_sleep(0.2)")
+            pid = conn.info.backend_pid
         t1 = time()
         results.append((n, t1 - t0, pid))
 
@@ -345,14 +343,14 @@ async def test_queue_size(dsn):
 
 @pytest.mark.slow
 @pytest.mark.timing
-@pytest.mark.crdb_skip("pg_backend_pid")
+@pytest.mark.crdb_skip("backend pid")
 async def test_queue_timeout(dsn):
     async def worker(n):
         t0 = time()
         try:
             async with p.connection() as conn:
-                cur = await conn.execute("select pg_backend_pid() from pg_sleep(0.2)")
-                (pid,) = await cur.fetchone()  # type: ignore[misc]
+                await conn.execute("select pg_sleep(0.2)")
+                pid = conn.info.backend_pid
         except PoolTimeout as e:
             t1 = time()
             errors.append((n, t1 - t0, e))
@@ -399,15 +397,15 @@ async def test_dead_client(dsn):
 
 @pytest.mark.slow
 @pytest.mark.timing
-@pytest.mark.crdb_skip("pg_backend_pid")
+@pytest.mark.crdb_skip("backend pid")
 async def test_queue_timeout_override(dsn):
     async def worker(n):
         t0 = time()
         timeout = 0.25 if n == 3 else None
         try:
             async with p.connection(timeout=timeout) as conn:
-                cur = await conn.execute("select pg_backend_pid() from pg_sleep(0.2)")
-                (pid,) = await cur.fetchone()  # type: ignore[misc]
+                await conn.execute("select pg_sleep(0.2)")
+                pid = conn.info.backend_pid
         except PoolTimeout as e:
             t1 = time()
             errors.append((n, t1 - t0, e))
@@ -428,17 +426,15 @@ async def test_queue_timeout_override(dsn):
         assert 0.1 < e[1] < 0.15
 
 
-@pytest.mark.crdb_skip("pg_backend_pid")
+@pytest.mark.crdb_skip("backend pid")
 async def test_broken_reconnect(dsn):
     async with AsyncNullConnectionPool(dsn, max_size=1) as p:
         async with p.connection() as conn:
-            cur = await conn.execute("select pg_backend_pid()")
-            (pid1,) = await cur.fetchone()  # type: ignore[misc]
+            pid1 = conn.info.backend_pid
             await conn.close()
 
         async with p.connection() as conn2:
-            cur = await conn2.execute("select pg_backend_pid()")
-            (pid2,) = await cur.fetchone()  # type: ignore[misc]
+            pid2 = conn2.info.backend_pid
 
     assert pid1 != pid2
 
index 31d789d57e4e1b4e4f316537dab86154e68d0caa..0089054116e72325883b7de5c6bc98f1437e3b18 100644 (file)
@@ -64,16 +64,14 @@ def test_kwargs(dsn):
             assert conn.autocommit
 
 
-@pytest.mark.crdb_skip("pg_backend_pid")
+@pytest.mark.crdb_skip("backend pid")
 def test_its_really_a_pool(dsn):
     with pool.ConnectionPool(dsn, min_size=2) as p:
         with p.connection() as conn:
-            with conn.execute("select pg_backend_pid()") as cur:
-                (pid1,) = cur.fetchone()  # type: ignore[misc]
+            pid1 = conn.info.backend_pid
 
             with p.connection() as conn2:
-                with conn2.execute("select pg_backend_pid()") as cur:
-                    (pid2,) = cur.fetchone()  # type: ignore[misc]
+                pid2 = conn2.info.backend_pid
 
         with p.connection() as conn:
             assert conn.info.backend_pid in (pid1, pid2)
@@ -292,14 +290,13 @@ def test_reset_broken(dsn, caplog):
 
 @pytest.mark.slow
 @pytest.mark.timing
-@pytest.mark.crdb_skip("pg_backend_pid")
+@pytest.mark.crdb_skip("backend pid")
 def test_queue(dsn):
     def worker(n):
         t0 = time()
         with p.connection() as conn:
-            (pid,) = conn.execute(
-                "select pg_backend_pid() from pg_sleep(0.2)"
-            ).fetchone()  # type: ignore[misc]
+            conn.execute("select pg_sleep(0.2)")
+            pid = conn.info.backend_pid
         t1 = time()
         results.append((n, t1 - t0, pid))
 
@@ -359,15 +356,14 @@ def test_queue_size(dsn):
 
 @pytest.mark.slow
 @pytest.mark.timing
-@pytest.mark.crdb_skip("pg_backend_pid")
+@pytest.mark.crdb_skip("backend pid")
 def test_queue_timeout(dsn):
     def worker(n):
         t0 = time()
         try:
             with p.connection() as conn:
-                (pid,) = conn.execute(  # type: ignore[misc]
-                    "select pg_backend_pid() from pg_sleep(0.2)"
-                ).fetchone()
+                conn.execute("select pg_sleep(0.2)")
+                pid = conn.info.backend_pid
         except pool.PoolTimeout as e:
             t1 = time()
             errors.append((n, t1 - t0, e))
@@ -421,16 +417,15 @@ def test_dead_client(dsn):
 
 @pytest.mark.slow
 @pytest.mark.timing
-@pytest.mark.crdb_skip("pg_backend_pid")
+@pytest.mark.crdb_skip("backend pid")
 def test_queue_timeout_override(dsn):
     def worker(n):
         t0 = time()
         timeout = 0.25 if n == 3 else None
         try:
             with p.connection(timeout=timeout) as conn:
-                (pid,) = conn.execute(  # type: ignore[misc]
-                    "select pg_backend_pid() from pg_sleep(0.2)"
-                ).fetchone()
+                conn.execute("select pg_sleep(0.2)")
+                pid = conn.info.backend_pid
         except pool.PoolTimeout as e:
             t1 = time()
             errors.append((n, t1 - t0, e))
@@ -454,17 +449,15 @@ def test_queue_timeout_override(dsn):
         assert 0.1 < e[1] < 0.15
 
 
-@pytest.mark.crdb_skip("pg_backend_pid")
+@pytest.mark.crdb_skip("backend pid")
 def test_broken_reconnect(dsn):
     with pool.ConnectionPool(dsn, min_size=1) as p:
         with p.connection() as conn:
-            with conn.execute("select pg_backend_pid()") as cur:
-                (pid1,) = cur.fetchone()  # type: ignore[misc]
+            pid1 = conn.info.backend_pid
             conn.close()
 
         with p.connection() as conn2:
-            with conn2.execute("select pg_backend_pid()") as cur:
-                (pid2,) = cur.fetchone()  # type: ignore[misc]
+            pid2 = conn2.info.backend_pid
 
     assert pid1 != pid2
 
index 6ad8a85797b01785e538adb2a2e84ba6d42dc0c4..b67a575e1276b30e412ae9225b3051e4af21f23a 100644 (file)
@@ -57,16 +57,14 @@ async def test_kwargs(dsn):
             assert conn.autocommit
 
 
-@pytest.mark.crdb_skip("pg_backend_pid")
+@pytest.mark.crdb_skip("backend pid")
 async def test_its_really_a_pool(dsn):
     async with pool.AsyncConnectionPool(dsn, min_size=2) as p:
         async with p.connection() as conn:
-            cur = await conn.execute("select pg_backend_pid()")
-            (pid1,) = await cur.fetchone()  # type: ignore[misc]
+            pid1 = conn.info.backend_pid
 
             async with p.connection() as conn2:
-                cur = await conn2.execute("select pg_backend_pid()")
-                (pid2,) = await cur.fetchone()  # type: ignore[misc]
+                pid2 = conn2.info.backend_pid
 
         async with p.connection() as conn:
             assert conn.info.backend_pid in (pid1, pid2)
@@ -289,13 +287,13 @@ async def test_reset_broken(dsn, caplog):
 
 @pytest.mark.slow
 @pytest.mark.timing
-@pytest.mark.crdb_skip("pg_backend_pid")
+@pytest.mark.crdb_skip("backend pid")
 async def test_queue(dsn):
     async def worker(n):
         t0 = time()
         async with p.connection() as conn:
-            cur = await conn.execute("select pg_backend_pid() from pg_sleep(0.2)")
-            (pid,) = await cur.fetchone()  # type: ignore[misc]
+            await conn.execute("select pg_sleep(0.2)")
+            pid = conn.info.backend_pid
         t1 = time()
         results.append((n, t1 - t0, pid))
 
@@ -348,14 +346,14 @@ async def test_queue_size(dsn):
 
 @pytest.mark.slow
 @pytest.mark.timing
-@pytest.mark.crdb_skip("pg_backend_pid")
+@pytest.mark.crdb_skip("backend pid")
 async def test_queue_timeout(dsn):
     async def worker(n):
         t0 = time()
         try:
             async with p.connection() as conn:
-                cur = await conn.execute("select pg_backend_pid() from pg_sleep(0.2)")
-                (pid,) = await cur.fetchone()  # type: ignore[misc]
+                await conn.execute("select pg_sleep(0.2)")
+                pid = conn.info.backend_pid
         except pool.PoolTimeout as e:
             t1 = time()
             errors.append((n, t1 - t0, e))
@@ -403,15 +401,15 @@ async def test_dead_client(dsn):
 
 @pytest.mark.slow
 @pytest.mark.timing
-@pytest.mark.crdb_skip("pg_backend_pid")
+@pytest.mark.crdb_skip("backend pid")
 async def test_queue_timeout_override(dsn):
     async def worker(n):
         t0 = time()
         timeout = 0.25 if n == 3 else None
         try:
             async with p.connection(timeout=timeout) as conn:
-                cur = await conn.execute("select pg_backend_pid() from pg_sleep(0.2)")
-                (pid,) = await cur.fetchone()  # type: ignore[misc]
+                await conn.execute("select pg_sleep(0.2)")
+                pid = conn.info.backend_pid
         except pool.PoolTimeout as e:
             t1 = time()
             errors.append((n, t1 - t0, e))
@@ -432,17 +430,15 @@ async def test_queue_timeout_override(dsn):
         assert 0.1 < e[1] < 0.15
 
 
-@pytest.mark.crdb_skip("pg_backend_pid")
+@pytest.mark.crdb_skip("backend pid")
 async def test_broken_reconnect(dsn):
     async with pool.AsyncConnectionPool(dsn, min_size=1) as p:
         async with p.connection() as conn:
-            cur = await conn.execute("select pg_backend_pid()")
-            (pid1,) = await cur.fetchone()  # type: ignore[misc]
+            pid1 = conn.info.backend_pid
             await conn.close()
 
         async with p.connection() as conn2:
-            cur = await conn2.execute("select pg_backend_pid()")
-            (pid2,) = await cur.fetchone()  # type: ignore[misc]
+            pid2 = conn2.info.backend_pid
 
     assert pid1 != pid2