Skip to content

Commit

Permalink
Make sure update script returns non-zero error on failure
Browse files Browse the repository at this point in the history
Fix wront return code check

Add index validation functions to update script

Fix update test runner logic

We used to run new tests on the old DB.
This need not always succeed as new tests may use/test functionality
from the newer version of the DB.
In the new approach, we only run tests *after* upgrade script has
been run.

Make common.sql idempotent

Suppress common output and add update comments

Rename main -> from_tags[-1] in update script

Do not fail on parallel test failure during update (tracked by #226)
  • Loading branch information
Ngalstyan4 committed Nov 18, 2023
1 parent fc6029f commit 6a31a91
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 20 deletions.
43 changes: 28 additions & 15 deletions scripts/test_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@
'16': ['0.0.4']
}

def shell(cmd, exit_on_error=True):
res = subprocess.run(cmd, shell=True)
if res.returncode != 0:
if res.stderr:
print("Error building from tag" + res.stderr)
print("res stdout", res.stdout, res)
if exit_on_error:
exit(1)
else:
print("ERROR on command", cmd)


def update_from_tag(from_version: str, to_version: str):
from_tag = "v" + from_version
repo = git.Repo(search_parent_directories=True)
Expand All @@ -19,23 +31,21 @@ def update_from_tag(from_version: str, to_version: str):
print("sha_after", sha_after)

# run "mkdir build && cd build && cmake .. && make -j4 && make install"
res = subprocess.run(f"mkdir -p {args.builddir} ; cd {args.builddir} && git submodule update && cmake .. && make -j4 && make install", shell=True)
if res.returncode != 0:
if res.stderr:
print("Error building from tag" + res.stderr)
print("res stdout", res.stdout, res.stderr, res)
exit(1)
res = shell(f"mkdir -p {args.builddir} ; cd {args.builddir} && git submodule update && cmake .. && make -j4 && make install")

res = subprocess.run(f"psql postgres -U {args.user} -c 'DROP DATABASE IF EXISTS {args.db};'", shell=True)
res = subprocess.run(f"psql postgres -U {args.user} -c 'CREATE DATABASE {args.db};'", shell=True)
res = subprocess.run(f"psql postgres -U {args.user} -c 'DROP EXTENSION IF EXISTS lantern CASCADE; CREATE EXTENSION lantern;' -d {args.db};", shell=True)
res = shell(f"psql postgres -U {args.user} -c 'DROP DATABASE IF EXISTS {args.db};'")
res = shell(f"psql postgres -U {args.user} -c 'CREATE DATABASE {args.db};'")
res = shell(f"psql postgres -U {args.user} -c 'DROP EXTENSION IF EXISTS lantern CASCADE; CREATE EXTENSION lantern;' -d {args.db};")
# todo:: run init() portion of parallel tests

repo.git.checkout(sha_before)
res = subprocess.run(f"cd {args.builddir} ; git submodule update && cmake .. && make -j4 && make install && make test", shell=True)
res = subprocess.run(f"cd {args.builddir} ; UPDATE_EXTENSION=1 UPDATE_FROM={from_version} UPDATE_TO={to_version} make test", shell=True)
res = subprocess.run(f"cd {args.builddir} ; UPDATE_EXTENSION=1 UPDATE_FROM={from_version} UPDATE_TO={from_version} make test-parallel FILTER=begin", shell=True)
res = subprocess.run(f"cd {args.builddir} ; UPDATE_EXTENSION=1 UPDATE_FROM={from_version} UPDATE_TO={to_version} make test-parallel EXCLUDE=begin", shell=True)
res = shell(f"cd {args.builddir} ; git submodule update && cmake .. && make -j4 && make install")
res = shell(f"cd {args.builddir} ; UPDATE_EXTENSION=1 UPDATE_FROM={from_version} UPDATE_TO={to_version} make test")
# run begin on {from_version}
res = shell(f"cd {args.builddir} ; UPDATE_EXTENSION=1 UPDATE_FROM={from_version} UPDATE_TO={from_version} make test-parallel FILTER=begin")
# run the actual parallel tests after the upgrade
# todo: parallel tests are failing (tracked by https://github.com/lanterndata/lantern/issues/226)
res = shell(f"cd {args.builddir} ; UPDATE_EXTENSION=1 UPDATE_FROM={from_version} UPDATE_TO={to_version} make test-parallel EXCLUDE=begin", exit_on_error=False)
#todo:: run query and check portion of parallel tests

def incompatible_version(pg_version, version_tag):
Expand Down Expand Up @@ -71,8 +81,11 @@ def incompatible_version(pg_version, version_tag):
exit(1)

# test updates from all tags
from_tags = [update_fname.split("--")[0] for update_fname in os.listdir("sql/updates")]
latest_version = "main"
tag_pairs = [update_fname.split("--") for update_fname in os.listdir("sql/updates")]
from_tags = [p[0] for p in tag_pairs]
to_tags = [p[1].split(".sql")[0] for p in tag_pairs]
# os.listdir has alphabetical order and postgres enforces same order of versions
latest_version = to_tags[-1]

pg_version = None if not 'PG_VERSION' in os.environ else os.environ['PG_VERSION']
for from_tag in from_tags:
Expand Down
10 changes: 9 additions & 1 deletion sql/updates/0.0.4--latest.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ BEGIN
END IF;
END;
$BODY$
LANGUAGE plpgsql;
LANGUAGE plpgsql;

CREATE SCHEMA _lantern_internal;

CREATE FUNCTION _lantern_internal.validate_index(index regclass, print_info boolean DEFAULT true) RETURNS VOID
AS 'MODULE_PATHNAME', 'lantern_internal_validate_index' LANGUAGE C STABLE STRICT PARALLEL UNSAFE;

CREATE FUNCTION _lantern_internal.failure_point_enable(func TEXT, name TEXT, dont_trigger_first_nr INTEGER DEFAULT 0) RETURNS VOID
AS 'MODULE_PATHNAME', 'lantern_internal_failure_point_enable' LANGUAGE C STABLE STRICT PARALLEL UNSAFE;
6 changes: 5 additions & 1 deletion test/sql/utils/common.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
-- N.B.: This file shall be maintained such that it can safely be rerun without throwing an error
-- This is because in upgrade tests we may run this multiple times in preparation for sequential
-- and parallel upgrade tests

-- test helper functions that should exist in all test runs live here
-- there is no need to explicitly include this file in other tests as the test runner will
-- run this before running the actual test

CREATE EXTENSION pageinspect;
CREATE EXTENSION IF NOT EXISTS pageinspect;

\set ON_ERROR_STOP on

Expand Down
7 changes: 4 additions & 3 deletions test/test_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ then
exit 1
fi

# print all available migrations with the line below:
# psql "$@" -U ${DB_USER} -d ${TEST_CASE_DB} -q -c "SELECT * FROM pg_extension_update_paths('lantern');" 2>/dev/null
# install the old version of the extension and sanity-check that all tests pass
psql "$@" -U ${DB_USER} -d ${TEST_CASE_DB} -v ECHO=none -q -c "SET client_min_messages=error; CREATE EXTENSION IF NOT EXISTS lantern VERSION '$UPDATE_FROM';" 2>/dev/null
psql "$@" -U ${DB_USER} -d ${TEST_CASE_DB} -v ECHO=none -q -c "SET client_min_messages=error; CREATE EXTENSION IF NOT EXISTS lantern VERSION '$UPDATE_FROM';"
psql "$@" -U ${DB_USER} -d ${TEST_CASE_DB} -v ECHO=none -q -f utils/common.sql 2>/dev/null
run_regression_test $@
# upgrade to the new version of the extension and make sure that all existing tests still pass
# todo:: this approach currently is broken for pgvector-compat related upgrade scripts as that regression test drops
# and recreates the extension so whatever we do here is ignored
psql "$@" -U ${DB_USER} -d ${TEST_CASE_DB} -v ECHO=none -q -c "SET client_min_messages=error; ALTER EXTENSION lantern UPDATE TO '$UPDATE_TO';" 2>/dev/null
psql "$@" -U ${DB_USER} -d ${TEST_CASE_DB} -v ECHO=none -q -c "SET client_min_messages=error; ALTER EXTENSION lantern UPDATE TO '$UPDATE_TO';"
run_regression_test $@
else

Expand Down

0 comments on commit 6a31a91

Please sign in to comment.