]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test: add missing prepared async tests
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 11 Apr 2024 22:44:42 +0000 (00:44 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 11 Apr 2024 22:44:42 +0000 (00:44 +0200)
Sync and async sides diverged because the async-to-sync check in CI was
pretty much disabled by the lack of the -B.

tests/test_prepared.py
tests/test_prepared_async.py

index 1dd4e9534dacd7c4271d64b844b2885cdb771415..20d09e29170539454689238b85e53da241361fd9 100644 (file)
@@ -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
index ef0c576053eb2a977e64f0783c288f79fb373719..fa73735974a24ede3d0649a60b032a120a8a7f77 100644 (file)
@@ -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])