-
Notifications
You must be signed in to change notification settings - Fork 82
/
run-integration-tests
executable file
·170 lines (142 loc) · 3.94 KB
/
run-integration-tests
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
#!/bin/bash
#
# Run integration tests for ringpop-go.
#
# Integration tests for different cluster sizes are run in parallel. Success
# output is suppressed and only the failures are shown.
#
# 2015-01-14
#
set -eo pipefail
declare project_root="${0%/*}/.."
declare ringpop_common_dir="${0%/*}/ringpop-common"
declare tap_filter="${ringpop_common_dir}/test/tap-filter.js"
declare test_cluster_sizes="1 2 3 4 5 10"
declare test_result=
declare temp_dir="$(mktemp -d)"
# Check node is installed
if ! type node &>/dev/null; then
echo "ERROR: missing 'node'" >&2
exit 1
fi
#
# Same as builtin wait, but return code is the number of background processes
# that exited with a non-zero code.
#
wait-all() {
local -i failed=0
# We need to explicitly loop through all background jobs and specify the
# pids to `wait`, otherwise `wait` doesn't return the exit code.
for pid in $(jobs -p); do
wait $pid || let "failed+=1"
done
return $failed
}
#
# Echos and runs the specified command.
#
run() {
echo "+ $@" >&2
"$@"
}
#
# Copy stdin to stdout but prefix each line with the specified string.
#
prefix() {
local _prefix=
[ -n "$1" ] && _prefix="[$1] "
while IFS= read -r -t 30 line; do
echo "${_prefix}${line}"
done
}
#
# Clones or updates the ringpop-common repository.
#
fetch-ringpop-common() {
if [ ! -e "$ringpop_common_dir" ]; then
run git clone --depth=1 https://github.com/uber/ringpop-common.git "$ringpop_common_dir"
fi
run cd "$ringpop_common_dir"
#run git checkout master
run git pull
run cd - >/dev/null
run cd "${ringpop_common_dir}/test"
run npm install >/dev/null
run cd - >/dev/null
# Check tap-filter exists in ringpop-common. It is required to filter output
# correctly to stdout/stderr
if ! [ -x "$tap_filter" ]; then
echo "ERROR: missing 'test/tap-filter.js' in ringpop-common" >&2
exit 1
fi
}
#
# Build the testpop binary.
#
build-testpop() {
cd "$project_root"
run make testpop
}
#
# Run test with specified cluster size.
#
# $1: cluster size
#
run-test-for-cluster-size() {
local cluster_size=$1
local err=0
local output_file="${temp_dir}/${cluster_size}.out"
# Run the tests and buffer the output to a log file. We'll display it later
# if the test fails. This avoids interleaving of output to the terminal
# when tests are running in parallel.
node "${ringpop_common_dir}/test/it-tests.js" \
-s "[$1]" "${project_root}/testpop" &>$output_file || err=$?
if [ $PIPESTATUS -gt 0 ]; then
echo "ERROR: Test errored for cluster size $cluster_size" | \
prefix "test-errors-${cluster_size}" >&2
return 1
fi
if [ $err -ne 0 ]; then
# If the test failed, print a message and display the failures
{
echo "FAIL: Test failed for cluster size $cluster_size"
# Output the test data through tap-filter, which discards success
# info unless -v is specified.
cat "$output_file" |$tap_filter
} | prefix "test-errors-${cluster_size}" >&2
return 1
fi
}
#
# Run the integration tests against the testpop binary.
#
run-tests() {
for cluster_size in $test_cluster_sizes; do
echo "Spawning test for cluster size ${cluster_size}..." |prefix "test-runner"
run-test-for-cluster-size $cluster_size &
done
{
echo
echo "Waiting for tests to complete."
echo
echo "To monitor test output (verbose), run:"
echo " tail -f ${temp_dir}/*.out"
echo
} \
|prefix "test-runner"
wait-all
}
# Fetch and build in parallel
{ fetch-ringpop-common 2>&1|prefix "fetch ringpop-common"; } &
{ build-testpop 2>&1|prefix "build testpop"; } &
wait-all
# Run integration tests
run-tests
test_result=$?
if [ $test_result -eq 0 ]; then
echo "Tests passed"
rm -rf "$temp_dir"
else
echo "Tests failed" >&2
fi
exit $test_result