-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathtest-docker.sh
executable file
·175 lines (154 loc) · 4.43 KB
/
test-docker.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
set -e
export TERM=xterm-256color
PROJECT_ROOT="$(pwd)"
TEST_ROOT="${PROJECT_ROOT}/tests/integration"
TIMEOUT_SECONDS=180
RUN_ID="$(date +%y%m%d_%H%M%S)"
LOG_DIR="${PROJECT_ROOT}/logs/${RUN_ID}"
while [ -d "$LOG_DIR" ]; do
tmp_id="$((tmp_id + 1))"
new_run="${RUN_ID}_${tmp_id}"
LOG_DIR="${PROJECT_ROOT}/logs/${RUN_ID}"
done
RUN_ID=''
mkdir -p "${PROJECT_ROOT}/logs"
mkdir "$LOG_DIR"
BUILD_LOG="${LOG_DIR}/build.log"
RUN_LOG="${LOG_DIR}/run_master.log"
TEST_LOG="${LOG_DIR}/test.log"
WORKER_LOG_DIR="/tmp/jasminegraph"
rm -rf "${WORKER_LOG_DIR}"
mkdir -p "${WORKER_LOG_DIR}"
force_remove() {
local files=("$@")
for f in "${files[@]}"; do
rm -rf "$f" &>/dev/null || sudo rm -rf "$f"
done
}
stop_and_remove_containers() {
if [ ! -z "$(docker ps -a -q)" ]; then
docker ps -a -q | xargs docker rm -f &>/dev/null
else
echo "No containers to stop and remove."
fi
docker run -v '/tmp/jasminegraph:/tmp/jasminegraph' --entrypoint /bin/bash jasminegraph:test -c 'rm -rf /tmp/jasminegraph/*' || echo 'Not removing existing tmp logs'
if [ ! -z "$(docker ps -a -q)" ]; then
docker ps -a -q | xargs docker rm -f &>/dev/null
fi
}
build_and_run_docker() {
stop_and_remove_containers
cd "$PROJECT_ROOT"
docker build -t jasminegraph:test . |& tee "$BUILD_LOG"
build_status="${PIPESTATUS[0]}"
if [ "$build_status" != '0' ]; then
set +ex
echo
echo -e '\e[31;1mERROR: Build failed\e[0m'
rm -rf "${TEST_ROOT}/env"
exit "$build_status"
fi
docker compose -f "${TEST_ROOT}/docker-compose.yml" up >"$RUN_LOG" 2>&1 &
}
stop_tests_on_failure() {
set +ex
failCnt=0
while true; do
if nc -zvn 127.0.0.1 7777 &>/dev/null; then
failCnt=0
else
if [ "$failCnt" = 0 ]; then
failCnt=1
else
sleep 5
if pgrep python3 &>/dev/null; then
echo "Master has stopped. Stopping tests..."
pkill python3
fi
break
fi
fi
sleep 5
done
}
cd "$TEST_ROOT"
force_remove env
cp -r env_init env
cd "$PROJECT_ROOT"
build_and_run_docker
# sleep until server starts listening
cur_timestamp="$(date +%s)"
end_timestamp="$((cur_timestamp + TIMEOUT_SECONDS))"
while ! nc -zvn 127.0.0.1 7777 &>/dev/null; do
if [ "$(date +%s)" -gt "$end_timestamp" ]; then
set +ex
echo "JasmineGraph is not listening"
echo "Build log:"
cat "$BUILD_LOG"
echo -e '\n\e[33;1mMASTER LOG:\e[0m'
cat "$RUN_LOG"
force_remove "${TEST_ROOT}/env"
stop_and_remove_containers
exit 1
fi
sleep .5
done
sleep 2
stop_tests_on_failure &
timeout "$TIMEOUT_SECONDS" python3 -u "${TEST_ROOT}/test.py" |& tee "$TEST_LOG"
exit_code="${PIPESTATUS[0]}"
set +ex
if [ "$exit_code" = '124' ]; then
echo
echo -e '\e[31;1mERROR: Test Timeout\e[0m'
echo
fi
print_log() {
sed -e 's/^integration-jasminegraph-1 | //g' \
-e 's/ \[logger\]//g' \
-e 's/ \[info\] / ['$'\033''[32minfo'$'\033''[0m] /g' \
-e 's/ \[warn\] / ['$'\033''[1;33mwarn'$'\033''[0m] /g' \
-e 's/ \[error\] / ['$'\033''[1;31merror'$'\033''[0m] /g' \
-e 's/ \[INFO\] / ['$'\033''[32mINFO'$'\033''[0m] /g' \
-e 's/ \[WARNING\] / ['$'\033''[1;33mWARNING'$'\033''[0m] /g' "$1"
}
cd "$TEST_ROOT"
for d in "${WORKER_LOG_DIR}"/worker_*; do
echo
worker_name="$(basename ${d})"
cp -r "$d" "${LOG_DIR}/${worker_name}"
done
cd "$LOG_DIR"
if [ "$exit_code" != '0' ]; then
echo
echo -e '\e[33;1mMaster log:\e[0m'
print_log "$RUN_LOG"
for d in worker_*; do
cd "${LOG_DIR}/${d}"
echo
echo -e '\e[33;1m'"${d}"' log:\e[0m'
print_log worker.log
for f in merge_*.log; do
echo
echo -e '\e[33;1m'"${d} ${f::-4}"' log:\e[0m'
print_log "$f"
done
for f in fl_client_*.log; do
echo
echo -e '\e[33;1m'"${d} ${f::-4}"' log:\e[0m'
print_log "$f"
done
for f in fl_server_*.log; do
echo
echo -e '\e[33;1m'"${d} ${f::-4}"' log:\e[0m'
print_log "$f"
done
done
fi
stop_and_remove_containers
force_remove "${TEST_ROOT}/env" "${WORKER_LOG_DIR}"
if [ "$exit_code" = '0' ]; then
docker tag jasminegraph:test jasminegraph:latest
fi
exit "$exit_code"