Skip to content

Commit

Permalink
Add parallel tests (#192)
Browse files Browse the repository at this point in the history
Uses pg_regress  to run tests in parallel against the database.
Allows custom DB initialization and finalization which can be used to load relevant data in the beginning
and check relevant invariants in the end
  • Loading branch information
ezra-varady authored and Ngalstyan4 committed Oct 13, 2023
1 parent f6c56e5 commit adb57d1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions ci/scripts/run-tests-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function run_db_tests(){
then
cd $WORKDIR/build && \
make test && \
make test-parallel && \
killall postgres && \
gcovr -r $WORKDIR/src/ --object-directory $WORKDIR/build/ --xml /tmp/coverage.xml
fi
Expand Down
25 changes: 21 additions & 4 deletions test/test_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function drop_db {
EOF
}

<<<<<<< HEAD
function run_regression_test {
# Exclude debug/inconsistent output from psql
# So tests will always have the same output
Expand All @@ -51,20 +52,36 @@ trap drop_db EXIT



# Change directory to sql so sql imports will work correctly
# If these aren't parallel tests always drop the db after the test
# if they are though we only want to drop after end which is where we check invariants
# this allows the parallel tests to be run against the same db
if [ "$PARALLEL" -eq 0 ]; then
trap drop_db EXIT
elif [[ "$TESTFILE_NAME" =~ ^end ]]; then
trap drop_db EXIT
fi


# Change directory to sql directory so sql imports will work correctly
cd sql/

# install lantern extension
psql "$@" -U ${DB_USER} -d postgres -v ECHO=none -q -c "DROP DATABASE IF EXISTS ${TEST_CASE_DB};" 2>/dev/null
psql "$@" -U ${DB_USER} -d postgres -v ECHO=none -q -c "CREATE DATABASE ${TEST_CASE_DB};" 2>/dev/null
# if tests are parallel we only do this for the begin tests as we won't be dropping the database until the end
# begin will handle initialization specific to the tests but expects the database already exists
if [ "$PARALLEL" -eq 0 ] || ( [[ "$TESTFILE_NAME" =~ ^begin ]] && [ "$PARALLEL" -eq 1 ] ); then
psql "$@" -U ${DB_USER} -d postgres -v ECHO=none -q -c "DROP DATABASE IF EXISTS ${TEST_CASE_DB};" 2>/dev/null
psql "$@" -U ${DB_USER} -d postgres -v ECHO=none -q -c "CREATE DATABASE ${TEST_CASE_DB};" 2>/dev/null
psql "$@" -U ${DB_USER} -d ${TEST_CASE_DB} -v ECHO=none -q -c "SET client_min_messages=error; CREATE EXTENSION lantern;" 2>/dev/null
psql "$@" -U ${DB_USER} -d ${TEST_CASE_DB} -v ECHO=none -q -f utils/common.sql 2>/dev/null
fi

if [ ! -z "$UPDATE_EXTENSION" ]
then
if [ -z "$UPDATE_FROM" ] || [ -z "$UPDATE_TO" ]
then
echo "ERROR: UPDATE_FROM and UPDATE_TO environment variables must be set before test_runner.sh whenever UPDATE_EXTENSION is set"
exit 1
fi

# 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 lantern VERSION '$UPDATE_FROM';" 2>/dev/null
psql "$@" -U ${DB_USER} -d ${TEST_CASE_DB} -v ECHO=none -q -f utils/common.sql 2>/dev/null
Expand Down

0 comments on commit adb57d1

Please sign in to comment.