aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2020-05-08 11:53:17 -0300
committerTorsten Grote <t@grobox.de>2020-05-08 11:53:58 -0300
commit1cf48054c47d9562876b5f021dc398b050b959fd (patch)
tree237a7380d55eb9532bf069f2179098d6f40c8e92
parent8056c7fb62ceb8de3171d13fd48d44bbdc43645c (diff)
Add test for retries
-rw-r--r--integrationtests/common.sh30
-rwxr-xr-xintegrationtests/test-base.sh3
-rwxr-xr-xintegrationtests/test-double-link.sh3
-rwxr-xr-xintegrationtests/test-double-spend.sh3
-rwxr-xr-xintegrationtests/test-refund.sh3
-rwxr-xr-xintegrationtests/test-retries.sh45
-rwxr-xr-xintegrationtests/test-tip.sh3
7 files changed, 71 insertions, 19 deletions
diff --git a/integrationtests/common.sh b/integrationtests/common.sh
index 8036b825b..57dc1a863 100644
--- a/integrationtests/common.sh
+++ b/integrationtests/common.sh
@@ -109,8 +109,7 @@ function wait_for_services() {
echo -n "."
sleep 0.2
OK=0
- # bank
- wget http://localhost:8082/ -o /dev/null -O /dev/null >/dev/null || continue
+ wget "$BANK_URL" -o /dev/null -O /dev/null >/dev/null || continue
OK=1
break
done
@@ -119,12 +118,9 @@ function wait_for_services() {
echo -n "."
sleep 0.1
OK=0
- # exchange
- wget http://localhost:8081/ -o /dev/null -O /dev/null >/dev/null || continue
- # merchant
- wget http://localhost:9966/ -o /dev/null -O /dev/null >/dev/null || continue
- # Auditor
- wget http://localhost:8083/ -o /dev/null -O /dev/null >/dev/null || continue
+ wget "$EXCHANGE_URL" -o /dev/null -O /dev/null >/dev/null || continue
+ wget "$MERCHANT_URL" -o /dev/null -O /dev/null >/dev/null || continue
+ wget "$AUDITOR_URL" -o /dev/null -O /dev/null >/dev/null || continue
OK=1
break
done
@@ -142,6 +138,17 @@ function normal_start_and_wait() {
wait_for_services
}
+# provide the service URL as first parameter
+function wait_for_service() {
+ for _ in $(seq 1 50); do
+ echo -n "."
+ sleep 0.1
+ wget "$1" -o /dev/null -O /dev/null >/dev/null || continue
+ echo " DONE"
+ break
+ done
+}
+
function shutdown_services() {
echo "Shutting down services"
jobs -p | xargs --no-run-if-empty kill || true
@@ -164,6 +171,11 @@ function exit_skip() {
}
function exit_error() {
- echo "Error: $1"
+ echo "\033[0;31mError: $1\033[0m"
exit 1
}
+
+function exit_success() {
+ echo -e "\033[0;32mSUCCESS \o/\033[0m"
+ exit 0
+}
diff --git a/integrationtests/test-base.sh b/integrationtests/test-base.sh
index 32187dd24..676ba7fb7 100755
--- a/integrationtests/test-base.sh
+++ b/integrationtests/test-base.sh
@@ -10,5 +10,4 @@ normal_start_and_wait "base"
echo "Running wallet"
taler-wallet-cli testing integrationtest -e "$EXCHANGE_URL" -m "$MERCHANT_URL" -b "$BANK_URL"
-echo "SUCCESS"
-exit 0
+exit_success
diff --git a/integrationtests/test-double-link.sh b/integrationtests/test-double-link.sh
index 62c152734..ee4af891a 100755
--- a/integrationtests/test-double-link.sh
+++ b/integrationtests/test-double-link.sh
@@ -16,5 +16,4 @@ echo "Trying to pay what was paid already should throw error"
taler-wallet-cli --wallet-db=$WALLET_DB --no-throttle handle-uri --yes "$PAY_URI" 2>&1 | grep -q "already paid" || exit_error "not reporting already paid"
echo "Already paid properly detected"
-echo "SUCCESS"
-exit 0
+exit_success
diff --git a/integrationtests/test-double-spend.sh b/integrationtests/test-double-spend.sh
index 6edf22a2c..5987ad494 100755
--- a/integrationtests/test-double-spend.sh
+++ b/integrationtests/test-double-spend.sh
@@ -21,5 +21,4 @@ echo "Try to double-spend"
# "exchange_reply: { hint: 'insufficient funds', code: 1200 }
taler-wallet-cli --wallet-db="$WALLET_DB" testing test-pay -m "$MERCHANT_URL" -k sandbox -a "TESTKUDOS:9.5" -s "foo"
-echo "SUCCESS"
-exit 0
+exit_success
diff --git a/integrationtests/test-refund.sh b/integrationtests/test-refund.sh
index 40dc65f57..d4193dbb7 100755
--- a/integrationtests/test-refund.sh
+++ b/integrationtests/test-refund.sh
@@ -20,5 +20,4 @@ echo -n "Balance after first refund: "
taler-wallet-cli --wallet-db="$WALLET_DB" balance 2>>"$LOG"
# TODO how to test second refund for same purchase?
-echo "SUCCESS"
-exit 0
+exit_success
diff --git a/integrationtests/test-retries.sh b/integrationtests/test-retries.sh
new file mode 100755
index 000000000..01bfa5774
--- /dev/null
+++ b/integrationtests/test-retries.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+# Script to check that the wallet retries operations when services are not reachable
+
+source "common.sh"
+normal_start_and_wait "retries"
+
+# TODO try withdrawal when bank is down
+
+echo "Withdraw TESTKUDOS"
+taler-wallet-cli --wallet-db="$WALLET_DB" --no-throttle testing withdraw -e "$EXCHANGE_URL" -b "$BANK_URL" -a "TESTKUDOS:10" 2>>"$LOG" >>"$LOG"
+echo -n "Balance after withdrawal: "
+taler-wallet-cli --wallet-db="$WALLET_DB" balance 2>>"$LOG"
+echo "Getting pay taler:// Uri"
+PAY_URI=$(taler-wallet-cli testing gen-pay-uri -m "$MERCHANT_URL" -k sandbox -a "TESTKUDOS:1" -s "foo" | grep -E -o 'taler://.*')
+echo "Trying to pay with exchange down, will fail"
+kill "$EXCHANGE_PID" && sleep 1
+ps -p "$EXCHANGE_PID" >"$LOG" && exit_error "exchange still alive"
+taler-wallet-cli --wallet-db="$WALLET_DB" --no-throttle handle-uri --yes "$PAY_URI" 2>>"$LOG" >>"$LOG" && exit_error "could pay with exchange down"
+echo "Re-launching exchange"
+taler-exchange-httpd -c "$CONF" 2>taler-exchange-httpd.log &
+EXCHANGE_PID=$!
+echo -n "Wait for exchange to start"
+wait_for_service "$EXCHANGE_URL"
+echo "Retrying operations with exchange up"
+taler-wallet-cli --wallet-db="$WALLET_DB" run-until-done 2>>"$LOG" >>"$LOG"
+echo -n "Balance after re-tried payment: "
+taler-wallet-cli --wallet-db="$WALLET_DB" balance 2>>"$LOG"
+
+echo "Getting pay taler:// Uri"
+PAY_URI=$(taler-wallet-cli testing gen-pay-uri -m "$MERCHANT_URL" -k sandbox -a "TESTKUDOS:1" -s "foo" | grep -E -o 'taler://.*')
+echo "Trying to pay with merchant down, will fail"
+kill "$MERCHANT_PID" && sleep 1
+ps -p "$MERCHANT_PID" >"$LOG" && exit_error "merchant still alive"
+taler-wallet-cli --wallet-db="$WALLET_DB" --no-throttle handle-uri --yes "$PAY_URI" 2>>"$LOG" >>"$LOG" && exit_error "could pay with merchant down"
+echo "Re-launching merchant"
+taler-merchant-httpd -c "$CONF" -L INFO 2>taler-merchant-httpd.log &
+MERCHANT_PID=$!
+echo -n "Wait for merchant to start"
+wait_for_service "$MERCHANT_URL"
+echo "Retrying payment with merchant up"
+taler-wallet-cli --wallet-db="$WALLET_DB" --no-throttle handle-uri --yes "$PAY_URI" 2>>"$LOG" >>"$LOG"
+echo -n "Balance after re-tried payment: "
+taler-wallet-cli --wallet-db="$WALLET_DB" balance 2>>"$LOG"
+
+exit_success
diff --git a/integrationtests/test-tip.sh b/integrationtests/test-tip.sh
index 1a0ea2817..8bdcc6ef3 100755
--- a/integrationtests/test-tip.sh
+++ b/integrationtests/test-tip.sh
@@ -15,5 +15,4 @@ taler-wallet-cli --wallet-db="$WALLET_DB" run-until-done 2>>"$LOG" >>"$LOG"
echo -n "Balance after first tip: "
taler-wallet-cli --wallet-db="$WALLET_DB" balance 2>>"$LOG"
-echo "SUCCESS"
-exit 0
+exit_success