Skip to content
Permalink
Browse files

[RAFT] add test scripts

- init_test.sh
  prepare test
- run_all.sh
  run all tests
- test files for indivisual case
  test_tx.sh
  test_up_down.sh
  test_leader_change.sh
  test_slow_follower.sh
  test_slow_leader.sh
  test_syncer_crash.sh
  test_member.sh
  • Loading branch information...
everjs78 committed Jun 4, 2019
1 parent cced63d commit 77c887318325a54f2c2ce5c6412a17d9ecc39cbc
Showing with 2,063 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +9 −0 consensus/impl/raftv2/test/README.txt
  3. +60 −0 consensus/impl/raftv2/test/add_member.sh
  4. +128 −0 consensus/impl/raftv2/test/aergoconf-gen.sh
  5. +16 −0 consensus/impl/raftv2/test/chk.sh
  6. +24 −0 consensus/impl/raftv2/test/clean.sh
  7. +34 −0 consensus/impl/raftv2/test/commit_tx.sh
  8. +1 −0 consensus/impl/raftv2/test/config/11001.id
  9. BIN consensus/impl/raftv2/test/config/11001.key
  10. +1 −0 consensus/impl/raftv2/test/config/11001.pub
  11. +68 −0 consensus/impl/raftv2/test/config/11001.toml
  12. +1 −0 consensus/impl/raftv2/test/config/11002.id
  13. +1 −0 consensus/impl/raftv2/test/config/11002.key
  14. +2 −0 consensus/impl/raftv2/test/config/11002.pub
  15. +1 −0 consensus/impl/raftv2/test/config/11003.id
  16. BIN consensus/impl/raftv2/test/config/11003.key
  17. +1 −0 consensus/impl/raftv2/test/config/11003.pub
  18. +1 −0 consensus/impl/raftv2/test/config/11004.id
  19. +1 −0 consensus/impl/raftv2/test/config/11004.key
  20. +1 −0 consensus/impl/raftv2/test/config/11004.pub
  21. +1 −0 consensus/impl/raftv2/test/config/11005.id
  22. +1 −0 consensus/impl/raftv2/test/config/11005.key
  23. BIN consensus/impl/raftv2/test/config/11005.pub
  24. +1 −0 consensus/impl/raftv2/test/config/11006.id
  25. +1 −0 consensus/impl/raftv2/test/config/11006.key
  26. +1 −0 consensus/impl/raftv2/test/config/11006.pub
  27. +1 −0 consensus/impl/raftv2/test/config/11007.id
  28. +1 −0 consensus/impl/raftv2/test/config/11007.key
  29. +2 −0 consensus/impl/raftv2/test/config/11007.pub
  30. +52 −0 consensus/impl/raftv2/test/config/BP11001.toml
  31. +52 −0 consensus/impl/raftv2/test/config/BP11002.toml
  32. +52 −0 consensus/impl/raftv2/test/config/BP11003.toml
  33. +54 −0 consensus/impl/raftv2/test/config/BP11004.toml
  34. +55 −0 consensus/impl/raftv2/test/config/BP11005.toml
  35. +54 −0 consensus/impl/raftv2/test/config/BP11006.toml
  36. +55 −0 consensus/impl/raftv2/test/config/BP11007.toml
  37. +15 −0 consensus/impl/raftv2/test/config/_genesis.json
  38. +22 −0 consensus/impl/raftv2/test/config/arglog.toml
  39. +26 −0 consensus/impl/raftv2/test/do_sed.sh
  40. +38 −0 consensus/impl/raftv2/test/generate_tx.sh
  41. +78 −0 consensus/impl/raftv2/test/init_genesis.sh
  42. +48 −0 consensus/impl/raftv2/test/init_test.sh
  43. +24 −0 consensus/impl/raftv2/test/kill_svr.sh
  44. +40 −0 consensus/impl/raftv2/test/make_node.sh
  45. +26 −0 consensus/impl/raftv2/test/make_tx_internal.sh
  46. +31 −0 consensus/impl/raftv2/test/rm_member.sh
  47. +30 −0 consensus/impl/raftv2/test/run_all.sh
  48. +21 −0 consensus/impl/raftv2/test/run_svr.sh
  49. +20 −0 consensus/impl/raftv2/test/run_tx.sh
  50. +58 −0 consensus/impl/raftv2/test/seed_tx.sh
  51. +28 −0 consensus/impl/raftv2/test/set_test_env.sh
  52. +35 −0 consensus/impl/raftv2/test/sign_tx.sh
  53. +412 −0 consensus/impl/raftv2/test/test_common.sh
  54. +63 −0 consensus/impl/raftv2/test/test_join_backup.sh
  55. +49 −0 consensus/impl/raftv2/test/test_leader_change.sh
  56. +71 −0 consensus/impl/raftv2/test/test_member.sh
  57. +32 −0 consensus/impl/raftv2/test/test_slow_follower.sh
  58. +24 −0 consensus/impl/raftv2/test/test_slow_leader.sh
  59. +3 −0 consensus/impl/raftv2/test/test_syncer.sh
  60. +64 −0 consensus/impl/raftv2/test/test_syncer_crash.sh
  61. +29 −0 consensus/impl/raftv2/test/test_tx.sh
  62. +41 −0 consensus/impl/raftv2/test/test_up_down.sh
@@ -22,3 +22,5 @@ Gopkg.lock
# developer workspace specific
/conf

# consensus test directory
/consensus/**/tmp/
@@ -0,0 +1,9 @@
To run all tests, run_all.sh.

* requirment
1. add bin directory of aergo to $PATH
scripts assume aergosvr, aergocli to be called

* run
1. run ./init_test.sh
2. run ./run_all.sh or run indivisual test scripts such as test_leader_change.sh
@@ -0,0 +1,60 @@
#!/usr/bin/env bash
source test_common.sh

addnode=$1

if [ "$1" = "" ] || [[ "$1" != aergo* ]] ;then
echo "use:add_member.sh aergo4|aergo5|aergo6|aergo7 usebackup"
exit 1
fi

usebackup=0
if [ "$2" == "usebackup" ]; then
usebackup=1

echo "try to join $addnode with backup"
fi

declare -A ports svrports svrname httpports peerids

leader=$(aergocli -p 10001 blockchain | jq .ConsensusInfo.Status.Leader)
leader=${leader//\"/}
if [[ $leader != aergo* ]]; then
echo "leader not exist"
exit 1
fi

leaderport=${ports[$leader]}

echo "leader=$leader, port=$leaderport"

echo "aergocli -p $leaderport cluster add --name \"$addnode\" --url \"http://127.0.0.1:${httpports[$addnode]}\" --peerid \"${peerids[$addnode]}\""

aergocli -p $leaderport cluster add --name "$addnode" --url "http://127.0.0.1:${httpports[$addnode]}" --peerid "${peerids[$addnode]}"

echo "add Done"

mySvrport=${svrports[$addnode]}
mySvrName=${svrname[$addnode]}
myConfig="$mySvrName.toml"


for i in {1..5}; do
echo ${svrname["aergo$i"]}
done
echo "new svr=$mySvrport $mySvrName, $myConfig"

sleep 5

echo "Get config of added member"
echo "cp $TEST_RAFT_INSTANCE_CONF/$myConfig $TEST_RAFT_INSTANCE"
cp $TEST_RAFT_INSTANCE_CONF/$myConfig $TEST_RAFT_INSTANCE

if [ "$usebackup" == "0" ]; then
echo "init genesis for $mySvrName"
init_genesis.sh $mySvrName > /dev/null 2>&1
else
echo "join using backup: $mySvrName"
do_sed.sh $myConfig "joinusingbackup=false" "joinusingbackup=true" "/"
run_svr.sh $mySvrName
fi
@@ -0,0 +1,128 @@
#!/bin/bash
# Usage: aergoconf-gen.sh 10001 tmpl.toml 5
#
# gen_start, gen_end: XXXX.toml 을 생성할 범위
# peer_start, peer_end : peer로 들어갈 node의 범위

# pkgen 명령 위치(path)를 적어줄 것
pkgen="aergocli keygen"

# pkey는 항상 0~22까지를 생성. 존재하면 생성 skip

if [ $# != 3 ]; then
echo "Usage: $0 <starting port:10001~> <template> <max>"
exit
fi


port0=$1
tmpl_file=$2
max=$3
gen_start=0
gen_end=$(($max - 1))

echo "Generate aergo config file from $tmpl_file, from $port0 to ($port0 + $max - 1)"

function gen_ids() {
for ((i=1; i <= $max; i++))
do
out[i]=${!i}
done

echo ${out[*]} | sed -e 's= =\,\\n=g' -e 's=\/=\\/=g'
}

# gen_peers selfno startno endno ( 0 <= *no < $max)
function gen_peers() {
self=$1
start=$2
end=$3

j=0
for ((i=$start; i <= $end; i++))
do
if [ $i != $self ]; then
out[j]=${peer[$i]}
j=$(($j + 1))
fi

done

echo ${out[*]} | sed -e 's= =\,=g' -e 's=\/=\\/=g'
}



# generate id[]
for((i=0; i < $max; ++i))
do
rpcport=$(($port0 + $i))
rpc[i]=$rpcport

profileport=$(($port0 + $i + 100))
prof[i]=$profileport

restport=$(($port0 + $i + 200))
rest[i]=$restport
p2pport=$(($port0 + $i + 1000))
p2p[i]=$p2pport

httpport=$(($port0 + $i + 3000))
http[i]=$httpport

pk[i]=${p2pport}.key
pk_id[i]=${p2pport}.id

ofile[i]=BP${p2pport}.toml

# check if file exist
if [ ! -e ${pk[i]} ]; then
echo "${pk[i]}: $pkgen $p2pport"
$pkgen $p2pport
fi

tmpid=$(cat ${p2pport}.id)
id[i]="\"${tmpid}\""
peer[i]="\"/ip4/127.0.0.1/tcp/${p2pport}/p2p/${tmpid}\""
#echo "peer[ $i ]= ${peer[i]}"

raftname[i]="aergo$(($i + 1))"
raftbp[i]="{name=\"${raftname[i]}\",url=\"http://127.0.0.1:$httpport\",p2pid=\"${tmpid}\"}"
echo "raftbp[$i]=${raftbp[i]}"
done

#ids=$(gen_ids ${id[*]})
#echo $ids
raftbps=$(gen_ids ${raftbp[*]})
echo "raftbps=$raftbps"

#for((i=0; i < $max; ++i))

for((i=$gen_start; i <= $gen_end; ++i))
do
peers=$(gen_peers ${i} $gen_start $gen_end)

# echo "${peers}"

echo "s=_home_=$PWD/${p2p[i]}=g"
echo "s/_rpc_/${rpc[i]}/g"
echo "s/_p2p_/${p2p[i]}/g"
echo "s/_peer_/${peers}/g"
echo "s/_pk_/${pk[i]}/g"
echo "s/_http_/${http[i]}/g"
echo "s/_raftbps_/$raftbps/g"


sed -e "s=_home_=$PWD/${p2p[i]}=g" \
-e "s=_data_=$PWD/data/${p2p[i]}=g" \
-e "s/_rest_/${rest[i]}/g" \
-e "s/_prof_/${prof[i]}/g" \
-e "s/_rpc_/${rpc[i]}/g" \
-e "s/_p2p_/${p2p[i]}/g" \
-e "s/_peer_/${peers}/g" \
-e "s/_http_/${http[i]}/g" \
-e "s/_raftname_/${raftname[i]}/g" \
-e "s/_raftbps_/${raftbps}/g" \
-e "s/_pk_/${pk[i]}/g" $tmpl_file >${ofile[i]}
done
echo $(pwd)
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
source set_test_env.sh

pushd $TEST_RAFT_INSTANCE

while [ 1 ]; do
for file in BP*.toml; do
echo "file=$file"
port=$(grep 'netserviceport' $file | awk '{ print $3 }')
aergocli -p $port blockchain
done
sleep 2
echo "---------------"
done

popd
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
# usage: clean [all]
if [ $# -gt 1 ]; then
echo "usage: clean [all]"
exit
fi

function rmall() {
echo "rmall"
#rm -rf *.id *.key *.pub BP*.toml
rm -rf *.log
}

killall -9 aergosvr
rm -rf data* genesis*
#rm *.log

# make empty args to string
if [ "$1" = "all" ]; then
rmall
fi



@@ -0,0 +1,34 @@
#!/bin/bash

echo "=========== commit tx for all accounts =============="
# 어떤 클라이언트
port=$1
TARGET_DIR=$2

if [ "$port" = "" ];then
port=10001
fi

if [ "$2" = "" ]; then
TARGET_DIR=$port
fi

echo "targetdir=$TARGET_DIR"

# 계정 & 트랜잭션 삭제
echo "start"
aergocli -p ${port} blockchain

# 트랜잭션 컨펌
for file in $TARGET_DIR/**/*.tmp; do
echo $file " confirm .."

if [ "$file" = ".tmp" ]; then
continue;
fi

aergocli -p ${port} committx --jsontxpath ${file}
done

echo "end"
aergocli -p ${port} blockchain
@@ -0,0 +1 @@
16Uiu2HAkvaAMCHkd9hZ6hQkdDLKoXP4eLJSqkMF1YqkSNy5v9SVn
Binary file not shown.
@@ -0,0 +1 @@
!i Er�0pOϻӥ�娲�U^���84�
@@ -0,0 +1,68 @@
# aergo TOML Configuration File (https://github.com/toml-lang/toml)
# base configurations
datadir = "/Users/everjs/work/integrated_test/raft_member/server/data"
dbtype = "badgerdb"
enableprofile = false
profileport = 6060
personal = true
authdir = "/Users/everjs/work/integrated_test/raft_member/server/auth"

[rpc]
netserviceaddr = "127.0.0.1"
netserviceport = 7845
netservicetrace = false
nstls = false
nscert = ""
nskey = ""
nsallowcors = false

[p2p]
# Set address and port to which the inbound peers connect, and don't set loopback address or private network unless used in local network
netprotocoladdr = ""
netprotocolport = 7846
npbindaddr = ""
npbindport = -1
# TLS and certificate is not applied in alpha release.
nptls = false
npcert = ""
# Set file path of key file
npkey = ""
npaddpeers = [
]
npdiscoverpeers = true
npmaxpeers = "100"
nppeerpool = "100"
npexposeself = true
npusepolaris= true
npaddpolarises = [
]

[polaris]
allowprivate = false
genesisfile = ""

[blockchain]
# blockchain configurations
maxblocksize = 1048576
coinbaseaccount = ""
maxanchorcount = "20"
verifiercount = "2"
forceresetheight = "0"

[mempool]
showmetrics = false
enablefadeout = false
fadeoutperiod = 12
verifiers = 4
dumpfilepath = "/Users/everjs/work/integrated_test/raft_member/server/mempool.dump"

[consensus]
enablebp = false
blockinterval = 1

[monitor]
protocol = ""
endpoint = ""

[account]
unlocktimeout = "60"
@@ -0,0 +1 @@
16Uiu2HAmJqEp9f9WAbzFxkLrnHnW4EuUDM69xkCDPF26HmNCsib6
@@ -0,0 +1 @@
 ��T*�]���G_��������q�� ��!3
@@ -0,0 +1,2 @@
![�H{��+��s
�������k�^iR�;�
@@ -0,0 +1 @@
16Uiu2HAmA2ysmFxoQ37sk1Zk2sMrPysqTmwYAFrACyf3LtP3gxpJ
Binary file not shown.
@@ -0,0 +1 @@
!�..��aD����n�H�l�u����"u7�[�
@@ -0,0 +1 @@
16Uiu2HAmQti7HLHC9rXqkeABtauv2YsCPG3Uo1WLqbXmbuxpbjmF
@@ -0,0 +1 @@
 ��J����t��I!:|�Ox�j�Vi||���ے
@@ -0,0 +1 @@
!����IPg�G̒z��V�>��/�'������
@@ -0,0 +1 @@
16Uiu2HAmRm9iKQdfLpeTZUW1YA2TDWabLskzNpizSiFd9nLo6mPy
@@ -0,0 +1 @@
 kR9�����p�8�j�a{��ŴA~+
Binary file not shown.
@@ -0,0 +1 @@
16Uiu2HAm1jAjmQxCCrtgfqGCzikc1XVZrv27uBb2PsvRPy9ieMC9
@@ -0,0 +1 @@
 Z��+E�c���6���>�n.�KF!Wݎ
@@ -0,0 +1 @@
!]��#�&C!.ώ��d'��G��6���q�g"�<�

0 comments on commit 77c8873

Please sign in to comment.
You can’t perform that action at this time.