Skip to content

Commit

Permalink
Do not run update script for pg16 and v0.0.4, fix pg start race condi…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
var77 committed Oct 9, 2023
1 parent 2f313f8 commit be60693
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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') }}
Expand Down
35 changes: 24 additions & 11 deletions ci/scripts/run-tests-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Expand All @@ -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
20 changes: 14 additions & 6 deletions scripts/test_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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)


Expand Down

0 comments on commit be60693

Please sign in to comment.