diff options
Diffstat (limited to 'src/auditor/test-sync.sh')
-rwxr-xr-x | src/auditor/test-sync.sh | 111 |
1 files changed, 82 insertions, 29 deletions
diff --git a/src/auditor/test-sync.sh b/src/auditor/test-sync.sh index 3ab6fa1e4..e0299f636 100755 --- a/src/auditor/test-sync.sh +++ b/src/auditor/test-sync.sh @@ -2,42 +2,95 @@ set -eu -echo -n "Testing synchronization logic ..." +# Exit, with status code "skip" (no 'real' failure) +function exit_skip() { + echo $1 + exit 77 +} -dropdb talercheck-in 2> /dev/null || true -dropdb talercheck-out 2> /dev/null || true +# Exit, with error message (hard failure) +function exit_fail() { + echo $1 + exit 1 +} -createdb talercheck-in || exit 77 -createdb talercheck-out || exit 77 -echo -n "." +check_with_database() +{ + echo -n "Testing synchronization logic ..." -taler-exchange-dbinit -c test-sync-out.conf -echo -n "." -psql talercheck-in < auditor-basedb.sql >/dev/null 2> /dev/null + dropdb talercheck-in 2> /dev/null || true + dropdb talercheck-out 2> /dev/null || true -echo -n "." -taler-auditor-sync -s test-sync-in.conf -d test-sync-out.conf -t + createdb talercheck-in || exit 77 + createdb talercheck-out || exit 77 + echo -n "." -# cs_nonce_locks excluded: no point -for table in denominations denomination_revocations wire_targets reserves reserves_in reserves_close reserves_out auditors auditor_denom_sigs exchange_sign_keys signkey_revocations extensions extension_details known_coins refresh_commitments refresh_revealed_coins refresh_transfer_keys deposits refunds wire_out aggregation_tracking wire_fee recoup recoup_refresh -do + taler-exchange-dbinit -c test-sync-out.conf echo -n "." - CIN=`echo "SELECT COUNT(*) FROM exchange.$table" | psql talercheck-in -Aqt` - COUT=`echo "SELECT COUNT(*) FROM exchange.$table" | psql talercheck-out -Aqt` + psql -Aqt talercheck-in -q -1 -f $1.sql >/dev/null || exit_skip "Failed to load database" - if test ${CIN} != ${COUT} - then - dropdb talercheck-in - dropdb talercheck-out - echo "FAIL" - echo "Record count mismatch: $CIN / $COUT in table $table" - exit 1 - fi -done + echo -n "." + taler-auditor-sync -s test-sync-in.conf -d test-sync-out.conf -t + + # cs_nonce_locks excluded: no point + for table in denominations denomination_revocations wire_targets reserves reserves_in reserves_close reserves_out auditors auditor_denom_sigs exchange_sign_keys signkey_revocations extensions extension_details known_coins refresh_commitments refresh_revealed_coins refresh_transfer_keys deposits refunds wire_out aggregation_tracking wire_fee recoup recoup_refresh + do + echo -n "." + CIN=`echo "SELECT COUNT(*) FROM exchange.$table" | psql talercheck-in -Aqt` + COUT=`echo "SELECT COUNT(*) FROM exchange.$table" | psql talercheck-out -Aqt` + + if test ${CIN} != ${COUT} + then + dropdb talercheck-in + dropdb talercheck-out + echo "FAIL" + exit_fail "Record count mismatch: $CIN / $COUT in table $table" + fi + done + + echo -n ". " + dropdb talercheck-in + dropdb talercheck-out -echo -n ". " -dropdb talercheck-in -dropdb talercheck-out + echo "PASS" +} -echo "PASS" + + +# Postgres database to use +DB=auditor-basedb + +# Configuration file to use +CONF=${DB}.conf + +# test required commands exist +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 || exit_skip "libeufin required" +echo "Testing for pdflatex" +which pdflatex > /dev/null </dev/null || exit_skip "pdflatex required" + +# check if we should regenerate the database +echo "Testing for taler-wallet-cli" +taler-wallet-cli -h >/dev/null </dev/null 2>/dev/null || exit_skip "taler-wallet-cli required" +MYDIR=`mktemp -d /tmp/taler-auditor-basedbXXXXXX` +echo "Generating fresh database at $MYDIR" +if faketime -f '-1 d' ./generate-auditor-basedb.sh $MYDIR/basedb +then + check_with_database $MYDIR/basedb + if test x$fail != x0 + then + exit $fail + else + echo "Cleaning up $MYDIR..." + rm -rf $MYDIR || echo "Removing $MYDIR failed" + fi +else + echo "Generation failed" + exit 77 +fi exit 0 |