diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index bb260004f..61a6e167e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -49,7 +49,7 @@ jobs: sudo pip install GitPython &&\ # Start postgres sudo su postgres -c "PG_VERSION=$PG_VERSION RUN_TESTS=0 ./ci/scripts/run-tests-linux.sh" && \ - sudo python3 ./scripts/test_updates.py -U postgres + sudo su -c "PG_VERSION=$PG_VERSION python3 ./scripts/test_updates.py -U postgres" env: PG_VERSION: ${{ matrix.postgres }} if: ${{ startsWith(matrix.os, 'ubuntu') }} diff --git a/ci/scripts/run-tests-linux.sh b/ci/scripts/run-tests-linux.sh index 50a6f6f04..ed8d4a740 100755 --- a/ci/scripts/run-tests-linux.sh +++ b/ci/scripts/run-tests-linux.sh @@ -8,7 +8,7 @@ RUN_TESTS=${RUN_TESTS:-1} export PGDATA=/etc/postgresql/$PG_VERSION/main -wait_for_pg(){ +function wait_for_pg(){ tries=0 until pg_isready -U postgres 2>/dev/null; do if [ $tries -eq 10 ]; @@ -32,16 +32,29 @@ function run_db_tests(){ fi } -echo "port = 5432" >> ${PGDATA}/postgresql.conf -# Enable auth without password -echo "local all all trust" > $PGDATA/pg_hba.conf -echo "host all all 127.0.0.1/32 trust" >> $PGDATA/pg_hba.conf -echo "host all all ::1/128 trust" >> $PGDATA/pg_hba.conf +function start_pg() { + pg_response=$(pg_isready -U postgres 2>&1) + echo "RESPONSE IS $pg_response" + if [[ $pg_response == *"accepting"* ]]; then + echo "Postgres already running" + elif [[ $pg_response == *"rejecting"* ]]; then + echo "Postgres process is being killed retrying..." + sleep 1 + start_pg + else + echo "port = 5432" >> ${PGDATA}/postgresql.conf + # Enable auth without password + echo "local all all trust" > $PGDATA/pg_hba.conf + echo "host all all 127.0.0.1/32 trust" >> $PGDATA/pg_hba.conf + echo "host all all ::1/128 trust" >> $PGDATA/pg_hba.conf -# Set port -echo "port = 5432" >> ${PGDATA}/postgresql.conf -# Run postgres database -GCOV_PREFIX=$WORKDIR/build/CMakeFiles/lantern.dir/ GCOV_PREFIX_STRIP=5 POSTGRES_HOST_AUTH_METHOD=trust /usr/lib/postgresql/$PG_VERSION/bin/postgres 1>/tmp/pg-out.log 2>/tmp/pg-error.log & + + # Set port + echo "port = 5432" >> ${PGDATA}/postgresql.conf + # Run postgres database + GCOV_PREFIX=$WORKDIR/build/CMakeFiles/lantern.dir/ GCOV_PREFIX_STRIP=5 POSTGRES_HOST_AUTH_METHOD=trust /usr/lib/postgresql/$PG_VERSION/bin/postgres 1>/tmp/pg-out.log 2>/tmp/pg-error.log & + fi +} # Wait for start and run tests -wait_for_pg && run_db_tests +start_pg && wait_for_pg && run_db_tests diff --git a/scripts/test_updates.py b/scripts/test_updates.py index 0b0b4ad06..702eaf67e 100644 --- a/scripts/test_updates.py +++ b/scripts/test_updates.py @@ -4,13 +4,15 @@ import git import os + +INCOMPATIBLE_VERSIONS = { + '16': ['0.0.4'] +} + def update_from_tag(from_version: str, to_version: str): from_tag = "v" + from_version - to_tag = "v" + to_version repo = git.Repo(search_parent_directories=True) sha_before = repo.head.object.hexsha - print("sha_before", sha_before) - print("checkout to tag", from_tag) repo.remotes[0].fetch() repo.git.checkout(from_tag) sha_after = repo.head.object.hexsha @@ -30,11 +32,15 @@ def update_from_tag(from_version: str, to_version: str): # todo:: run init() portion of parallel tests repo.git.checkout(sha_before) - print("sha_before", 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) #todo:: run query and check portion of parallel tests +def incompatible_version(pg_version, version_tag): + if not pg_version or pg_version not in INCOMPATIBLE_VERSIONS: + return False + return version_tag in INCOMPATIBLE_VERSIONS[pg_version] + if __name__ == "__main__": default_user = getpass.getuser() @@ -62,11 +68,13 @@ def update_from_tag(from_version: str, to_version: str): exit(1) # test updates from all tags - print([update_fname for update_fname in os.listdir("sql/updates")]) from_tags = [update_fname.split("--")[0] for update_fname in os.listdir("sql/updates")] - print(from_tags) latest_version = "0.0.5" + + pg_version = None if not 'PG_VERSION' in os.environ else os.environ['PG_VERSION'] for from_tag in from_tags: + if incompatible_version(pg_version, from_tag): + continue update_from_tag(from_tag, latest_version)