forked from dotmesh-io/dotmesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·71 lines (62 loc) · 2.26 KB
/
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
#!/usr/bin/env bash
# Run with arguments you want to pass to test.
# Example: ./test.sh -run TestTwoSingleNodeClusters
if which timeout >/dev/null; then
export TIMEOUT=timeout
elif which gtimeout >/dev/null; then
export TIMEOUT=gtimeout
else
echo "Unable to locate timeout or gtimeout commands (try brew/apt install coreutils)"
exit 1
fi
if ! which uuidgen >/dev/null; then
echo "Unable to locate uuidgen command"
exit 1
fi
# Generate a unique test id, which we pass to go test and it puts it in the
# container-unique /dotmesh-test-pools dir, so we can find them later and clean
# them up in case the 'go test' itself times out.
export GO_TEST_ID=$(uuidgen |cut -d "-" -f 1)
cleanup() {
local REASON="$1"
echo "Cleaning up due to $REASON"
# Outside of the -xe/pipefail, after the timeout has fired, do belt-and-braces cleanup.
if [ "$DOTMESH_TEST_CLEANUP" == "always" ]; then
# https://stackoverflow.com/questions/29438045/how-to-match-nothing-if-a-file-name-glob-has-no-matches
shopt -s nullglob
for SCRIPT in /dotmesh-test-pools/*${GO_TEST_ID}*/cleanup-actions.*; do set -x; sudo bash $SCRIPT; done
fi
echo "Finished cleaning up"
}
shutdown() {
local SIGNAL="$1"
# Remove the handler now it's happened once
trap - $SIGNAL
cleanup "signal $SIGNAL"
}
trap 'shutdown SIGTERM' SIGTERM
trap 'shutdown SIGINT' SIGINT
trap 'shutdown SIGQUIT' SIGQUIT
trap 'shutdown SIGHUP' SIGHUP
trap 'shutdown SIGPIPE' SIGPIPE
(
set -xe
set -o pipefail
export PATH=/usr/local/go/bin:$PATH
export DISABLE_LOG_AGGREGATION=1
cd tests
if [ -n "$DOTMESH_TEST_TIMEOUT" ]; then
echo "======================================================"
echo "Running with $DOTMESH_TEST_TIMEOUT timeout: go test $@"
echo "======================================================"
($TIMEOUT $DOTMESH_TEST_TIMEOUT sudo -E `which go` test -v "$@" 2>&1 ) | ts
else
echo "======================================================"
echo "Running without timeout: go test $@"
echo "======================================================"
(sudo -E `which go` test -v "$@" 2>&1 ) | ts
fi
)
TEST_EXIT_CODE=$?
cleanup "test terminated with retval=$RETVAL"
exit $TEST_EXIT_CODE