summaryrefslogtreecommitdiff
path: root/test/scripts/e2e.sh
blob: 571d1178190bc79177575cbb3a2d68a83b80cc21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env bash
echo "######################################################################"
echo "  E2E Tests"
echo "######################################################################"
set -e

# Suppress telemetry reporting for tests
export ALGOTEST=1

SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )"

SRCROOT="$(pwd -P)"

export CHANNEL=master

HELP="Usage: $0 [-v] [-u]
Script for running go-algorand e2e tests
Requires:
    * pip
    * python 3
    * go
Options:
    -c        Channel of build you are building binaries with this script
    -n        Run tests without building binaries (Binaries are expected in PATH)
"
NO_BUILD=false
while getopts ":c:nhi" opt; do
  case ${opt} in
    c ) CHANNEL=$OPTARG
      ;;
    n ) NO_BUILD=true
        GO_TEST_ARGS="-norace"
      ;;
    h ) echo "${HELP}"
        exit 0
	;;
    i ) echo "  Interactive session"
	echo "######################################################################"
	INTERACTIVE=true
	;;
    \? ) echo "${HELP}"
        exit 2
      ;;
  esac
done

# export TEMPDIR=$(mktemp -d 2>/dev/null || mktemp -d -t "tmp")
TEST_RUN_ID=$(${SCRIPT_PATH}/testrunid.py)
export TEMPDIR=${SRCROOT}/tmp/out/e2e/${TEST_RUN_ID}
echo "Test output can be found in ${TEMPDIR}"

function cleanup() {
  echo "Cleaning up temp dir."

  rm -rf "${TEMPDIR}"

  if ! ${NO_BUILD} ; then
      rm -rf ${PKG_ROOT}
  fi
}

# Cleanup files created during tests.
trap cleanup EXIT

# ARM64 has an unoptimized scrypt() which can cause tests to timeout.
# Run kmd with scrypt() configured to run less secure and fast to go through the motions for test.
# thus, on those platforms we launch kmd with unsafe_scrypt = true to speed up the tests.
RUN_KMD_WITH_UNSAFE_SCRYPT=""
PLATFORM_ARCHTYPE=$("${SRCROOT}/scripts/archtype.sh")

echo "ARCHTYPE:    ${PLATFORM_ARCHTYPE}"
if [[ "${PLATFORM_ARCHTYPE}" = arm* ]]; then
    RUN_KMD_WITH_UNSAFE_SCRYPT="--unsafe_scrypt"
fi

echo "RUN_KMD_WITH_UNSAFE_SCRYPT = ${RUN_KMD_WITH_UNSAFE_SCRYPT}"

export BINDIR=${TEMPDIR}/bin
export DATADIR=${TEMPDIR}/data

function reset_dirs() {
    rm -rf ${BINDIR}
    rm -rf ${DATADIR}
    mkdir -p ${BINDIR}
    mkdir -p ${DATADIR}
}

# $1 - Message
LAST_DURATION=$SECONDS
function duration() {
  ELAPSED=$((SECONDS - $LAST_DURATION))
  printf "Duration: '%s' - %02dh:%02dm:%02ds\n" "$1" $(($ELAPSED/3600)) $(($ELAPSED%3600/60)) $(($ELAPSED%60))
  LAST_DURATION=$SECONDS
}

#----------------------
# Start E2E tests by installing the current build after killing all instances
reset_dirs
echo Killing all instances and installing current build

pkill -u "$(whoami)" -x algod || true

if ! ${NO_BUILD} ; then
    ./scripts/local_install.sh -c ${CHANNEL} -p ${BINDIR} -d ${DATADIR}
    export PATH=${BINDIR}:${PATH}
fi

# check our install
algod -v
goal -v

./test/scripts/goal_subcommand_sanity.sh "${TEMPDIR}"

export GOPATH=$(go env GOPATH)

# Change current directory to test/scripts so we can just use ./test.sh to exec.
cd "${SCRIPT_PATH}"

if [ -z "$E2E_TEST_FILTER" ] || [ "$E2E_TEST_FILTER" == "SCRIPTS" ]; then
    ./timeout 200 ./e2e_basic_start_stop.sh
    duration "e2e_basic_start_stop.sh"

    python3 -m venv "${TEMPDIR}/ve"
    . "${TEMPDIR}/ve/bin/activate"
    "${TEMPDIR}/ve/bin/pip3" install --upgrade pip
    "${TEMPDIR}/ve/bin/pip3" install --upgrade py-algorand-sdk cryptography
    duration "e2e client setup"

    if [ $INTERACTIVE ]; then
	echo "********** READY **********"
	echo "The test environment is now set. Run the tests using the following command on a different terminal after setting the path."
	echo ""
	echo "export VIRTUAL_ENV=\"${TEMPDIR}/ve\""
	echo "export PATH=\"\$VIRTUAL_ENV/bin:\$PATH\""
	echo ""
	echo "${TEMPDIR}/ve/bin/python3" test/scripts/e2e_client_runner.py ${RUN_KMD_WITH_UNSAFE_SCRYPT} "$SRCROOT"/test/scripts/e2e_subs/SCRIPT_FILE_NAME
	echo ""
	echo "Press enter to shut down the test environment..."
	read a
	echo -n "deactivating..."
	deactivate
	echo "done"
	exit
    fi

    "${TEMPDIR}/ve/bin/python3" e2e_client_runner.py ${RUN_KMD_WITH_UNSAFE_SCRYPT} "$SRCROOT"/test/scripts/e2e_subs/*.{sh,py}
    duration "parallel client runner"

    for vdir in "$SRCROOT"/test/scripts/e2e_subs/v??; do
        "${TEMPDIR}/ve/bin/python3" e2e_client_runner.py ${RUN_KMD_WITH_UNSAFE_SCRYPT} --version "$(basename "$vdir")" "$vdir"/*.sh
    done
    duration "vdir client runners"

    for script in "$SRCROOT"/test/scripts/e2e_subs/serial/*; do
        "${TEMPDIR}/ve/bin/python3" e2e_client_runner.py ${RUN_KMD_WITH_UNSAFE_SCRYPT} $script
    done

    deactivate
    duration "serial client runners"
fi # if E2E_TEST_FILTER == "" or == "SCRIPTS"

if [ -z "$E2E_TEST_FILTER" ] || [ "$E2E_TEST_FILTER" == "GO" ]; then
    # Export our root temp folder as 'TESTDIR' for tests to use as their root test folder
    # This allows us to clean up everything with our rm -rf trap.
    mkdir "${TEMPDIR}/go"
    export TESTDIR=${TEMPDIR}/go
    export TESTDATADIR=${SRCROOT}/test/testdata
    export SRCROOT=${SRCROOT}

    ./e2e_go_tests.sh ${GO_TEST_ARGS}
    duration "go integration tests"
fi # if E2E_TEST_FILTER == "" or == "GO"

if [ -z "$E2E_TEST_FILTER" ] || [ "$E2E_TEST_FILTER" == "EXPECT" ]; then
    # Export our root temp folder as 'TESTDIR' for tests to use as their root test folder
    # This allows us to clean up everything with our rm -rf trap.
    mkdir "${TEMPDIR}/expect"
    export TESTDIR=${TEMPDIR}/expect
    export TESTDATADIR=${SRCROOT}/test/testdata
    export SRCROOT=${SRCROOT}

    ./e2e_go_tests.sh -e ${GO_TEST_ARGS}
    duration "expect tests"
fi # if E2E_TEST_FILTER == "" or == "EXPECT"

echo "----------------------------------------------------------------------"
echo "  DONE: E2E"
echo "----------------------------------------------------------------------"