Skip to content

Commit d288f1f

Browse files
committed
change retry strategy
1 parent e3eb97b commit d288f1f

2 files changed

Lines changed: 84 additions & 59 deletions

File tree

tests/deploy/run-deploy-test.sh

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,50 @@ delete_cluster_exit () {
1313

1414
trap delete_cluster_exit EXIT
1515

16-
retry () {
17-
local try=0
18-
local max=5
19-
local delay=5
20-
while [ $try -lt $max ]; do
16+
add_todo() {
17+
set +e
18+
19+
local running=0
20+
local check=0
21+
local check_limit=10
22+
23+
url=$1
24+
title=$2
25+
26+
try=0
27+
rc=1
28+
29+
while [ $rc -ne 0 ] && [ $try -lt 10 ]; do
2130
try=$((try + 1))
22-
echo "Try $try of $* ..."
23-
$* && RC=$? || RC=$?
24-
if [ $RC -eq 0 ]; then
25-
return 0
26-
else
27-
sleep $delay
31+
curl "$url" \
32+
-H 'Accept: application/json, text/plain, */*' \
33+
-H 'Accept-Language: en-US,en;q=0.9' \
34+
-H 'Connection: keep-alive' \
35+
-H 'Content-Type: application/json' \
36+
-H 'Origin: http://localhost' \
37+
-H 'Referer: http://localhost/' \
38+
-H 'Sec-Fetch-Dest: empty' \
39+
-H 'Sec-Fetch-Mode: cors' \
40+
-H 'Sec-Fetch-Site: same-site' \
41+
-H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 Edg/135.0.0.0' \
42+
-H 'sec-ch-ua: "Microsoft Edge";v="135", "Not-A.Brand";v="8", "Chromium";v="135"' \
43+
-H 'sec-ch-ua-mobile: ?0' \
44+
-H 'sec-ch-ua-platform: "Windows"' \
45+
--data-raw "{\"title\":\"$title\",\"completed\":false}"
46+
rc=$?
47+
48+
if [ $rc -ne 0 ]; then
49+
echo "Error adding todo, retrying..."
50+
sleep 5
2851
fi
2952
done
30-
return 1
53+
54+
set -e
55+
56+
return $rc
3157
}
3258

59+
3360
wait_for_running () {
3461
# Check that all services are running
3562
local how_many=$1
@@ -102,21 +129,7 @@ wait_for_running 3
102129

103130
# Add a todo
104131
todo_title="79b06705-b402-431a-83a3-a634392d2754"
105-
retry curl 'http://localhost:5000/api/todos' \
106-
-H 'Accept: application/json, text/plain, */*' \
107-
-H 'Accept-Language: en-US,en;q=0.9' \
108-
-H 'Connection: keep-alive' \
109-
-H 'Content-Type: application/json' \
110-
-H 'Origin: http://localhost:3000' \
111-
-H 'Referer: http://localhost:3000/' \
112-
-H 'Sec-Fetch-Dest: empty' \
113-
-H 'Sec-Fetch-Mode: cors' \
114-
-H 'Sec-Fetch-Site: same-site' \
115-
-H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 Edg/135.0.0.0' \
116-
-H 'sec-ch-ua: "Microsoft Edge";v="135", "Not-A.Brand";v="8", "Chromium";v="135"' \
117-
-H 'sec-ch-ua-mobile: ?0' \
118-
-H 'sec-ch-ua-platform: "Windows"' \
119-
--data-raw "{\"title\":\"$todo_title\",\"completed\":false}"
132+
add_todo http://localhost:5000/api/todos "$todo_title"
120133

121134
# Check that it exists
122135
if [ "$todo_title" != "$(curl -s http://localhost:5000/api/todos | jq -r '.[] | select(.id == 1) | .title')" ]; then

tests/k8s-deploy/run-deploy-test.sh

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,6 @@ delete_cluster_exit () {
1717

1818
trap delete_cluster_exit EXIT
1919

20-
retry () {
21-
local try=0
22-
local max=5
23-
local delay=5
24-
while [ $try -lt $max ]; do
25-
try=$((try + 1))
26-
echo "Try $try of $* ..."
27-
$* && RC=$? || RC=$?
28-
if [ $RC -eq 0 ]; then
29-
return 0
30-
else
31-
sleep $delay
32-
fi
33-
done
34-
return 1
35-
}
36-
3720
wait_for_pods_started () {
3821
for i in {1..50}
3922
do
@@ -96,6 +79,49 @@ wait_for_running () {
9679
set -e
9780
}
9881

82+
add_todo() {
83+
set +e
84+
85+
local running=0
86+
local check=0
87+
local check_limit=10
88+
89+
url=$1
90+
title=$2
91+
92+
try=0
93+
rc=1
94+
95+
while [ $rc -ne 0 ] && [ $try -lt 10 ]; do
96+
try=$((try + 1))
97+
curl "$url" \
98+
-H 'Accept: application/json, text/plain, */*' \
99+
-H 'Accept-Language: en-US,en;q=0.9' \
100+
-H 'Connection: keep-alive' \
101+
-H 'Content-Type: application/json' \
102+
-H 'Origin: http://localhost' \
103+
-H 'Referer: http://localhost/' \
104+
-H 'Sec-Fetch-Dest: empty' \
105+
-H 'Sec-Fetch-Mode: cors' \
106+
-H 'Sec-Fetch-Site: same-site' \
107+
-H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 Edg/135.0.0.0' \
108+
-H 'sec-ch-ua: "Microsoft Edge";v="135", "Not-A.Brand";v="8", "Chromium";v="135"' \
109+
-H 'sec-ch-ua-mobile: ?0' \
110+
-H 'sec-ch-ua-platform: "Windows"' \
111+
--data-raw "{\"title\":\"$title\",\"completed\":false}"
112+
rc=$?
113+
114+
if [ $rc -ne 0 ]; then
115+
echo "Error adding todo, retrying..."
116+
sleep 5
117+
fi
118+
done
119+
120+
set -e
121+
122+
return $rc
123+
}
124+
99125
export STACK_USE_BUILTIN_STACK=true
100126

101127
# Test basic stack deploy
@@ -153,21 +179,7 @@ wait_for_running 3
153179

154180
# Add a todo
155181
todo_title="79b06705-b402-431a-83a3-a634392d2754"
156-
retry curl 'http://localhost/api/todos' \
157-
-H 'Accept: application/json, text/plain, */*' \
158-
-H 'Accept-Language: en-US,en;q=0.9' \
159-
-H 'Connection: keep-alive' \
160-
-H 'Content-Type: application/json' \
161-
-H 'Origin: http://localhost' \
162-
-H 'Referer: http://localhost/' \
163-
-H 'Sec-Fetch-Dest: empty' \
164-
-H 'Sec-Fetch-Mode: cors' \
165-
-H 'Sec-Fetch-Site: same-site' \
166-
-H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 Edg/135.0.0.0' \
167-
-H 'sec-ch-ua: "Microsoft Edge";v="135", "Not-A.Brand";v="8", "Chromium";v="135"' \
168-
-H 'sec-ch-ua-mobile: ?0' \
169-
-H 'sec-ch-ua-platform: "Windows"' \
170-
--data-raw "{\"title\":\"$todo_title\",\"completed\":false}"
182+
add_todo http://localhost/api/todos "$todo_title"
171183

172184
# Check that it exists
173185
if [ "$todo_title" != "$(curl -s http://localhost/api/todos | jq -r '.[] | select(.id == 1) | .title')" ]; then

0 commit comments

Comments
 (0)