forked from couchbase/goxdcr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_unit_tests.sh
executable file
·151 lines (139 loc) · 3.33 KB
/
run_unit_tests.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
#!/bin/bash
# Copyright 2017-Present Couchbase, Inc.
#
# Use of this software is governed by the Business Source License included in
# the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that
# file, in accordance with the Business Source License, use of this software
# will be governed by the Apache License, Version 2.0, included in the file
# licenses/APL2.txt.
function man() {
echo "Usage: $0 [-d <path>] [-l]" 1>&2
echo ""
echo "d: Root directory absolute path of goxdcr (default is pwd)" 1>&2
echo "h: Help" 1>&2
echo "l: Run all tests including lengthy tests (which are not run by default)" 1>&2
exit 1
}
declare ROOT_DIR
declare runAllTests
while getopts "d:lh" opt; do
case "${opt}" in
l)
runAllTests=1
;;
d)
ROOT_DIR=${OPTARG}
;;
h)
man
;;
*)
man
;;
esac
done
if [[ -z "$ROOT_DIR" ]]; then
ROOT_DIR=$(pwd)
fi
if [[ ${ROOT_DIR:0:1} == "." ]]; then
echo "Cannot pass in relative path for -d"
man
fi
declare -a DIRS_WITH_UT
declare -a outputs
DIRS_WITH_UT=(
base
base/filter
crMeta
backfill_manager
factory
peerToPeer
pipeline
pipeline_svc
pipeline_manager
parts
metadata
metadata_svc
service_impl
streamApiWatcher
utils
)
function killAllBgOnExit {
for job in $(jobs -p); do
kill $job
done
}
trap killAllBgOnExit EXIT
pids=""
totalTasks=0
for directory in ${DIRS_WITH_UT[@]}; do
cd ${ROOT_DIR}/${directory}
fileFriendlyFileName=$(echo "${directory}" | sed 's/\//_/g')
if [[ -z "$runAllTests" ]]; then
go test -short >/tmp/${fileFriendlyFileName}.out 2>&1 &
else
go test >/tmp/${fileFriendlyFileName}.out 2>&1 &
fi
lastPid="$!"
echo "Test $directory with background PID $lastPid"
outputs[$lastPid]="/tmp/${fileFriendlyFileName}.out"
pids+=" $lastPid"
totalTasks=$(($totalTasks + 1))
pcreTestsFound=false
for testFile in $(ls *_test.go); do
if (($(head $testFile | grep -c "build pcre") > 0)); then
pcreTestsFound=true
break
fi
done
if [[ "$pcreTestsFound" == "true" ]]; then
fileFriendlyFileName=$(echo "${directory}" | sed 's/\//_/g')
if [[ -z "$runAllTests" ]]; then
go test -short -tags=pcre >/tmp/${fileFriendlyFileName}_pcre.out 2>&1 &
else
go test -tags=pcre >/tmp/${fileFriendlyFileName}_pcre.out 2>&1 &
fi
lastPid2="$!"
echo "Test $directory PCRE tests with background PID $lastPid2"
pids+=" $lastPid2"
outputs[$lastPid2]="/tmp/${fileFriendlyFileName}_pcre.out"
totalTasks=$(($totalTasks + 1))
fi
done
# Do a pretty print progress bar
# https://stackoverflow.com/questions/12498304/using-bash-to-display-a-progress-indicator
echo "Total tasks running: $totalTasks"
count=0
failedCnt=0
pstr="[=======================================================================]"
while (($count < $totalTasks)); do
replacementPids=""
for p in $pids; do
kill -0 $p >/dev/null 2>&1
if (($? == 0)); then
# process is still running
replacementPids+=" $p"
else
# process is done running
count=$(($count + 1))
wait $p
if (($? > 0)); then
echo ""
echo "PID $p failed unit test"
failedCnt=$(($failedCnt + 1))
else
rm ${outputs[p]}
unset outputs[p]
fi
fi
done
pids=$replacementPids
pd=$(($count * 73 / $totalTasks))
printf "\r%3d.%1d%% %.${pd}s" $(($count * 100 / $totalTasks)) $((($count * 1000 / $totalTasks) % 10)) $pstr
sleep 0.5
done
if (($failedCnt > 0)); then
echo ""
echo "See ${outputs[@]} for failed test outputs"
exit 1
fi