Skip to content

Commit f26787b

Browse files
committed
test(pg-compat): review follow-ups — Go cleanup parity, connect encoding assert, xfail entry warning
1 parent 8d2f338 commit f26787b

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

test/pg-compat/behaviors/connect.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ def run(Adapter):
99
a = Adapter()
1010
try:
1111
assert a.exec_simple("SELECT 1")[0][0] == 1
12+
# Uniform with the four SP-3 driver ports (go/java/node/prisma):
13+
# assert the client_encoding=UTF8 pin took effect -- see
14+
# harness/targets.py's encoding rationale (backend DBs default to
15+
# SQL_ASCII; ProxySQL imposes UTF8).
16+
assert a.exec_simple("SHOW client_encoding")[0][0] == "UTF8"
1217
finally:
1318
a.close()

test/pg-compat/conftest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import warnings
23

34
import psycopg
45
import pytest
@@ -48,11 +49,26 @@ def proxy_conn():
4849

4950

5051
def pytest_collection_modifyitems(config, items):
52+
matched_ids = set()
5153
for item in items:
5254
entry = _XFAILS.get(item.nodeid)
5355
if entry:
56+
matched_ids.add(item.nodeid)
5457
item.add_marker(
5558
pytest.mark.xfail(
5659
reason=f'{entry["reason"]} ({entry["ref"]})', strict=False
5760
)
5861
)
62+
63+
# Catalogue hygiene: a [[xfail]] entry whose test_id matched NO collected
64+
# item is currently a silent no-op (e.g. a typo'd nodeid, or a test that
65+
# was renamed/removed without updating xfail.toml). Warn -- don't fail
66+
# collection -- so a stale/typo'd entry is visible in the run instead of
67+
# quietly doing nothing forever.
68+
for test_id in _XFAILS:
69+
if test_id not in matched_ids:
70+
warnings.warn(
71+
f"xfail.toml entry test_id={test_id!r} matched no collected "
72+
f"test item -- stale or typo'd entry?",
73+
stacklevel=1,
74+
)

test/pg-compat/drivers/go/behaviors.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,13 @@ func transactions() error {
110110
defer conn.Close(ctx)
111111

112112
// Cleanup runs on success AND on failure (defer), leaving no state
113-
// behind, same as the Python behavior's try/finally.
113+
// behind, same as the Python behavior's try/finally. Parity with
114+
// Java/Node/Prisma: best-effort ROLLBACK first (error ignored) restores
115+
// a usable session state before the DROP -- if a non-assertion error
116+
// above left the connection mid-transaction, an aborted implicit
117+
// transaction would otherwise reject the DROP.
114118
defer func() {
119+
conn.Exec(ctx, "ROLLBACK")
115120
conn.Exec(ctx, fmt.Sprintf("DROP TABLE IF EXISTS %s", txTable))
116121
}()
117122

0 commit comments

Comments
 (0)