-
Notifications
You must be signed in to change notification settings - Fork 16
/
auto_test.sh
executable file
·169 lines (139 loc) · 3.66 KB
/
auto_test.sh
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
#!/bin/bash
iters=1
verbose=0
log=auto_test.log
s=1
utilFail=0
integration=0
testname=""
tag=""
override=0
timeout=0
rebuild=0
OPTIND=1
if [[ "${#EYWA_HOME}" -eq 0 ]]; then
echo 'Warn: EYWA_HOME is not set. Using current directory as EYWA_HOME.'
export EYWA_HOME=$PWD
fi
read -r -d '' USAGE << EOM
Usage:
-h show this helper message.
-? show this helper message.
-f stop util fail. default: disabled
-v enable verbose mode. default: disabled
-n max iteration number, 0 means infinite. default: 1
-s sleep seconds between iterations. default: 1 second
-l log output. default: auto_test.log
-i integration tests. default: disabled
-t tests tag. default: none
-T tests name. default: none
-o override the log in each of the test iteration
-b rebuild binary before running integration tests. default: not rebuild
EOM
while getopts "h?vobifn:s:l:t:T:O:" opt; do
case "$opt" in
h|\?)
echo "$USAGE"
exit 0
;;
v) verbose=1
;;
f) utilFail=1
;;
i) integration=1
tag=integration
;;
l) log=$OPTARG
;;
s) s=$OPTARG
;;
n) iters=$OPTARG
;;
t) tag=$OPTARG
;;
T) testname=$OPTARG
;;
o) override=1
;;
O) timeout=$OPTARG
;;
b) rebuild=1
;;
esac
done
shift $((OPTIND-1))
if [[ $utilFail -eq 1 ]]; then
verbose=1
fi
if [[ $iters -eq 0 && $utilFail -eq 1 ]]; then
echo "WARN: Test will run infinitely. Are you sure? [Y/N]:"
read c
if [ "$c" != "Y" ]; then
exit 0;
fi
fi
params="$([[ $verbose != 1 ]] || echo '-v' ) \
$([[ $timeout -gt 0 ]] && echo '-timeout' ${timeout}s) \
$([[ ${#tag} -gt 0 ]] && echo '-tags' ${tag}) \
$([[ ${#testname} -gt 0 ]] && echo '--run' \
${testname}) ./..."
serverpid=""
if [[ $integration -eq 1 ]]; then
if [[ $rebuild -eq 1 ]]; then
echo "Rebuilding eywa binary..."
go build -a
fi
echo "Running test setup..."
"$EYWA_HOME"/eywa migrate -conf="$EYWA_HOME/configs/eywa_test.yml"
curl -XDELETE 127.0.0.1:9200/channels.* > /dev/null 2>&1
curl -XDELETE 127.0.0.1:9200/_template/* > /dev/null 2>&1
"$EYWA_HOME"/eywa setup_es -conf="$EYWA_HOME/configs/eywa_test.yml"
echo "Starting test server..."
"$EYWA_HOME"/eywa serve -conf="$EYWA_HOME/configs/eywa_test.yml" &
sleep 5
serverpid="$(cat "${EYWA_HOME}"/tmp/pids/eywa_test.pid)"
if [[ ${#serverpid} -eq 0 ]]; then
echo 'Error: test server was not started within 5 seconds'
exit 1
fi
echo "Test server started..."
fi
fail=1
iter=0
echo '' > $log
echo "Starting Tests..."
while [[ $utilFail -eq 1 && $iters -eq 0 && $fail -eq 1 ]] || [[ $utilFail -eq 1 && $iters -gt 0 && $fail -eq 1 && $iter -lt $iters ]] || [[ $utilFail -ne 1 && $iters -eq 0 ]] || [[ $utilFail -ne 1 && $iters -gt 0 && $iter -lt $iters ]]; do
if [[ $override -eq 1 ]]; then
echo '' > $log
fi
echo "TEST RUN [$iter] ========================================================================" >> $log
go test $params >> $log 2>&1
grep FAIL $log
fail=$?
iter=$((iter+1))
sleep $s
done
echo "Tests are done..."
echo "Test results are in $log. iterations=$iter"
if [[ ${#serverpid} -gt 0 ]]; then
echo "Shutting down test server..."
kill -INT $serverpid
ps auxww | grep $serverpid | grep -v grep >/dev/null 2>&1
running=$?
waitIter=0
while [[ $running -eq 0 ]]; do
echo "Trying ${waitIter} time."
if [[ $waitIter -gt 10 ]]; then
echo 'Error: server failed to shutdown.'
exit 1
fi
sleep 1
ps auxww | grep $serverpid | grep -v grep >/dev/null 2>&1
running=$?
waitIter=$((waitIter+1))
done
echo "Test server is shutdown..."
fi
if [[ $fail -ne 1 ]]; then
exit 1
fi