99
1010delete_cluster_exit () {
1111 $TEST_TARGET_SO manage --dir $test_deployment_dir stop --delete-volumes
12- exit 1
1312}
1413
14+ trap delete_cluster_exit EXIT
15+
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
30+ try=$(( try + 1 ))
31+ curl " $url " \
32+ --fail-with-body \
33+ -H ' Accept: application/json, text/plain, */*' \
34+ -H ' Accept-Language: en-US,en;q=0.9' \
35+ -H ' Connection: keep-alive' \
36+ -H ' Content-Type: application/json' \
37+ -H ' Origin: http://localhost' \
38+ -H ' Referer: http://localhost/' \
39+ -H ' Sec-Fetch-Dest: empty' \
40+ -H ' Sec-Fetch-Mode: cors' \
41+ -H ' Sec-Fetch-Site: same-site' \
42+ -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' \
43+ -H ' sec-ch-ua: "Microsoft Edge";v="135", "Not-A.Brand";v="8", "Chromium";v="135"' \
44+ -H ' sec-ch-ua-mobile: ?0' \
45+ -H ' sec-ch-ua-platform: "Windows"' \
46+ --data-raw " {\" title\" :\" $title \" ,\" completed\" :false}"
47+ rc=$?
48+
49+ if [ $rc -ne 0 ]; then
50+ echo " Error adding todo, retrying..."
51+ sleep 5
52+ fi
53+ done
54+
55+ set -e
56+
57+ return $rc
58+ }
59+
60+
1561wait_for_running () {
1662 # Check that all services are running
63+ local how_many=$1
1764 local running=0
1865 local check=0
1966 local check_limit=10
20- while [ $running -lt 3 ] && [ $check -lt $check_limit ]; do
67+ while [ $running -lt $how_many ] && [ $check -lt $check_limit ]; do
2168 check=$(( check + 1 ))
22- running=$( $TEST_TARGET_SO manage --dir $test_deployment_dir status | grep -c " running" )
23- if [ $running -lt 3 ]; then
69+ running=$( $TEST_TARGET_SO manage --dir $test_deployment_dir status | grep -ic " running" )
70+ if [ $running -lt $how_many ]; then
2471 echo " deploy manage start: Waiting for services to start..."
2572 sleep 5
2673 fi
2774 done
2875
29- if [ $running -lt 3 ]; then
76+ if [ $running -lt $how_many ]; then
3077 echo " deploy manage start: failed - not all services started"
31- delete_cluster_exit
78+ exit 1
3279 fi
3380}
3481
@@ -79,34 +126,16 @@ echo "deploy create test: passed"
79126
80127# Start
81128$TEST_TARGET_SO manage --dir $test_deployment_dir start
82- wait_for_running
129+ wait_for_running 3
83130
84131# Add a todo
85132todo_title=" 79b06705-b402-431a-83a3-a634392d2754"
86- curl ' http://localhost:5000/api/todos' \
87- -H ' Accept: application/json, text/plain, */*' \
88- -H ' Accept-Language: en-US,en;q=0.9' \
89- -H ' Connection: keep-alive' \
90- -H ' Content-Type: application/json' \
91- -H ' Origin: http://localhost:3000' \
92- -H ' Referer: http://localhost:3000/' \
93- -H ' Sec-Fetch-Dest: empty' \
94- -H ' Sec-Fetch-Mode: cors' \
95- -H ' Sec-Fetch-Site: same-site' \
96- -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' \
97- -H ' sec-ch-ua: "Microsoft Edge";v="135", "Not-A.Brand";v="8", "Chromium";v="135"' \
98- -H ' sec-ch-ua-mobile: ?0' \
99- -H ' sec-ch-ua-platform: "Windows"' \
100- --data-raw " {\" title\" :\" $todo_title \" ,\" completed\" :false}"
101- if [ $? -ne 0 ]; then
102- echo " deploy storage: failed - todo $todo_title not added"
103- delete_cluster_exit
104- fi
133+ add_todo http://localhost:5000/api/todos " $todo_title "
105134
106135# Check that it exists
107136if [ " $todo_title " != " $( curl -s http://localhost:5000/api/todos | jq -r ' .[] | select(.id == 1) | .title' ) " ]; then
108137 echo " deploy storage: failed - todo $todo_title not found"
109- delete_cluster_exit
138+ exit 1
110139fi
111140
112141# Stop the stack (don't delete volumes)
@@ -116,18 +145,19 @@ $TEST_TARGET_SO manage --dir $test_deployment_dir stop
116145$TEST_TARGET_SO manage --dir $test_deployment_dir start
117146
118147# Check that all services are running
119- wait_for_running
148+ wait_for_running 3
120149
121150# Check that it is still viewable
122151if [ " $todo_title " != " $( curl -s http://localhost:5000/api/todos | jq -r ' .[] | select(.id == 1) | .title' ) " ]; then
123152 echo " deploy storage: failed - todo $todo_title not found after restart"
124- delete_cluster_exit
153+ exit 1
125154fi
126155echo " deploy storage: passed"
127156
128157# TODO: Do we need to add a check for deleting the volumes?
129158# Docker doesn't remove the files for a bound volume so nothing much really changes.
130159
131- # Stop and clean up
132- $TEST_TARGET_SO manage --dir $test_deployment_dir stop --delete-volumes
160+ wget -q -O - http://localhost:3000 | grep ' bundle.js'
161+ echo " deploy http: passed"
162+
133163echo " Test passed"
0 commit comments