From: Daniele Varrazzo Date: Thu, 11 Apr 2024 22:44:42 +0000 (+0200) Subject: test: add missing prepared async tests X-Git-Tag: 3.2.0~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5eb3086c5e697a091ff46a50f2158a661687ddf6;p=thirdparty%2Fpsycopg.git test: add missing prepared async tests Sync and async sides diverged because the async-to-sync check in CI was pretty much disabled by the lack of the -B. --- diff --git a/tests/test_prepared.py b/tests/test_prepared.py index 1dd4e9534..20d09e291 100644 --- a/tests/test_prepared.py +++ b/tests/test_prepared.py @@ -191,7 +191,7 @@ def test_deallocate_or_close(conn, caplog): conn.execute("select 1::bigint") conn.execute("select 1::text") - msgs = "\n".join(rec.message for rec in caplog.records) + msgs = "\n".join((rec.message for rec in caplog.records)) if psycopg.pq.__build_version__ >= 170000: assert "PGconn.send_close_prepared" in msgs assert "DEALLOCATE" not in msgs diff --git a/tests/test_prepared_async.py b/tests/test_prepared_async.py index ef0c57605..fa7373597 100644 --- a/tests/test_prepared_async.py +++ b/tests/test_prepared_async.py @@ -2,12 +2,16 @@ Prepared statements tests """ +import sys +import logging import datetime as dt from decimal import Decimal import pytest +import psycopg from psycopg.rows import namedtuple_row +from psycopg.pq._debug import PGconnDebug @pytest.mark.parametrize("value", [None, 0, 3]) @@ -174,6 +178,45 @@ async def test_evict_lru_deallocate(aconn): assert got == [f"select {i}" for i in ["'a'", 6, 7, 8, 9]] +@pytest.mark.skipif("psycopg._cmodule._psycopg", reason="Python-only debug conn") +async def test_deallocate_or_close(aconn, caplog): + aconn.pgconn = PGconnDebug(aconn.pgconn) + caplog.set_level(logging.INFO, logger="psycopg.debug") + + await aconn.set_autocommit(True) + aconn.prepare_threshold = 0 + aconn.prepared_max = 1 + + await aconn.execute("select 1::bigint") + await aconn.execute("select 1::text") + + msgs = "\n".join(rec.message for rec in caplog.records) + if psycopg.pq.__build_version__ >= 170000: + assert "PGconn.send_close_prepared" in msgs + assert "DEALLOCATE" not in msgs + else: + assert "PGconn.send_close_prepared" not in msgs + assert "DEALLOCATE" in msgs + + +def test_prepared_max_none(conn): + conn.prepared_max = 42 + assert conn.prepared_max == 42 + assert conn._prepared.prepared_max == 42 + + conn.prepared_max = None + assert conn._prepared.prepared_max == sys.maxsize + assert conn.prepared_max is None + + conn.prepared_max = 0 + assert conn._prepared.prepared_max == 0 + assert conn.prepared_max == 0 + + conn.prepared_max = 24 + assert conn.prepared_max == 24 + assert conn._prepared.prepared_max == 24 + + async def test_different_types(aconn): aconn.prepare_threshold = 0 await aconn.execute("select %s", [None])