diff options
author | Florian Dold <florian@dold.me> | 2024-11-11 13:06:31 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-11-11 13:06:44 +0100 |
commit | e9125316643461b8af190263aacac79d8fe7998f (patch) | |
tree | eb0511ec2b9dc859a55a0c59db4f4b9da29093f7 | |
parent | 9508cb1806608274262f70efee9d43630b81ccd3 (diff) |
auditor: wait for libeufin-bank in tests
-rwxr-xr-x | src/auditor/setup.sh | 123 |
1 files changed, 69 insertions, 54 deletions
diff --git a/src/auditor/setup.sh b/src/auditor/setup.sh index 41ddc3da2..18892e896 100755 --- a/src/auditor/setup.sh +++ b/src/auditor/setup.sh @@ -11,82 +11,97 @@ set -eu # Cleanup to run whenever we exit -function exit_cleanup() -{ - if [ ! -z ${SETUP_PID+x} ] - then - echo "Killing taler-unified-setup ($SETUP_PID)" >&2 - kill -TERM "$SETUP_PID" 2> /dev/null || true - wait "$SETUP_PID" 2> /dev/null || true - fi +function exit_cleanup() { + if [ ! -z ${SETUP_PID+x} ]; then + echo "Killing taler-unified-setup ($SETUP_PID)" >&2 + kill -TERM "$SETUP_PID" 2>/dev/null || true + wait "$SETUP_PID" 2>/dev/null || true + fi } # Install cleanup handler (except for kill -9) trap exit_cleanup EXIT -function setup() -{ - echo "Starting test system ..." >&2 - # Create a named pipe in a temp directory we own. - FIFO_DIR=$(mktemp -d fifo-XXXXXX) - FIFO_OUT=$(echo "$FIFO_DIR/out") - mkfifo "$FIFO_OUT" - # Open pipe as FD 3 (RW) and FD 4 (RO) - exec 3<> "$FIFO_OUT" 4< "$FIFO_OUT" - rm -rf "$FIFO_DIR" - # We require '-W' for our termination logic to work. - taler-unified-setup.sh -W "$@" \ - > >(tee taler-unified-setup.log >&3) & - SETUP_PID=$! - # Close FD3 - exec 3>&- - sed -u '/<<READY>>/ q' <&4 - # Close FD4 - exec 4>&- - echo "Test system ready" >&2 +function setup() { + echo "Starting test system ..." >&2 + # Create a named pipe in a temp directory we own. + FIFO_DIR=$(mktemp -d fifo-XXXXXX) + FIFO_OUT=$(echo "$FIFO_DIR/out") + mkfifo "$FIFO_OUT" + # Open pipe as FD 3 (RW) and FD 4 (RO) + exec 3<>"$FIFO_OUT" 4<"$FIFO_OUT" + rm -rf "$FIFO_DIR" + # We require '-W' for our termination logic to work. + taler-unified-setup.sh -W "$@" \ + > >(tee taler-unified-setup.log >&3) & + SETUP_PID=$! + # Close FD3 + exec 3>&- + sed -u '/<<READY>>/ q' <&4 + # Close FD4 + exec 4>&- + echo "Test system ready" >&2 } # Exit, with status code "skip" (no 'real' failure) function exit_fail() { - echo "$@" >&2 - exit 1 + echo "$@" >&2 + exit 1 } # Exit, with status code "skip" (no 'real' failure) function exit_skip() { - echo "SKIPPING: $1" - exit 77 + echo "SKIPPING: $1" + exit 77 } function get_payto_uri() { - export LIBEUFIN_SANDBOX_USERNAME="$1" - export LIBEUFIN_SANDBOX_PASSWORD="$2" - export LIBEUFIN_SANDBOX_URL="http://localhost:18082" - echo "get_payto_uri currently not implemented" - exit 1 -# libeufin-cli sandbox demobank info --bank-account "$1" | jq --raw-output '.paytoUri' + export LIBEUFIN_SANDBOX_USERNAME="$1" + export LIBEUFIN_SANDBOX_PASSWORD="$2" + export LIBEUFIN_SANDBOX_URL="http://localhost:18082" + echo "get_payto_uri currently not implemented" + exit 1 + # libeufin-cli sandbox demobank info --bank-account "$1" | jq --raw-output '.paytoUri' } # Stop libeufin-bank (if running) -function stop_libeufin() -{ - if [ -f "${MY_TMP_DIR:-/}/libeufin-bank.pid" ] - then - PID=$(cat "${MY_TMP_DIR}/libeufin-bank.pid" 2> /dev/null) - echo -n "Stopping libeufin $PID... " - rm "${MY_TMP_DIR}/libeufin-bank.pid" - kill "$PID" 2> /dev/null || true - wait "$PID" || true - echo "DONE" - fi +function stop_libeufin() { + if [ -f "${MY_TMP_DIR:-/}/libeufin-bank.pid" ]; then + PID=$(cat "${MY_TMP_DIR}/libeufin-bank.pid" 2>/dev/null) + echo -n "Stopping libeufin $PID... " + rm "${MY_TMP_DIR}/libeufin-bank.pid" + kill "$PID" 2>/dev/null || true + wait "$PID" || true + echo "DONE" + fi } - -function launch_libeufin () { +function launch_libeufin() { + echo "launching libeufin-bank" libeufin-bank serve \ -c "$CONF" \ -L "INFO" \ - > "${MY_TMP_DIR}/libeufin-bank-stdout.log" \ - 2> "${MY_TMP_DIR}/libeufin-bank-stderr.log" & - echo $! > "${MY_TMP_DIR}/libeufin-bank.pid" + >"${MY_TMP_DIR}/libeufin-bank-stdout.log" \ + 2>"${MY_TMP_DIR}/libeufin-bank-stderr.log" & + echo $! >"${MY_TMP_DIR}/libeufin-bank.pid" + BANK_PORT=$(taler-config -c "$CONF" -s "libeufin-bank" -o "PORT") + BANK_URL="http://localhost:${BANK_PORT}/" + for n in $(seq 1 100); do + echo -n "." + sleep 0.2 + wget --timeout=1 \ + --tries=3 \ + --waitretry=0 \ + -a wget-bank-check.log \ + -o /dev/null \ + -O /dev/null \ + "${BANK_URL}config" || continue + OK="1" + break + done + if [ "1" != "$OK" ]; then + echo "Failed to launch libeufin-bank" + exit 1 + fi + echo "launched libeufin-bank" } |