generated from bmstu-rsoi/lab3-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-script.sh
executable file
·72 lines (54 loc) · 1.48 KB
/
test-script.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
#!/usr/bin/env bash
set -e
variant=${1:-${VARIANT}}
service=${2:-${SERVICE_NAME}}
port=${3:-${PORT_NUMBER}}
path=$(dirname "$0")
timed() {
end=$(date +%s)
dt=$(("$end" - $1))
dd=$(("$dt" / 86400))
dt2=$(("$dt" - 86400 * "$dd"))
dh=$(("$dt2" / 3600))
dt3=$(("$dt2" - 3600 * "$dh"))
dm=$(("$dt3" / 60))
ds=$(("$dt3" - 60 * "$dm"))
LC_NUMERIC=C printf "\nTotal runtime: %02d min %02d seconds\n" "$dm" "$ds"
}
success() {
newman run \
--delay-request=100 \
--folder=success \
--export-environment "$variant"/postman/environment.json \
--environment "$variant"/postman/environment.json \
"$variant"/postman/collection.json
}
step() {
local step=$1
[[ $((step % 2)) -eq 0 ]] && operation="start" || operation="stop"
printf "=== Step %d: %s %s ===\n" "$step" "$operation" "$service"
docker compose "$operation" "$service"
if [[ "$operation" == "start" ]]; then
"$path"/wait-for.sh -t 120 "http://localhost:$port/manage/health" -- echo "Host localhost:$port is active"
fi
newman run \
--delay-request=100 \
--folder=step"$step" \
--export-environment "$variant"/postman/environment.json \
--environment "$variant"/postman/environment.json \
"$variant"/postman/collection.json
printf "=== Step %d completed ===\n" "$step"
}
start=$(date +%s)
trap 'timed $start' EXIT
printf "=== Start test scenario ===\n"
# success execute
success
# stop service
step 1
# start service
step 2
# stop service
step 3
# start service
step 4