aboutsummaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
authorAntoine A <>2021-12-15 15:04:00 +0100
committerAntoine A <>2021-12-15 15:04:00 +0100
commite21dbc6255dad5c30de11a9622bb4c02af68a4b0 (patch)
tree7af466950c1850cafb09db04ff319154ce27ee17 /script
parentd0a58b074225b5c277253b3aae4bcd52fa7714c3 (diff)
downloaddepolymerization-e21dbc6255dad5c30de11a9622bb4c02af68a4b0.tar.gz
depolymerization-e21dbc6255dad5c30de11a9622bb4c02af68a4b0.tar.bz2
depolymerization-e21dbc6255dad5c30de11a9622bb4c02af68a4b0.zip
Learn how concurrency work in postgresql the hard way
Diffstat (limited to 'script')
-rw-r--r--script/setup.sh24
-rw-r--r--script/test_btc_fail.sh0
-rw-r--r--script/test_btc_stress.sh61
-rw-r--r--script/test_gateway.sh22
4 files changed, 75 insertions, 32 deletions
diff --git a/script/setup.sh b/script/setup.sh
index c4ec9ba..8a67102 100644
--- a/script/setup.sh
+++ b/script/setup.sh
@@ -80,12 +80,12 @@ function btc_wire() {
target/debug/btc-wire $BTC_DIR &> btc_wire.log &
}
-# Start multiple btc_wire in parralel in fail mode
+# Start multiple btc_wire in parallel
function stressed_btc_wire() {
cargo build --bin btc-wire &> /dev/null
target/debug/btc-wire $BTC_DIR &> btc_wire.log &
- target/debug/btc-wire $BTC_DIR &>> btc_wire.log &
- target/debug/btc-wire $BTC_DIR &>> btc_wire.log &
+ target/debug/btc-wire $BTC_DIR &> btc_wire1.log &
+ target/debug/btc-wire $BTC_DIR &> btc_wire2.log &
}
# Start wire_gateway in test mode
@@ -97,4 +97,22 @@ function gateway() {
sleep 0.2
curl -s $BANK_ENDPOINT -o /dev/null && break
done
+}
+
+# Check history endpoint request return a specific amount of transactions of specific amounts
+# usage: check_delta endpoint nb_txs amount_sequence
+function check_delta() {
+ ALL=`curl -s ${BANK_ENDPOINT}history/$1`
+ for n in `$2`; do
+ if ! `echo $ALL | grep BTC:0.0000$n > /dev/null`; then
+ echo -n " missing tx with amount: BTC:0.0000$n"
+ return 1
+ fi
+ done
+ NB=`echo $ALL | grep -o BTC | wc -l`
+ EXPECTED=`$2 | wc -w`
+ if [ "$EXPECTED" != "$NB" ]; then
+ echo -n " expected: $EXPECTED txs found $NB"
+ return 1
+ fi
} \ No newline at end of file
diff --git a/script/test_btc_fail.sh b/script/test_btc_fail.sh
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/script/test_btc_fail.sh
diff --git a/script/test_btc_stress.sh b/script/test_btc_stress.sh
index 832a1d0..f19ca2c 100644
--- a/script/test_btc_stress.sh
+++ b/script/test_btc_stress.sh
@@ -1,5 +1,7 @@
#!/bin/bash
+# Test btc_wire behavior
+
set -eu
# Cleanup to run whenever we exit
@@ -16,7 +18,7 @@ trap cleanup EXIT
source "${BASH_SOURCE%/*}/setup.sh"
-echo "---- Setup -----"
+echo "---- Setup stressed -----"
echo "Load config file"
load_config
echo "Reset database"
@@ -31,24 +33,52 @@ echo "Start gateway"
gateway
echo ""
+SEQ="seq 10 99"
+
+function check() {
+ check_delta "$1?delta=-100" "$SEQ"
+}
+
echo "----- Generate many transactions -----"
echo -n "Making wire transfer to exchange:"
-for n in `seq 10 99`; do
+for n in `$SEQ`; do
btc-wire-cli -d $BTC_DIR transfer 0.0000$n
mine_btc # Mine transactions
done
next_btc # Trigger btc_wire
-next_btc # Trigger watcher twice, never sure
-check_balance 9.99438310 1.00490500
echo " OK"
echo -n "Requesting exchange incoming transaction list:"
-ALL=`curl -s ${BANK_ENDPOINT}history/incoming?delta=-100`
-test `echo $ALL | grep -o BTC | wc -l` -eq 90 || exit 1;
-for n in `seq 10 99`; do
- echo $ALL | grep BTC:0.0000$n > /dev/null || exit 1;
+check incoming
+echo " OK"
+
+echo -n "Check balance:"
+check_balance 9.99438310 1.00490500
+echo " OK"
+
+echo -n "Making wire transfer from exchange:"
+for n in `$SEQ`; do
+ taler-exchange-wire-gateway-client \
+ -b $BANK_ENDPOINT \
+ -C payto://bitcoin/$CLIENT \
+ -a BTC:0.0000$n > /dev/null
done
+next_btc # Mine transactions
+sleep 10
+next_btc # Trigger watcher twice, never sure
+sleep 10
+next_btc # Trigger watcher twice, never sure
+sleep 10
+next_btc # Trigger watcher twice, never sure
+echo " OK"
+
+echo -n "Requesting exchange outgoing transaction list:"
+check outgoing
+echo " OK"
+
+echo -n "Check balance:"
+check_balance 9.99928810 0.99981936
echo " OK"
echo "----- Recover DB -----"
@@ -59,11 +89,16 @@ next_btc # Trigger watcher
sleep 2
echo -n "Requesting exchange incoming transaction list:"
-ALL=`curl -s ${BANK_ENDPOINT}history/incoming?delta=-100`
-test `echo $ALL | grep -o BTC | wc -l` -eq 90 || exit 1;
-for n in `seq 10 99`; do
- echo $ALL | grep BTC:0.0000$n > /dev/null || exit 1;
-done
+check incoming
+echo " OK"
+
+echo -n "Requesting exchange outgoing transaction list:"
+check outgoing
+echo " OK"
+
+echo -n "Check balance:"
+# Balance should not have changed
+check_balance 9.99928810 0.99981936
echo " OK"
echo "All tests passed" \ No newline at end of file
diff --git a/script/test_gateway.sh b/script/test_gateway.sh
index 5d0e00a..1e4a4ab 100644
--- a/script/test_gateway.sh
+++ b/script/test_gateway.sh
@@ -93,24 +93,14 @@ echo ""
echo "----- History delta -----"
-# Check history endpoint request return a specific amount of transactions of specific amounts
-# usage: check_delta endpoint nb_txs amount_sequence
-function check_delta() {
- ALL=`curl -s ${BANK_ENDPOINT}history/$1`
- test `echo $ALL | grep -o BTC | wc -l` -eq $2 || return 1;
- for n in `$3`; do
- echo $ALL | grep BTC:0.0000$n > /dev/null || return 1;
- done
-}
-
for endpoint in incoming outgoing; do
echo -n "History $endpoint:"
- check_delta ${endpoint}?delta=-9 9 "seq 1 9" && echo -n " OK" || echo -n " Failed"
- check_delta ${endpoint}?delta=9 9 "seq 1 9" && echo -n " OK" || echo -n " Failed"
- check_delta ${endpoint}?delta=-4 4 "seq 6 9" && echo -n " OK" || echo -n " Failed"
- check_delta ${endpoint}?delta=4 4 "seq 1 4" && echo -n " OK" || echo -n " Failed"
- check_delta "${endpoint}?delta=-3&start=5" 3 "seq 2 4" && echo -n " OK" || echo -n " Failed"
- check_delta "${endpoint}?delta=3&start=4" 3 "seq 5 7" && echo -n " OK" || echo -n " Failed"
+ check_delta ${endpoint}?delta=-9 "seq 1 9" && echo -n " OK" || echo -n " Failed"
+ check_delta ${endpoint}?delta=9 "seq 1 9" && echo -n " OK" || echo -n " Failed"
+ check_delta ${endpoint}?delta=-4 "seq 6 9" && echo -n " OK" || echo -n " Failed"
+ check_delta ${endpoint}?delta=4 "seq 1 4" && echo -n " OK" || echo -n " Failed"
+ check_delta "${endpoint}?delta=-3&start=5" "seq 2 4" && echo -n " OK" || echo -n " Failed"
+ check_delta "${endpoint}?delta=3&start=4" "seq 5 7" && echo -n " OK" || echo -n " Failed"
echo ""
done