Skip to content

Commit

Permalink
Try to fix test suite on old pg versions (#8108)
Browse files Browse the repository at this point in the history
- Skip extension test that uses ltree on older postgres versions
- Skip restore part of pg_dump tests
- Skip query_stats tests
- Use psql to restore dumps during branch creation
  • Loading branch information
msullivan authored Dec 12, 2024
1 parent 5d2d0cd commit 446045f
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion edb/buildmeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
# The merge conflict there is a nice reminder that you probably need
# to write a patch in edb/pgsql/patches.py, and then you should preserve
# the old value.
EDGEDB_CATALOG_VERSION = 2024_12_04_00_00
EDGEDB_CATALOG_VERSION = 2024_12_11_00_00
EDGEDB_MAJOR_VERSION = 6


Expand Down
11 changes: 11 additions & 0 deletions edb/lib/_testmode.edgeql
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,17 @@ sys::_sleep(duration: std::duration) -> std::bool
};


CREATE FUNCTION
sys::_postgres_version() -> std::str
{
CREATE ANNOTATION std::description :=
'Get the postgres version string';
USING SQL $$
SELECT version()
$$;
};


CREATE FUNCTION
sys::_advisory_lock(key: std::int64) -> std::bool
{
Expand Down
11 changes: 8 additions & 3 deletions edb/server/pgcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,16 +333,19 @@ async def _copy_database(
if self._pg_bin_dir is None:
await self.lookup_postgres()
pg_dump = self._find_pg_binary('pg_dump')
pg_restore = self._find_pg_binary('pg_restore')
# We actually just use psql to restore, because it is more
# tolerant of version differences.
# TODO: Maybe use pg_restore when we know we match the backend version?
pg_restore = self._find_pg_binary('psql')

src_conn_args, src_env = self._dump_restore_conn_args(src_dbname)
tgt_conn_args, _tgt_env = self._dump_restore_conn_args(tgt_dbname)

dump_args = [
pg_dump, '--verbose', '--format=c', *src_conn_args, *src_args
pg_dump, '--verbose', *src_conn_args, *src_args
]
restore_args = [
pg_restore, '--verbose', *tgt_conn_args, *tgt_args
pg_restore, *tgt_conn_args, *tgt_args
]

rpipe, wpipe = os.pipe()
Expand All @@ -367,6 +370,8 @@ async def _copy_database(
stdin=rpipe,
capture_stdout=False,
capture_stderr=False,
log_stdout=True,
log_stderr=True,
env=src_env,
)
finally:
Expand Down
12 changes: 12 additions & 0 deletions edb/testbase/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
from edb.common import retryloop
from edb.common import secretkey

from edb import buildmeta
from edb import protocol
from edb.protocol import protocol as test_protocol
from edb.testbase import serutils
Expand Down Expand Up @@ -1982,6 +1983,17 @@ def setUpClass(cls):
# Run pg_dump to create the dump data for an existing Gel database.
with tempfile.NamedTemporaryFile() as f:
cls.run_pg_dump_on_connection(conargs, '-f', f.name)

# Skip the restore part of the test if the database
# backend is older than our pg_dump, since it won't work.
pg_ver_str = cls.loop.run_until_complete(
cls.backend.fetch('select version()')
)[0][0]
pg_ver = buildmeta.parse_pg_version(pg_ver_str)
bundled_ver = buildmeta.get_pg_version()
if pg_ver.major < bundled_ver.major:
raise unittest.SkipTest('pg_dump newer than backend')

# Create a new Postgres database to be used for dump tests.
db_exists = cls.loop.run_until_complete(
cls.backend.fetch(f'''
Expand Down
8 changes: 8 additions & 0 deletions tests/test_edgeql_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import edgedb

import edb.buildmeta
from edb.testbase import server as tb


Expand Down Expand Up @@ -112,6 +113,13 @@ async def _extension_test_01(self):
''')

async def test_edgeql_extensions_01(self):
pg_ver = edb.buildmeta.parse_pg_version(await self.con.query_single('''
select sys::_postgres_version();
'''))
# Skip if postgres is old, since it doesn't have ltree 1.3
if pg_ver.major < 17:
self.skipTest('Postgres version too old')

# Make an extension that wraps a tiny bit of the ltree package.
await self.con.execute('''
create extension package ltree VERSION '1.0' {
Expand Down
5 changes: 5 additions & 0 deletions tests/test_edgeql_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ async def _bad_query_for_stats(self):
raise NotImplementedError

async def _test_sys_query_stats(self):
if self.backend_dsn:
self.skipTest(
"can't run query stats test when extension isn't present"
)

stats_query = f'''
with stats := (
select
Expand Down

0 comments on commit 446045f

Please sign in to comment.