-
Notifications
You must be signed in to change notification settings - Fork 452
/
test-e2e
executable file
·182 lines (133 loc) · 4.53 KB
/
test-e2e
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
176
177
178
179
180
181
182
#!/usr/bin/env bash
set -ueo pipefail
cd "$(dirname "$0")"
server="../dist/toxiproxy-server"
state="started"
benchmark() {
go test -bench=.. ../test/e2e -v
}
cli() {
../dist/toxiproxy-cli "$@" 2>&1 | sed -e 's/^/[client] /'
}
wait_for_url() {
curl -s --retry-connrefused --retry 5 --retry-delay 2 --retry-max-time 30 \
--max-time 1 -L -I -X GET "${1}"
}
# Stop all background jobs on exit
function cleanup() {
echo -e "\n\n== Teardown: state=${state}"
pkill -15 -f "toxiproxy-server -proxy-metrics -runtime-metrics$"
pkill -15 -f "exe/endpoint$"
}
trap "cleanup" EXIT SIGINT SIGTERM
echo "= Toxiproxy E2E tests"
echo
echo "== Setup"
echo
echo "=== Starting Web service"
pkill -15 "toxiproxy-server" || true
pkill -15 -f "exe/endpoint$" || true
go run ../test/e2e/endpoint.go 2>&1 | sed -e 's/^/[web] /' &
echo "=== Starting Toxiproxy"
LOG_LEVEL=trace $server -proxy-metrics -runtime-metrics 2>&1 | sed -e 's/^/[toxiproxy] /' &
echo "=== Wait when services are available"
wait_for_url http://localhost:20002/test2
wait_for_url http://localhost:8474/version
echo "=== Test client to manipulate proxy"
cli -h http://localhost:8474 \
create -l localhost:20000 -u localhost:20002 shopify_http
cli list
cli toggle shopify_http
cli inspect shopify_http
cli toggle shopify_http
echo -e "-----------------\n"
echo "== Benchmarking"
echo
echo "=== Without toxics"
benchmark
echo -e "-----------------\n"
echo "=== Latency toxic downstream"
cli toxic add --downstream \
--type=latency \
--toxicName="latency_downstream" \
--attribute="latency=1000" \
--attribute="jitter=50" \
--toxicity=0.99 \
shopify_http
cli inspect shopify_http
benchmark
cli toxic update --toxicName="latency_downstream" \
--attribute="jitter=20" \
--toxicity=0.7 \
shopify_http
cli inspect shopify_http
cli toxic delete --toxicName="latency_downstream" shopify_http
echo -e "-----------------\n"
echo "=== Latency toxic upstream"
cli toxic add --upstream \
--type=latency \
--toxicName="latency_upstream" \
--attribute="latency=1000" \
--attribute="jitter=50" \
--toxicity=1 \
shopify_http
cli inspect shopify_http
benchmark
cli toxic update --toxicName="latency_upstream" \
--attribute="jitter=20" \
--toxicity=0.3 \
shopify_http
cli inspect shopify_http
cli toxic delete --toxicName="latency_upstream" shopify_http
echo -e "-----------------\n"
echo "=== Bandwidth toxic"
cli toxic add --type=bandwidth \
--toxicName="bandwidth_kb_per_second" \
--attribute="rate=1" \
--toxicity=0.5 \
shopify_http
cli toxic update --toxicName="bandwidth_kb_per_second" \
--attribute="rate=10" \
--toxicity=1.0 \
shopify_http
benchmark
cli toxic delete --toxicName="bandwidth_kb_per_second" \
shopify_http
echo -e "-----------------\n"
echo "=== Timeout toxic"
cli toxic add --type=timeout \
--toxicName="timeout_ms" \
--attribute="timeout=10" \
--toxicity=0.1 \
shopify_http
cli toxic delete --toxicName="timeout_ms" shopify_http
echo -e "-----------------\n"
echo "=== Slicer toxic"
cli toxic add --type=slicer \
--toxicName="slicer_us" \
--attribute="average_size=64" \
--attribute="size_variation=32" \
--attribute="delay=10" \
--toxicity=1.0 \
shopify_http
benchmark
cli toxic delete --toxicName="slicer_us" shopify_http
echo -e "-----------------\n"
echo "=== Reset peer toxic"
cli toxic add --type=reset_peer \
--toxicName="reset_peer" \
--attribute="timeout=2000" \
--toxicity=1.0 \
shopify_http
cli inspect shopify_http
cli toxic delete --toxicName="reset_peer" shopify_http
echo -e "-----------------\n"
echo "== Metrics test"
wait_for_url http://localhost:20000/test1
curl -s http://localhost:8474/metrics | grep -E '^toxiproxy_proxy_sent_bytes_total{direction="downstream",listener="127.0.0.1:20000",proxy="shopify_http",upstream="localhost:20002"} [0-9]+'
curl -s http://localhost:8474/metrics | grep -E '^go_info'
curl -s http://localhost:8474/metrics | grep -E '^go_goroutines'
echo -e "-----------------\n"
echo -e "=================\n"
echo "Succcess!"
state="success"