forked from open-telemetry/opentelemetry-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.bash
executable file
·110 lines (93 loc) · 2.44 KB
/
run.bash
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
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0
#/bin/bash
# This script set up how to run Tracetest and which test files
# be executed
set -e
# Availalble services to test
ALL_SERVICES=("ad" "cart" "currency" "checkoutservice" "frontend" "email" "paymentservice" "productcatalogservice" "recommendationservice" "shipping")
## Script variables
# Will contain the list of services to test
chosen_services=()
# Array to hold process IDs
pids=()
# Array to hold exit codes
exit_codes=()
## Script functions
check_if_tracetest_is_installed() {
if ! command -v tracetest &> /dev/null
then
echo "tracetest CLI could not be found"
exit -1
fi
}
create_env_file() {
cat << EOF > tracetesting-vars.yaml
type: VariableSet
spec:
id: tracetesting-vars
name: tracetesting-vars
values:
- key: AD_ADDR
value: $AD_ADDR
- key: CART_ADDR
value: $CART_ADDR
- key: CHECKOUT_SERVICE_ADDR
value: $CHECKOUT_SERVICE_ADDR
- key: CURRENCY_ADDR
value: $CURRENCY_ADDR
- key: EMAIL_ADDR
value: $EMAIL_ADDR
- key: FRONTEND_ADDR
value: $FRONTEND_ADDR
- key: PAYMENT_SERVICE_ADDR
value: $PAYMENT_SERVICE_ADDR
- key: PRODUCT_CATALOG_SERVICE_ADDR
value: $PRODUCT_CATALOG_SERVICE_ADDR
- key: RECOMMENDATION_SERVICE_ADDR
value: $RECOMMENDATION_SERVICE_ADDR
- key: SHIPPING_ADDR
value: $SHIPPING_ADDR
- key: KAFKA_SERVICE_ADDR
value: $KAFKA_SERVICE_ADDR
EOF
}
run_tracetest() {
service_name=$1
testsuite_file=./$service_name/all.yaml
tracetest --config ./cli-config.yml run testsuite --file $testsuite_file --vars ./tracetesting-vars.yaml &
pids+=($!)
}
## Script execution
while [[ $# -gt 0 ]]; do
chosen_services+=("$1")
shift
done
if [ ${#chosen_services[@]} -eq 0 ]; then
for service in "${ALL_SERVICES[@]}"; do
chosen_services+=("$service")
done
fi
check_if_tracetest_is_installed
create_env_file
echo "Starting tests..."
echo "Running trace-based tests for: ${chosen_services[*]} ..."
echo ""
for service in "${chosen_services[@]}"; do
run_tracetest $service
done
# Wait for processes to finish and capture their exit codes
for pid in "${pids[@]}"; do
wait $pid
exit_codes+=($?)
done
# Find the maximum exit code
max_exit_code=0
for code in "${exit_codes[@]}"; do
if [[ $code -gt $max_exit_code ]]; then
max_exit_code=$code
fi
done
echo ""
echo "Tests done! Exit code: $max_exit_code"
exit $max_exit_code