Skip to content

Commit d141297

Browse files
author
chenyunliang520
committed
Add wal_level check to skip logical decoding tests when not set to logical; skip composite and range type tests on GaussDB
1 parent 8fb9d8b commit d141297

File tree

4 files changed

+49
-19
lines changed

4 files changed

+49
-19
lines changed

tests/conftest.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,36 @@ def get_database_type():
145145
print(f"Failed to get database version: {e}")
146146
return ""
147147

148+
def get_wal_level():
149+
dsn = os.getenv("DSN") or os.getenv("GAUSSDB_TEST_DSN")
150+
if not dsn:
151+
print("DSN environment variable not set")
152+
return ""
153+
154+
try:
155+
conn = pq.PGconn.connect(dsn.encode("utf-8"))
156+
if conn.status != pq.ConnStatus.OK:
157+
print(f"Connection failed: {conn.error_message.decode()}")
158+
conn.finish()
159+
return ""
160+
161+
res = conn.exec_(b"SHOW wal_level;")
162+
if res.status != pq.ExecStatus.TUPLES_OK:
163+
print(f"Query failed: {conn.error_message.decode()}")
164+
res.clear()
165+
conn.finish()
166+
return ""
167+
168+
raw_wal_level = res.get_value(0, 0)
169+
wal_level = raw_wal_level.decode("utf-8").lower() if raw_wal_level is not None else ""
170+
171+
res.clear()
172+
conn.finish()
173+
return wal_level
174+
except Exception as e:
175+
print(f"Failed to get wal_level: {e}")
176+
return ""
177+
148178

149179
def pytest_collection_modifyitems(config, items):
150180
res = get_database_type()

tests/test_logical_decoding.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import pytest
2+
from .conftest import get_wal_level
23

34
SLOT_NAME = "slot_test"
45
SCHEMA = "my_schema"
56
TABLE = "test01"
67

78

9+
@pytest.fixture(scope="session", autouse=True)
10+
def check_wal_level():
11+
"""Check if wal_level is set to logical, skip tests if not."""
12+
wal_level = get_wal_level()
13+
if wal_level != "logical":
14+
pytest.skip(f"wal_level={wal_level!r}, expected 'logical'")
15+
16+
817
def _slot_exists(conn, slot_name):
918
cur = conn.cursor()
1019
cur.execute(
@@ -37,7 +46,7 @@ def _cleanup_slot_and_schema(conn):
3746

3847

3948
@pytest.fixture(scope="function")
40-
def setup_env(conn):
49+
def setup_env(conn, check_wal_level):
4150
"""Ensure clean environment for each test."""
4251
_cleanup_slot_and_schema(conn)
4352
cur = conn.cursor()

tests/types/test_composite.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from ..utils import eur
1111
from ..fix_crdb import crdb_skip_message, is_crdb
1212
from ..test_adapt import StrNoneBinaryDumper, StrNoneDumper
13+
from ..conftest import get_database_type
1314

1415
pytestmark = pytest.mark.crdb_skip("composite")
1516

@@ -162,6 +163,9 @@ def test_load_record_binary(conn, want, rec):
162163
def testcomp(svcconn):
163164
if is_crdb(svcconn):
164165
pytest.skip(crdb_skip_message("composite"))
166+
res = get_database_type()
167+
if res == "gaussdb":
168+
pytest.skip("gaussdb not support.")
165169
cur = svcconn.cursor()
166170
cur.execute(
167171
"""

tests/types/test_range.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from ..utils import eur
1313
from ..fix_crdb import crdb_skip_message, is_crdb
1414
from ..test_adapt import StrNoneBinaryDumper, StrNoneDumper
15+
from ..conftest import get_database_type
1516

1617
pytestmark = pytest.mark.crdb_skip("range")
1718

@@ -268,27 +269,14 @@ def create_test_range(conn):
268269
if is_crdb(conn):
269270
pytest.skip(crdb_skip_message("range"))
270271

272+
res = get_database_type()
273+
if res == "gaussdb":
274+
pytest.skip("gaussdb not support.")
275+
271276
conn.execute(
272277
"""
273-
ALTER FUNCTION testschema.testrange(
274-
double precision,
275-
double precision
276-
)
277-
OWNER TO root;
278-
279-
ALTER FUNCTION testschema.testrange(
280-
double precision,
281-
double precision,
282-
text
283-
)
284-
OWNER TO root;
285-
286-
ALTER FUNCTION public.testrange(text, text, text) OWNER TO root;
287-
ALTER FUNCTION public.testrange(text, text) OWNER TO root;
288-
289278
drop schema if exists testschema cascade;
290279
create schema testschema;
291-
292280
drop type if exists testrange cascade;
293281
drop type if exists testschema.testrange cascade;
294282
@@ -297,7 +285,6 @@ def create_test_range(conn):
297285
"""
298286
)
299287

300-
301288
fetch_cases = [
302289
("testrange", "text"),
303290
("testschema.testrange", "float8"),

0 commit comments

Comments
 (0)