Skip to content

Commit

Permalink
Merge pull request #6 from evdzhurov/utt-test-automation
Browse files Browse the repository at this point in the history
Utt test automation
  • Loading branch information
evdzhurov authored May 16, 2022
2 parents 33064db + 328b496 commit 97c6ef0
Show file tree
Hide file tree
Showing 10 changed files with 324 additions and 48 deletions.
2 changes: 1 addition & 1 deletion tests/uttDemo/PaymentService/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ PaymentServiceParams setupParams(int argc, char** argv) {
}

/////////////////////////////////////////////////////////////////////////////////////////////////////
auto logger = logging::getLogger("uttdemo.payment-service");
auto logger = logging::getLogger("payment-service");

/////////////////////////////////////////////////////////////////////////////////////////////////////
ICommunication* setupCommunicationParams(ClientParams& cp) {
Expand Down
229 changes: 189 additions & 40 deletions tests/uttDemo/UTTClient/main.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/uttDemo/UTTReplica/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "UTTCommandsHandler.hpp"
#include "replica_state_sync_imp.hpp"
#include "block_metadata.hpp"
#include "SimpleBCStateTransfer.hpp"
//#include "SimpleBCStateTransfer.hpp"
#include "secrets_manager_plain.h"
#include "bftengine/ControlStateManager.hpp"
#include "messages/ReplicaRestartReadyMsg.hpp"
Expand Down
3 changes: 2 additions & 1 deletion tests/uttDemo/scripts/config/logging.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ log4cplus.appender.R.layout.ConversionPattern=%X{rid}|%d{%d-%m-%Y %H:%M:%S.%q}|%

# Don't log to console
log4cplus.rootLogger=INFO, R

log4cplus.logger.payment-service=WARN, R
log4cplus.logger.wallet=WARN, R
5 changes: 3 additions & 2 deletions tests/uttDemo/scripts/reset.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/bin/bash
echo ""
echo "Killing all services..."
killall utt_replica
killall payment_service
echo "Done."

echo ""
echo "Cleaning files..."
rm -rf logs/* core.* rocksdb/*
rm -rf logs/* core.* rocksdb/* automation/*
echo "Done."

78 changes: 78 additions & 0 deletions tests/uttDemo/scripts/runAutomation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash

set +x

if [[ -z $1 ]]; then
echo "Usage: specify the automation commands to be used."
exit 1
fi

# Reset the state
./reset.sh

# Start replicas and payment services (and keep them running in the background)
. startServices.sh

mkdir -p automation

# Summarize the initial state of each wallet
echo ""
echo "Gather the initial state of the system..."
WALLET_PIDS=()
for id in {1..9}
do
../UTTClient/utt_client -n config/net_localhost.txt -i $id -s automation/init_$id.txt > /dev/null &
WALLET_PIDS+=" $!"
done
echo "Waiting wallet pids (${WALLET_PIDS}) to finish..."
wait ${WALLET_PIDS}
echo "Done."

echo ""
echo "WalledId | LastBlockId | PublicBalance | UttBalance | UttBudget"
cat automation/init_*

# Export variables describing the initial state
NUM_WALLETS=9
INIT_BLOCK_ID=$(awk 'BEGIN {value=0} {if(NR==1) value=$2; else if(value != $2) value="error: inconsistent initial value"} END {print value}' automation/init_*)
INIT_PUBLIC_BALANCE=$(awk 'BEGIN {value=0} {if(NR==1) value=$3; else if(value != $3) value="error: inconsistent initial value"} END {print value}' automation/init_*)
INIT_UTT_BALANCE=$(awk 'BEGIN {value=0} {if(NR==1) value=$4; else if(value != $4) value="error: inconsistent initial value"} END {print value}' automation/init_*)
INIT_UTT_BUDGET=$(awk 'BEGIN {value=0} {if(NR==1) value=$5; else if(value != $5) value="error: inconsistent initial value"} END {print value}' automation/init_*)

# Run automation on each wallet
echo ""
echo "Run automation..."
WALLET_PIDS=()
for id in {1..9}
do
echo -e $1 | ../UTTClient/utt_client -n config/net_localhost.txt -i $id &> automation/run_$id.txt &
WALLET_PIDS+=" $!"
done
echo "Waiting wallet pids (${WALLET_PIDS}) to finish..."
wait ${WALLET_PIDS}
echo "Done."

# Summarize the final state of each wallet
echo ""
echo "Gather the final state of the system..."
WALLET_PIDS=()
for id in {1..9}
do
../UTTClient/utt_client -n config/net_localhost.txt -i $id -s automation/final_$id.txt > /dev/null &
WALLET_PIDS+=" $!"
done
echo "Waiting wallet pids (${WALLET_PIDS}) to finish..."
wait ${WALLET_PIDS}
echo "Done."

echo ""
echo "WalledId | LastBlockId | PublicBalance | UttBalance | UttBudget"
cat automation/final_*

# Stop replicas and payment services
. stopServices.sh

wait # Wait all services to terminate
echo ""
echo "Automation completed."

1 change: 1 addition & 0 deletions tests/uttDemo/scripts/startServices.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
echo ""
echo "Making sure no previous services are up..."
killall utt_replica
killall payment_service
Expand Down
5 changes: 2 additions & 3 deletions tests/uttDemo/scripts/stopServices.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash
echo ""
echo "Killing all services..."
killall utt_replica
killall payment_service

echo "Finished!"
killall payment_service
23 changes: 23 additions & 0 deletions tests/uttDemo/scripts/testRandomTransactions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

echo ""
echo "###############################################################"
echo "# This test concurrently runs randomized public and utt"
echo "# transafers between random wallets. At the end we check"
echo "# that the total public and utt balance remain the same."
echo "# You can obtain the random seeds from automation/run_ files."
echo "###############################################################"

# Each wallet executes random transfers and quits
. runAutomation.sh "random 50\nq"

# Total balances must be conserved
EXPECTED_TOTAL_PUBLIC_BALANCE=$((NUM_WALLETS * INIT_PUBLIC_BALANCE))
EXPECTED_TOTAL_UTT_BALANCE=$((NUM_WALLETS * INIT_UTT_BALANCE))

echo "Expected total public balance: ${EXPECTED_TOTAL_PUBLIC_BALANCE}"
echo "Expected total utt balance: ${EXPECTED_TOTAL_UTT_BALANCE}"

# Validate
awk -v x=${EXPECTED_TOTAL_PUBLIC_BALANCE} '{ sum += $3 } END {if(sum != x) print "Error: unexpected total public balance!",sum; else print "Total public balance Ok."}' automation/final_*
awk -v x=${EXPECTED_TOTAL_UTT_BALANCE} '{ sum += $4 } END {if(sum != x) print "Error: unexpected total UTT balance!",sum; else print "Total UTT balance Ok."}' automation/final_*
24 changes: 24 additions & 0 deletions tests/uttDemo/scripts/testWalletConcurrency.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

echo ""
echo "###########################################################"
echo "# This test concurrently runs deposits of \$1 for each"
echo "# wallet. At the end we check that all deposits have been"
echo "# made and that each wallet has the expected amount of"
echo "# additional public money added to its balance."
echo "###########################################################"

# Each wallet executes 150 additions of $1 to its balance (defined by the checkpoint command)
. runAutomation.sh "checkpoint\nq"

# We expect all deposits to succeed and that each wallet adds the expected
# value to its public balance
EXPECTED_BLOCK_ID=$((INIT_BLOCK_ID + NUM_WALLETS * 150))
EXPECTED_PUBLIC_BALANCE=$((INIT_PUBLIC_BALANCE + 150))

echo "Expected block id: ${EXPECTED_BLOCK_ID}"
echo "Expected public balance per wallet: ${EXPECTED_PUBLIC_BALANCE}"

# Validate
awk -v x=${EXPECTED_BLOCK_ID} 'BEGIN {err=0} $2 != x {print "Error: unexpected block id!",$0; err=1} END {if (!err) print "All block ids are Ok."}' automation/final_*
awk -v x=${EXPECTED_PUBLIC_BALANCE} 'BEGIN {err=0} $3 != x {print "Error: unexpected public balance!",$0; err=1} END {if (!err) print "All public balances are Ok."}' automation/final_*

0 comments on commit 97c6ef0

Please sign in to comment.