From 266d71e5970ad9cef294931a52ec116d20081889 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Wed, 8 Jun 2022 03:35:03 +0200 Subject: [PATCH] test(crdb): don't use pg_backend_pid in pool tests You can express the same test using info.backend_pid, which is supported from CRDB 22.1. --- tests/fix_crdb.py | 1 - tests/pool/test_null_pool.py | 38 +++++++++++++----------------- tests/pool/test_null_pool_async.py | 34 ++++++++++++-------------- tests/pool/test_pool.py | 37 ++++++++++++----------------- tests/pool/test_pool_async.py | 34 ++++++++++++-------------- 5 files changed, 61 insertions(+), 83 deletions(-) diff --git a/tests/fix_crdb.py b/tests/fix_crdb.py index 0098f2b81..0700395c9 100644 --- a/tests/fix_crdb.py +++ b/tests/fix_crdb.py @@ -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, diff --git a/tests/pool/test_null_pool.py b/tests/pool/test_null_pool.py index 385be5519..c0e80603f 100644 --- a/tests/pool/test_null_pool.py +++ b/tests/pool/test_null_pool.py @@ -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 diff --git a/tests/pool/test_null_pool_async.py b/tests/pool/test_null_pool_async.py index 71e0475f5..23a1a5221 100644 --- a/tests/pool/test_null_pool_async.py +++ b/tests/pool/test_null_pool_async.py @@ -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 diff --git a/tests/pool/test_pool.py b/tests/pool/test_pool.py index 31d789d57..008905411 100644 --- a/tests/pool/test_pool.py +++ b/tests/pool/test_pool.py @@ -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 diff --git a/tests/pool/test_pool_async.py b/tests/pool/test_pool_async.py index 6ad8a8579..b67a575e1 100644 --- a/tests/pool/test_pool_async.py +++ b/tests/pool/test_pool_async.py @@ -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 -- 2.47.2