-
Notifications
You must be signed in to change notification settings - Fork 325
/
Copy pathintegration.sh
executable file
·148 lines (128 loc) · 5.11 KB
/
integration.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
#!/usr/bin/env bash
set -eo pipefail
USAGE="$0 <test-executable> [args...]"
EXE=${1:?$USAGE}
TOP_LEVEL="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
DIR="${TOP_LEVEL}/services"
PARENT_PID=$$
rm -f /tmp/integration.* # remove previous temp files, if any
EXIT_STATUS_LOCATION=$(mktemp "/tmp/integration.XXXXXXXXXXX")
echo 1 >"${EXIT_STATUS_LOCATION}"
function kill_all() {
# kill the process tree of the PARENT_PID
kill -9 -${PARENT_PID} &> /dev/null
}
function list_descendants () {
local children
children="$(pgrep -P "$1")"
for pid in $children
do
list_descendants "$pid"
done
echo "$children"
}
function kill_gracefully() {
pkill "gundeck|brig|galley|cargohold|cannon|spar|nginz"
sleep 1
kill $(list_descendants "$PARENT_PID") &> /dev/null
}
trap "kill_gracefully; kill_all" INT TERM ERR
function check_prerequisites() {
if ! ( nc -z 127.0.0.1 9042 \
&& nc -z 127.0.0.1 9200 \
&& nc -z 127.0.0.1 6379 ); then
echo "Databases not up. Maybe run 'deploy/dockerephemeral/run.sh' in a separate terminal first?"; exit 1;
fi
if [ ! -f "${TOP_LEVEL}/dist/brig" ] \
&& [ ! -f "${TOP_LEVEL}/dist/galley" ] \
&& [ ! -f "${TOP_LEVEL}/dist/cannon" ] \
&& [ ! -f "${TOP_LEVEL}/dist/gundeck" ] \
&& [ ! -f "${TOP_LEVEL}/dist/cargohold" ] \
&& [ ! -f "${TOP_LEVEL}/dist/spar" ]; then
echo "Not all services are compiled. How about you run 'cd ${TOP_LEVEL} && make' first?"; exit 1;
fi
}
blue=6
green=10
orange=3
yellow=11
purpleish=13
if [[ $INTEGRATION_USE_REAL_AWS -eq 1 ]]; then
echo 'Attempting to run integration tests using real AWS services!'
[ -z "$AWS_REGION" ] && echo "Need to set AWS_REGION in your environment" && exit 1;
[ -z "$AWS_ACCESS_KEY_ID" ] && echo "Need to set AWS_ACCESS_KEY_ID in your environment" && exit 1;
[ -z "$AWS_SECRET_ACCESS_KEY" ] && echo "Need to set AWS_SECRET_ACCESS_KEY in your environment" && exit 1;
"${TOP_LEVEL}"/services/gen-aws-conf.sh
integration_file_extension='-aws.yaml'
else
# brig,gundeck,galley use the amazonka library's 'Discover', which expects AWS credentials
# even if those are not used/can be dummy values with the fake sqs/ses/etc containers used
# (see deploy/dockerephemeral/docker-compose.yaml )
echo 'Running tests using mocked AWS services'
export AWS_REGION=eu-west-1
export AWS_ACCESS_KEY_ID=dummykey
export AWS_SECRET_ACCESS_KEY=dummysecret
integration_file_extension='.yaml'
fi
function run() {
service=$1
instance=$2
colour=$3
# Check if we're on a Mac
if [[ "$OSTYPE" == "darwin"* ]]; then
# Mac sed uses '-l' to set line-by-line buffering
UNBUFFERED=-l
# Test if sed supports buffer settings. GNU sed does, busybox does not.
elif sed -u '' </dev/null >/dev/null 2>&1; then
UNBUFFERED=-u
else
echo -e "\n\nWARNING: log output is buffered and may not show on your screen!\n\n"
UNBUFFERED=''
fi
( ( cd "${DIR}/${service}" && "${TOP_LEVEL}/dist/${service}" -c "${service}${instance}.integration${integration_file_extension}" ) || kill_all) \
| sed ${UNBUFFERED} -e "s/^/$(tput setaf ${colour})[${service}] /" -e "s/$/$(tput sgr0)/" &
}
check_prerequisites
run brig "" ${green}
run galley "" ${yellow}
run gundeck "" ${blue}
run cannon "" ${orange}
run cannon "2" ${orange}
run cargohold "" ${purpleish}
run spar "" ${orange}
function run_nginz() {
colour=$1
# For nix we dont need LD_LIBRARY_PATH; we link agaiinterpolationnst libzauth directly.
# nix-build will put a symlink to ./result with the nginx artifact
if which nix-build; then
nginz=$(nix-build "${TOP_LEVEL}/nix" -A nginz --no-out-link )
(cd ${NGINZ_WORK_DIR} && ${nginz}/bin/nginx -p ${NGINZ_WORK_DIR} -c ${NGINZ_WORK_DIR}/conf/nginz/nginx.conf -g 'daemon off;' || kill_all) \
| sed -e "s/^/$(tput setaf ${colour})[nginz] /" -e "s/$/$(tput sgr0)/" &
else
prefix=$([ -w /usr/local ] && echo /usr/local || echo "${HOME}/.wire-dev")
(cd ${NGINZ_WORK_DIR} && LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${prefix}/lib/ ${TOP_LEVEL}/dist/nginx -p ${NGINZ_WORK_DIR} -c ${NGINZ_WORK_DIR}/conf/nginz/nginx.conf -g 'daemon off;' || kill_all) \
| sed -e "s/^/$(tput setaf ${colour})[nginz] /" -e "s/$/$(tput sgr0)/" &
fi
}
NGINZ_PORT=""
if [[ $INTEGRATION_USE_NGINZ -eq 1 ]]; then
NGINZ_PORT=8080
# Note: for integration tests involving nginz,
# nginz and brig must share the same zauth public/private keys
export NGINZ_WORK_DIR="$TOP_LEVEL/services/nginz/integration-test"
run_nginz ${purpleish}
fi
# the ports are copied from ./integration.yaml
while [ "$all_services_are_up" == "" ]; do
export all_services_are_up="1"
for port in $(seq 8082 8086) 8088 $NGINZ_PORT; do
( curl --write-out '%{http_code}' --silent --output /dev/null http://localhost:"$port"/i/status \
| grep -q '^20[04]' ) \
|| export all_services_are_up=""
done
sleep 1
done
echo "all services are up!"
( ${EXE} "${@:2}" && echo 0 > "${EXIT_STATUS_LOCATION}" && kill_gracefully ) || kill_gracefully &
wait
exit $(<"${EXIT_STATUS_LOCATION}")