From 60b6e76d6637c099ec39e216496c673034285b0c Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 12 Jul 2022 12:24:21 +0100 Subject: [PATCH] test(crdb): tweak server-side cursors test to run on CRDB Server-side cursors are well supported starting from CRDB 22.1.3. --- docs/api/crdb.rst | 2 ++ tests/fix_crdb.py | 2 ++ tests/test_server_cursor.py | 12 +++++++----- tests/test_server_cursor_async.py | 10 ++++++---- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/docs/api/crdb.rst b/docs/api/crdb.rst index 3bc781fcc..de8344ec4 100644 --- a/docs/api/crdb.rst +++ b/docs/api/crdb.rst @@ -32,6 +32,8 @@ affecting Psycopg behaviour: older versions, you can use `CANCEL QUERY`_ instead (but from a different connection). +- :ref:`server-side-cursors` are well supported only from CockroachDB 22.1.3. + - `~psycopg.ConnectionInfo.backend_pid` is only populated from CockroachDB 22.1. Note however that you cannot use the PID to terminate the session; use `SHOW session_id`_ to find the id of a session, which you may terminate with diff --git a/tests/fix_crdb.py b/tests/fix_crdb.py index 5a73d005c..27144774d 100644 --- a/tests/fix_crdb.py +++ b/tests/fix_crdb.py @@ -98,6 +98,7 @@ _crdb_reasons = { "copy array": 82792, "copy canceled": 81559, "copy": 41608, + "cursor invalid name": 84261, "cursor with hold": 77101, "deferrable": 48307, "do": 17511, @@ -124,4 +125,5 @@ _crdb_reasons = { _crdb_reason_version = { "backend pid": "skip < 22", "cancel": "skip < 22", + "server-side cursor": "skip < 22.1.3", } diff --git a/tests/test_server_cursor.py b/tests/test_server_cursor.py index 350d95b65..e1f8ce392 100644 --- a/tests/test_server_cursor.py +++ b/tests/test_server_cursor.py @@ -34,6 +34,7 @@ def test_init_params(conn): assert cur.withhold is True +@pytest.mark.crdb_skip("cursor invalid name") def test_funny_name(conn): cur = conn.cursor("1-2-3") cur.execute("select generate_series(1, 3) as bar") @@ -58,7 +59,7 @@ def test_connection(conn): def test_description(conn): cur = conn.cursor("foo") assert cur.name == "foo" - cur.execute("select generate_series(1, 10) as bar") + cur.execute("select generate_series(1, 10)::int4 as bar") assert len(cur.description) == 1 assert cur.description[0].name == "bar" assert cur.description[0].type_code == cur.adapters.types["int4"].oid @@ -88,7 +89,7 @@ def test_query_params(conn): def test_binary_cursor_execute(conn): cur = conn.cursor("foo", binary=True) - cur.execute("select generate_series(1, 2)") + cur.execute("select generate_series(1, 2)::int4") assert cur.fetchone() == (1,) assert cur.pgresult.fformat(0) == 1 assert cur.pgresult.get_value(0, 0) == b"\x00\x00\x00\x01" @@ -100,7 +101,7 @@ def test_binary_cursor_execute(conn): def test_execute_binary(conn): cur = conn.cursor("foo") - cur.execute("select generate_series(1, 2)", binary=True) + cur.execute("select generate_series(1, 2)::int4", binary=True) assert cur.fetchone() == (1,) assert cur.pgresult.fformat(0) == 1 assert cur.pgresult.get_value(0, 0) == b"\x00\x00\x00\x01" @@ -108,7 +109,7 @@ def test_execute_binary(conn): assert cur.pgresult.fformat(0) == 1 assert cur.pgresult.get_value(0, 0) == b"\x00\x00\x00\x02" - cur.execute("select generate_series(1, 1)") + cur.execute("select generate_series(1, 1)::int4") assert cur.fetchone() == (1,) assert cur.pgresult.fformat(0) == 0 assert cur.pgresult.get_value(0, 0) == b"1" @@ -125,7 +126,7 @@ def test_binary_cursor_text_override(conn): assert cur.pgresult.fformat(0) == 0 assert cur.pgresult.get_value(0, 0) == b"2" - cur.execute("select generate_series(1, 2)") + cur.execute("select generate_series(1, 2)::int4") assert cur.fetchone() == (1,) assert cur.pgresult.fformat(0) == 1 assert cur.pgresult.get_value(0, 0) == b"\x00\x00\x00\x01" @@ -247,6 +248,7 @@ def test_close_no_clobber(conn): with pytest.raises(e.DivisionByZero): with conn.cursor("foo") as cur: cur.execute("select 1 / %s", (0,)) + cur.fetchall() def test_warn_close(conn, recwarn): diff --git a/tests/test_server_cursor_async.py b/tests/test_server_cursor_async.py index 337f1677f..0a795bb82 100644 --- a/tests/test_server_cursor_async.py +++ b/tests/test_server_cursor_async.py @@ -41,6 +41,7 @@ async def test_init_params(aconn): assert cur.withhold is True +@pytest.mark.crdb_skip("cursor invalid name") async def test_funny_name(aconn): cur = aconn.cursor("1-2-3") await cur.execute("select generate_series(1, 3) as bar") @@ -65,7 +66,7 @@ async def test_connection(aconn): async def test_description(aconn): cur = aconn.cursor("foo") assert cur.name == "foo" - await cur.execute("select generate_series(1, 10) as bar") + await cur.execute("select generate_series(1, 10)::int4 as bar") assert len(cur.description) == 1 assert cur.description[0].name == "bar" assert cur.description[0].type_code == cur.adapters.types["int4"].oid @@ -95,7 +96,7 @@ async def test_query_params(aconn): async def test_binary_cursor_execute(aconn): cur = aconn.cursor("foo", binary=True) - await cur.execute("select generate_series(1, 2)") + await cur.execute("select generate_series(1, 2)::int4") assert (await cur.fetchone()) == (1,) assert cur.pgresult.fformat(0) == 1 assert cur.pgresult.get_value(0, 0) == b"\x00\x00\x00\x01" @@ -107,7 +108,7 @@ async def test_binary_cursor_execute(aconn): async def test_execute_binary(aconn): cur = aconn.cursor("foo") - await cur.execute("select generate_series(1, 2)", binary=True) + await cur.execute("select generate_series(1, 2)::int4", binary=True) assert (await cur.fetchone()) == (1,) assert cur.pgresult.fformat(0) == 1 assert cur.pgresult.get_value(0, 0) == b"\x00\x00\x00\x01" @@ -132,7 +133,7 @@ async def test_binary_cursor_text_override(aconn): assert cur.pgresult.fformat(0) == 0 assert cur.pgresult.get_value(0, 0) == b"2" - await cur.execute("select generate_series(1, 2)") + await cur.execute("select generate_series(1, 2)::int4") assert (await cur.fetchone()) == (1,) assert cur.pgresult.fformat(0) == 1 assert cur.pgresult.get_value(0, 0) == b"\x00\x00\x00\x01" @@ -258,6 +259,7 @@ async def test_close_no_clobber(aconn): with pytest.raises(e.DivisionByZero): async with aconn.cursor("foo") as cur: await cur.execute("select 1 / %s", (0,)) + await cur.fetchall() async def test_warn_close(aconn, recwarn): -- 2.47.2