-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
entrypoint
executable file
·59 lines (45 loc) · 1.89 KB
/
entrypoint
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
#!/usr/bin/env bash
# Runs tests for a specific product
set -x
# get this scripts directory
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
cd "$SCRIPT_DIR"/../ || exit 1
# Arguments needed
# ARGS=${ARGS:=} any extra args for go test
# SUITE=${SUITE:=} the suite of tests you want to run
# TEST_NAME=${TEST_NAME:=} The specific test to run
if [ -z "${SUITE}" ]; then
echo "SUITE is not set. You likely need to set the TEST_SUITE env var in your workflow. Exiting."
exit 1
fi
# Helpful for debugging
pwd
ls -la
# run the tests
./${SUITE}.test -test.v -test.count 1 ${ARGS} -test.run ^${TEST_NAME}$
exit_code=$?
echo "Test exit code: ${exit_code}"
# Check if the test did not pass (non-zero exit code)
if [ $exit_code -ne 0 ]; then
# 3 is the code for an interrupted test, we only want to restart the test when the test is interrupted and in a state
# that it can recover from. Otherwise we mark the test as "passed" as far as K8s is concerned so it doesn't restart it.
if [ $exit_code -eq 3 ]; then
echo "Test was interrupted, exiting with 1 exit code to trigger K8s to restart"
exit 1 # Exiting with non-zero status to trigger pod restart
else
echo "Test either panicked or had some sort of failure. We're exiting with a non-zero exit code so that K8s doesn't restart the pod."
echo "TEST_FAILED"
fi
fi
# Sleep for the amount of time provided by the POST_RUN_SLEEP env var
upload_to_slack() {
curl -F file=@$1 -F "initial_comment=$2" -F channels=${SLACK_CHANNEL} -H "Authorization: Bearer ${SLACK_API_KEY}" https://slack.com/api/files.upload
}
if [ -n "${UPLOAD_CPU_PROFILE}" ]; then
upload_to_slack profile.out "CPU Profile for ${TEST_NAME}"
fi
if [ -n "${UPLOAD_MEM_PROFILE}" ]; then
upload_to_slack memprofile.out "MEM Profile for ${TEST_NAME}"
fi
echo "Exiting with 0 exit code as test is either completed, or failed and cannot be restarted"
exit 0