From 05cf62b3973236c8646005e27a50cc27be559408 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 12 Sep 2022 11:33:56 +0200 Subject: -use private DB for tests --- src/auditor/test-sync.sh | 63 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 10 deletions(-) (limited to 'src/auditor/test-sync.sh') diff --git a/src/auditor/test-sync.sh b/src/auditor/test-sync.sh index b40f11557..0c9327d63 100755 --- a/src/auditor/test-sync.sh +++ b/src/auditor/test-sync.sh @@ -1,20 +1,36 @@ -#!/bin/sh +#!/bin/bash set -eu # Exit, with status code "skip" (no 'real' failure) -exit_skip() { - echo $1 +function exit_skip() { + echo "SKIPPING test: $1" exit 77 } # Exit, with error message (hard failure) -exit_fail() { - echo $1 +function exit_fail() { + echo "FAILING test: $1" exit 1 } -check_with_database() +# Cleanup to run whenever we exit +function cleanup() { + if test ! -z ${POSTGRES_PATH:-} + then + ${POSTGRES_PATH}/pg_ctl -D $TMPDIR stop &> /dev/null || true + fi + for n in `jobs -p` + do + kill $n 2> /dev/null || true + done + wait +} + +# Install cleanup handler (except for kill -9) +trap cleanup EXIT + +function check_with_database() { echo -n "Testing synchronization logic ..." @@ -68,15 +84,41 @@ echo "Testing for jq" jq -h > /dev/null || exit_skip "jq required" echo "Testing for faketime" faketime -h > /dev/null || exit_skip "faketime required" -# NOTE: really check for all three libeufin commands? echo "Testing for libeufin" -libeufin-cli --help >/dev/null /dev/null /dev/null || exit_skip "libeufin required" echo "Testing for pdflatex" which pdflatex > /dev/null /dev/null /dev/null || exit_skip "taler-wallet-cli required" + +echo -n "Testing for Postgres" +HAVE_INITDB=`find /usr -name "initdb" | grep postgres` || exit_skip " MISSING" +echo " FOUND" +echo -n "Setting up Postgres DB" +INITDB_BIN=`find /usr -name "initdb" | grep bin/initdb | grep postgres | sort -n | tail -n1` +POSTGRES_PATH=`basename $INITDB_BIN` +TMPDIR=`mktemp -d /tmp/taler-test-postgresXXXXXX` +$INITDB_BIN --no-sync --auth=trust -D ${TMPDIR} > postgres-dbinit.log 2> postgres-dbinit.err +echo " DONE" +mkdir ${TMPDIR}/sockets +echo -n "Launching Postgres service" +cat - >> $TMPDIR/postgresql.conf < $TMPDIR/pg_hba.conf.new +mv $TMPDIR/pg_hba.conf.new $TMPDIR/pg_hba.conf +${POSTGRES_PATH}/pg_ctl -D $TMPDIR -l /dev/null start > postgres-start.log 2> postgres-start.err +echo " DONE" +PGHOST="$TMPDIR/sockets" +EXPORT PGHOST="@POSTGRES_SOCKET" + + + MYDIR=`mktemp -d /tmp/taler-auditor-basedbXXXXXX` echo "Generating fresh database at $MYDIR" if faketime -f '-1 d' ./generate-auditor-basedb.sh $MYDIR/basedb @@ -88,6 +130,7 @@ then else echo "Cleaning up $MYDIR..." rm -rf $MYDIR || echo "Removing $MYDIR failed" + rm -rf $TMPDIR || echo "Removing $TMPDIR failed" fi else echo "Generation failed" -- cgit v1.2.3