Skip to content

Commit 4be2bd0

Browse files
authored
Merge pull request #327 from jajik/issue-326
test: Add timeout for curls, minor syntax tweaks
2 parents 644bceb + be85c06 commit 4be2bd0

File tree

8 files changed

+41
-41
lines changed

8 files changed

+41
-41
lines changed

test/MODCLUSTER-640/testit.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ docker cp MODCLUSTER-640/webapp1 tomcat2:/usr/local/tomcat/webapps/webapp1
2929
sleep 12
3030

3131
# test the URL
32-
code=$(/usr/bin/curl -o /dev/null --silent --write-out '%{http_code}' http://localhost:8000/webapp1/index.html)
32+
code=$(/usr/bin/curl -o /dev/null -s -m 20 --write-out '%{http_code}' http://localhost:8000/webapp1/index.html)
3333
if [ "${code}" != "200" ]; then
3434
echo "nocanon test failed, we get ${code} on http://localhost:8000/webapp1/index.html"
3535
exit 1
3636
fi
37-
curl -v "http://localhost:8000/webapp1/jsr%3aroot/toto" | grep "jsr:root"
37+
curl -v -m 20 "http://localhost:8000/webapp1/jsr%3aroot/toto" | grep "jsr:root"
3838
if [ $? -eq 0 ]; then
3939
echo "nocanon test failed, we get \"jsr:root\"!!!"
4040
exit 1
@@ -49,12 +49,12 @@ docker exec MODCLUSTER-640 /usr/local/apache2/bin/apachectl restart
4949
tomcat_wait_for_n_nodes 2
5050

5151
# test the URL
52-
code=$(/usr/bin/curl -o /dev/null --silent --write-out '%{http_code}' http://localhost:8000/webapp1/index.html)
52+
code=$(/usr/bin/curl -o /dev/null -s -m 20 --write-out '%{http_code}' http://localhost:8000/webapp1/index.html)
5353
if [ "${code}" != "200" ]; then
5454
echo "nocanon test failed, we get ${code} on http://localhost:8000/webapp1/index.html"
5555
exit 1
5656
fi
57-
curl -v "http://localhost:8000/webapp1/jsr%3aroot/toto" | grep "jsr:root"
57+
curl -v -m 20 "http://localhost:8000/webapp1/jsr%3aroot/toto" | grep "jsr:root"
5858
if [ $? -ne 0 ]; then
5959
echo "NO nocanon test failed, we don't get \"jsr:root\"!!!"
6060
exit 1
@@ -68,12 +68,12 @@ docker exec MODCLUSTER-640 /usr/local/apache2/bin/apachectl restart
6868
tomcat_wait_for_n_nodes 2
6969

7070
# test the URL
71-
code=$(/usr/bin/curl -o /dev/null --silent --write-out '%{http_code}' http://localhost:8000/webapp1/index.html)
71+
code=$(/usr/bin/curl -o /dev/null -s -m 20 --write-out '%{http_code}' http://localhost:8000/webapp1/index.html)
7272
if [ "${code}" != "200" ]; then
7373
echo "nocanon test failed, we get ${code} on http://localhost:8000/webapp1/index.html"
7474
exit 1
7575
fi
76-
curl -v "http://localhost:8000/webapp1/jsr%3aroot/toto" | grep "jsr:root"
76+
curl -v -m 20 "http://localhost:8000/webapp1/jsr%3aroot/toto" | grep "jsr:root"
7777
if [ $? -eq 0 ]; then
7878
echo "nocanon test failed, we get \"jsr:root\"!!!"
7979
tomcat_all_remove

test/MODCLUSTER-734/testit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ docker cp MODCLUSTER-734/ROOT_OK tomcat2:/usr/local/tomcat/webapps/ROOT
3131
# and mark the node not OK.
3232
sleep 15
3333

34-
curl -s http://localhost:6666/mod_cluster_manager | grep "Status: NOTOK"
34+
curl -s -m 20 http://localhost:6666/mod_cluster_manager | grep "Status: NOTOK"
3535
if [ $? -eq 0 ]; then
3636
echo "MODCLUSTER-734 Done!"
3737
else

test/MODCLUSTER-736/testit.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ singlecycle() {
8989
i=0
9090
while true
9191
do
92-
curl -s http://localhost:6666/mod_cluster_manager | grep Node | grep tomcat$1 > /dev/null
92+
curl -s -m 20 http://localhost:6666/mod_cluster_manager | grep Node | grep tomcat$1 > /dev/null
9393
if [ $? -eq 0 ]; then
9494
break
9595
fi
@@ -106,7 +106,7 @@ singlecycle() {
106106
i=0
107107
while true
108108
do
109-
curl -s http://localhost:6666/mod_cluster_manager | grep /tomcat$1 > /dev/null
109+
curl -s -m 20 http://localhost:6666/mod_cluster_manager | grep /tomcat$1 > /dev/null
110110
if [ $? -eq 0 ]; then
111111
break
112112
fi
@@ -126,7 +126,7 @@ singlecycle() {
126126
tomcat_shutdown $1 127.0.0.$R || exit 1
127127
while true
128128
do
129-
curl -s http://localhost:6666/mod_cluster_manager | grep Node | grep tomcat$1 > /dev/null
129+
curl -s -m 20 http://localhost:6666/mod_cluster_manager | grep Node | grep tomcat$1 > /dev/null
130130
if [ $? -ne 0 ]; then
131131
break
132132
fi

test/MODCLUSTER-785/testit.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ docker cp MODCLUSTER-785/app tomcat1:/usr/local/tomcat/webapps/app
2525

2626
# check that the app is answering
2727
sleep 15
28-
curl -s http://localhost:8000/app/status.jsp | grep "785"
28+
curl -s -m 20 http://localhost:8000/app/status.jsp | grep "785"
2929
if [ $? -ne 0 ]; then
3030
echo "MODCLUSTER-785 Failed!"
3131
exit 1
@@ -37,7 +37,7 @@ tomcat_remove 1
3737
# it return 503
3838
# make sure we use enough workers
3939
ab -c 10 -n100 http://localhost:8000/app/
40-
http_code=`curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/app/`
40+
http_code=$(curl -s -m 20 -o /dev/null -w "%{http_code}" http://localhost:8000/app/)
4141
if [ ${http_code} != 503 ]; then
4242
echo "MODCLUSTER-785 Failed! not 503 but ${http_code}"
4343
exit 1
@@ -57,16 +57,16 @@ sleep 15
5757

5858
# check that the app is answering
5959
# does it return 503
60-
http_code=`curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/app/status.jsp`
60+
http_code=$(curl -s -m 20 -o /dev/null -w "%{http_code}" http://localhost:8000/app/status.jsp)
6161
i=0
6262
while true
6363
do
6464
sleep 1
65-
http_code=`curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/app/status.jsp`
65+
http_code=$(curl -s -m 20 -o /dev/null -w "%{http_code}" http://localhost:8000/app/status.jsp)
6666
if [ ${http_code} == 200 ]; then
6767
break
6868
fi
69-
i=`expr $i + 1`
69+
i=$(expr $i + 1)
7070
if [ $i -gt 60 ]; then
7171
break
7272
fi
@@ -86,12 +86,12 @@ i=0
8686
while true
8787
do
8888
sleep 1
89-
http_code=`curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/app/status.jsp`
89+
http_code=$(curl -s -m 20 -o /dev/null -w "%{http_code}" http://localhost:8000/app/status.jsp)
9090
if [ ${http_code} == 503 ]; then
9191
echo "MODCLUSTER-785 Failed! return 503"
9292
exit 1
9393
fi
94-
i=`expr $i + 1`
94+
i=$(expr $i + 1)
9595
if [ $i -gt 60 ]; then
9696
break
9797
fi

test/basetests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ sleep 12
2020

2121
# Basic 200 and 404 tests.
2222
echo "basic 200 and 404 tests"
23-
CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/testapp/test.jsp)
23+
CODE=$(curl -s -m 20 -o /dev/null -w "%{http_code}" http://localhost:8000/testapp/test.jsp)
2424
if [ ${CODE} != "200" ]; then
2525
echo "Failed can't reach webapp: ${CODE}"
2626
exit 1
2727
fi
28-
CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/testapp/toto.jsp)
28+
CODE=$(curl -s -m 20 -o /dev/null -w "%{http_code}" http://localhost:8000/testapp/toto.jsp)
2929
if [ ${CODE} != "404" ]; then
3030
echo "Failed should get 404"
3131
exit 1

test/curlloop.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ done
1111
while true
1212
do
1313
found=0
14-
http_code=`curl -s -m10 -o /dev/null -w "%{http_code}" http://localhost:8000/testapp/test.jsp`
14+
http_code=$(curl -s -m 10 -o /dev/null -w "%{http_code}" http://localhost:8000/testapp/test.jsp)
1515
for var in "$@"
1616
do
1717
if [ "${http_code}" -eq "${var}" ]; then
@@ -20,7 +20,7 @@ do
2020
fi
2121
done
2222
if [ ${found} -eq 0 ]; then
23-
echo "ERROR got: ${http_code} expects one of ${codes} `date`"
23+
echo "ERROR got: ${http_code} expects one of ${codes} $(date)"
2424
exit 1
2525
fi
2626

test/includes/common.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ httpd_start() {
7676

7777
httpd_wait_until_ready() {
7878
local i=0
79-
curl localhost:6666 > /dev/null 2>&1
79+
curl -m 20 localhost:6666 > /dev/null 2>&1
8080
while [ $? != 0 ];
8181
do
8282
i=$(expr $i + 1)
@@ -85,7 +85,7 @@ httpd_wait_until_ready() {
8585
exit 1;
8686
fi
8787
sleep 10;
88-
curl localhost:6666 > /dev/null 2>&1
88+
curl -m 20 localhost:6666 > /dev/null 2>&1
8989
done
9090
echo "httpd ready after $i attempts"
9191
}
@@ -166,7 +166,7 @@ tomcat_start() {
166166
# Wait until there are $1 nodes in OK state (i.e., some will start or go away if the count is different)
167167
tomcat_wait_for_n_nodes() {
168168
nodes=${1:-0}
169-
curl -s http://localhost:6666/mod_cluster_manager -o /dev/null
169+
curl -s http://localhost:6666/mod_cluster_manager -m 20 -o /dev/null
170170
if [ $? -ne 0 ]; then
171171
echo "httpd isn't running or something is VERY wrong"
172172
exit 1
@@ -175,7 +175,7 @@ tomcat_wait_for_n_nodes() {
175175
i=0
176176
while [ ${NBNODES} != ${nodes} ]
177177
do
178-
NBNODES=$(curl -s http://localhost:6666/mod_cluster_manager | grep "Status: OK" | awk ' { print $3} ' | wc -l)
178+
NBNODES=$(curl -s http://localhost:6666/mod_cluster_manager -m 20 | grep "Status: OK" | awk ' { print $3} ' | wc -l)
179179
sleep 10
180180
echo "Waiting for ${nodes} node to be ready: $(date)"
181181
i=$(expr $i + 1)
@@ -184,7 +184,7 @@ tomcat_wait_for_n_nodes() {
184184
exit 1
185185
fi
186186
done
187-
curl -s http://localhost:6666/mod_cluster_manager -o /dev/null
187+
curl -s http://localhost:6666/mod_cluster_manager -m 20 -o /dev/null
188188
if [ $? -ne 0 ]; then
189189
echo "httpd isn't running or something VERY wrong"
190190
exit 1
@@ -298,7 +298,7 @@ tomcat_all_run_ab() {
298298

299299
# Test whether the webapp is working (responding)
300300
tomcat_test_app() {
301-
CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/tomcat$1/test.jsp)
301+
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" http://localhost:8000/tomcat$1/test.jsp)
302302
if [ ${CODE} != "200" ]; then
303303
echo "Failed can't reach tomcat$1: ${CODE}"
304304
exit 1

test/maintests.sh

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ sleep 12
2929

3030
# Sticky (yes, there is only one app!!!)
3131
echotestlabel "sticky one app"
32-
SESSIONCO=$(curl -v http://localhost:8000/testapp/test.jsp -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::')
32+
SESSIONCO=$(curl -v http://localhost:8000/testapp/test.jsp -m 20 -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::')
3333
if [ "${SESSIONCO}" == "" ];then
3434
echo "Failed no sessionid in curl output..."
3535
curl -v http://localhost:8000/testapp/test.jsp
3636
fi
3737
echo ${SESSIONCO}
38-
NEWCO=$(curl -v --cookie "${SESSIONCO}" http://localhost:8000/testapp/test.jsp -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::')
38+
NEWCO=$(curl -v --cookie "${SESSIONCO}" http://localhost:8000/testapp/test.jsp -m 20 -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::')
3939
if [ "${NEWCO}" != "" ]; then
4040
echo "Failed not sticky received : ${NEWCO}???"
4141
exit 1
@@ -47,17 +47,17 @@ sleep 12
4747

4848
# Sticky (yes there are 2 apps now)
4949
echotestlabel "sticky 2 app"
50-
SESSIONCO=$(curl -v http://localhost:8000/testapp/test.jsp -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::')
50+
SESSIONCO=$(curl -v http://localhost:8000/testapp/test.jsp -m 20 -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::')
5151
NODE=$(echo ${SESSIONCO} | awk -F = '{ print $2 }' | awk -F . '{ print $2 }')
5252
echo "first: ${SESSIONCO} node: ${NODE}"
53-
NEWCO=$(curl -v http://localhost:8000/testapp/test.jsp -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::')
53+
NEWCO=$(curl -v http://localhost:8000/testapp/test.jsp -m 20 -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::')
5454
NEWNODE=$(echo ${NEWCO} | awk -F = '{ print $2 }' | awk -F . '{ print $2 }')
5555
echo "second: ${NEWCO} node: ${NEWNODE}"
5656
echo "Checking we can reach the 2 nodes"
5757
i=0
5858
while [ "${NODE}" == "${NEWNODE}" ]
5959
do
60-
NEWCO=$(curl -v http://localhost:8000/testapp/test.jsp -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::')
60+
NEWCO=$(curl -v http://localhost:8000/testapp/test.jsp -m 20 -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::')
6161
NEWNODE=$(echo ${NEWCO} | awk -F = '{ print $2 }' | awk -F . '{ print $2 }')
6262
i=$(expr $i + 1)
6363
if [ $i -gt 40 ]; then
@@ -73,12 +73,12 @@ done
7373
echo "${i} try gives: ${NEWCO} node: ${NEWNODE}"
7474

7575
# Still sticky
76-
CO=$(curl -v --cookie "${SESSIONCO}" http://localhost:8000/testapp/test.jsp -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::')
76+
CO=$(curl -v --cookie "${SESSIONCO}" http://localhost:8000/testapp/test.jsp -m 20 -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::')
7777
if [ "${CO}" != "" ]; then
7878
echo "Failed not sticky received : ${CO}???"
7979
exit 1
8080
fi
81-
CO=$(curl -v --cookie "${NEWCO}" http://localhost:8000/testapp/test.jsp -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::')
81+
CO=$(curl -v --cookie "${NEWCO}" http://localhost:8000/testapp/test.jsp -m 20 -o /dev/null 2>&1 | grep Set-Cookie | awk '{ print $3 } ' | sed 's:;::')
8282
if [ "${CO}" != "" ]; then
8383
echo "Failed not sticky received : ${CO}???"
8484
exit 1
@@ -88,7 +88,7 @@ fi
8888
echotestlabel "sticky: stopping one node and doing requests..."
8989
NODE=$(echo ${NEWCO} | awk -F = '{ print $2 }' | awk -F . '{ print $2 }')
9090
echo $NODE
91-
PORT=$(curl http://localhost:6666/mod_cluster_manager | grep Node | grep $NODE | sed 's:)::' | awk -F : '{ print $3 } ')
91+
PORT=$(curl http://localhost:6666/mod_cluster_manager -m 20 | grep Node | grep $NODE | sed 's:)::' | awk -F : '{ print $3 } ')
9292
NAME=$(expr ${PORT} - 8080 + 1)
9393
echo "Will stop tomcat$NAME corresponding to ${NODE} and cookie: ${NEWCO}"
9494
CODE="200"
@@ -99,7 +99,7 @@ do
9999
echo "Done remaining tomcat still answering!"
100100
break
101101
fi
102-
CODE=$(curl -s -o /dev/null -w "%{http_code}" --cookie "${NEWCO}" http://localhost:8000/testapp/test.jsp)
102+
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --cookie "${NEWCO}" http://localhost:8000/testapp/test.jsp)
103103
if [ $i -eq 0 ]; then
104104
# stop the tomcat
105105
echo "tomcat${NAME} being stopped"
@@ -109,7 +109,7 @@ do
109109
done
110110
if [ ${CODE} != "200" ]; then
111111
echo "Something was wrong... got: ${CODE}"
112-
curl -v --cookie "${NEWCO}" http://localhost:8000/testapp/test.jsp
112+
curl -v --cookie "${NEWCO}" -m 20 http://localhost:8000/testapp/test.jsp
113113
exit 1
114114
fi
115115

@@ -148,25 +148,25 @@ tomcat_wait_for_n_nodes 2 || exit 1
148148
# X-Forwarded-Server: fe80::faf4:935b:9dda:2adf
149149
# therefore don't forget ProxyPreserveHost On (otherwise UseAlias On failed...)
150150
#
151-
CODE=$(curl -s -o /dev/null -w "%{http_code}" --header "Host: example.com" http://127.0.0.1:8000/test/test.jsp)
151+
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --header "Host: example.com" http://127.0.0.1:8000/test/test.jsp)
152152
if [ ${CODE} != "200" ]; then
153153
echo "Failed can't rearch webapp at example.com: ${CODE}"
154154
exit 1
155155
fi
156156
# Basically curl --header "Host: localhost" http://127.0.0.1:8000/test/test.jsp gives 400
157-
CODE=$(curl -s -o /dev/null -w "%{http_code}" --header "Host: localhost" http://127.0.0.1:8000/test/test.jsp)
157+
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --header "Host: localhost" http://127.0.0.1:8000/test/test.jsp)
158158
if [ ${CODE} != "404" ]; then
159159
echo "Failed should NOT rearch webapp at localhost: ${CODE}"
160160
exit 1
161161
fi
162162
# Same using localhost/testapp2 and curl --header "Host: localhost" http://127.0.0.1:8000/testapp2/test.jsp
163-
CODE=$(curl -s -o /dev/null -w "%{http_code}" --header "Host: localhost" http://127.0.0.1:8000/testapp2/test.jsp)
163+
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --header "Host: localhost" http://127.0.0.1:8000/testapp2/test.jsp)
164164
if [ ${CODE} != "200" ]; then
165165
echo "Failed can't rearch webapp at localhost: ${CODE}"
166166
exit 1
167167
fi
168168
# Basically curl --header "Host: example.com" http://127.0.0.1:8000/testapp2/test.jsp gives 400
169-
CODE=$(curl -s -o /dev/null -w "%{http_code}" --header "Host: example.com" http://127.0.0.1:8000/testapp2/test.jsp)
169+
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --header "Host: example.com" http://127.0.0.1:8000/testapp2/test.jsp)
170170
if [ ${CODE} != "404" ]; then
171171
echo "Failed should NOT rearch webapp at localhost: ${CODE}"
172172
exit 1

0 commit comments

Comments
 (0)