Skip to content

Commit b131a0c

Browse files
committed
test: Update tests to use new container provisioning
Shift tomcat ports where conflicts might lead to random test failures Code and format clean ups
1 parent dc90b16 commit b131a0c

File tree

9 files changed

+95
-90
lines changed

9 files changed

+95
-90
lines changed

test/MODCLUSTER-640/testit.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ httpd_remove
1010
rm -f nohup.out
1111

1212
MPC_CONF=${MPC_CONF:-MODCLUSTER-640/mod_proxy_cluster.conf}
13-
MPC_NAME=MODCLUSTER-640 httpd_start
13+
MPC_NAME=MODCLUSTER-640
14+
15+
httpd_start
1416

1517
# wait until httpd is started
1618
httpd_wait_until_ready || exit 1

test/MODCLUSTER-734/testit.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ httpd_remove
1010
rm -f nohup.out
1111

1212
MPC_CONF=${MPC_CONF:-MODCLUSTER-734/mod_proxy_cluster.conf}
13-
MPC_NAME=MODCLUSTER-734 httpd_start
13+
MPC_NAME=MODCLUSTER-734
14+
15+
httpd_start
1416

1517
# wait until httpd is started
1618
httpd_wait_until_ready || exit 1
@@ -29,7 +31,7 @@ docker cp MODCLUSTER-734/ROOT_OK tomcat2:/usr/local/tomcat/webapps/ROOT
2931

3032
# after a while the health check will get the Under maintenance status.jsp
3133
# and mark the node not OK.
32-
sleep 15
34+
sleep 20
3335

3436
curl -s -m 20 http://localhost:8090/mod_cluster_manager | grep "Status: NOTOK"
3537
if [ $? -eq 0 ]; then

test/MODCLUSTER-736/testit.sh

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
httpd_remove
66
tomcat_all_remove
77

8-
MPC_NAME=MODCLUSTER-736 httpd_start
8+
MPC_NAME=MODCLUSTER-736
9+
# We must shift tomcat ports so that they do not collide with proxy
10+
PORT=9000
11+
SHUTDOWN_PORT=7005
12+
13+
httpd_start
914

1015
# Start a bunch ($1, or 6 if no argument is given) of tomcat
1116
# containers, then test them and stop them
@@ -75,15 +80,8 @@ runtomcatbatch() {
7580
singlecycle() {
7681
echo "singlecycle: Testing tomcat$1"
7782
R=$1
78-
if [ "$2" = "useran" ]; then
79-
R=$(expr 1 + $RANDOM % 10 + 10)
80-
R=$(expr $R + 2)
81-
# TODO
82-
tomcat_start $1 127.0.0.$R || exit 1
83-
else
84-
R=0
85-
tomcat_start $1 127.0.0.$R || exit 1
86-
fi
83+
tomcat_start $1 || exit 1
84+
8785
# Wait for it to start
8886
echo "Testing(0) tomcat$1 waiting..."
8987
i=0
@@ -106,7 +104,8 @@ singlecycle() {
106104
i=0
107105
while true
108106
do
109-
curl -s -m 20 http://localhost:8090/mod_cluster_manager | grep /tomcat$1 > /dev/null
107+
# we have to grep the beginning slash but also a comma at the end, otherwise hostname might be matched
108+
curl -s -m 20 http://localhost:8090/mod_cluster_manager | grep "/tomcat$1," > /dev/null
110109
if [ $? -eq 0 ]; then
111110
break
112111
fi
@@ -123,7 +122,7 @@ singlecycle() {
123122
tomcat_test_app $1 || exit 1
124123
tomcat_run_ab $1 || exit 1
125124
echo "Testing(3) tomcat$1"
126-
tomcat_shutdown $1 127.0.0.$R || exit 1
125+
tomcat_shutdown $1 || exit 1
127126
while true
128127
do
129128
curl -s -m 20 http://localhost:8090/mod_cluster_manager | grep Node | grep tomcat$1 > /dev/null
@@ -184,16 +183,11 @@ forevertomcat() {
184183

185184
# Start and stop successively (one after another) $1 tomcats
186185
cyclestomcats() {
187-
i=1
188-
while true
189-
do
190-
i=$(expr $i + 1)
191-
if [ $i -gt $1 ]; then
192-
echo "Looks OK, Done!"
193-
break
194-
fi
195-
singlecycle $i useran || exit 1
186+
for i in $(seq 1 $1); do
187+
echo -n "$i/$1: "
188+
singlecycle $i || exit 1
196189
done
190+
echo "Looks OK, Done!"
197191
}
198192

199193
# run test for https://issues.redhat.com/browse/MODCLUSTER-736

test/MODCLUSTER-755/testit.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ httpd_remove
1212
tomcat_all_remove
1313

1414
MPC_CONF=${MPC_CONF:-MODCLUSTER-755/mod_proxy_cluster.conf}
15-
MPC_NAME=MODCLUSTER-755 httpd_start
15+
MPC_NAME=MODCLUSTER-755
16+
17+
httpd_start
1618

1719
httpd_wait_until_ready
1820

test/MODCLUSTER-785/testit.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ httpd_remove
1111
rm -f nohup.out
1212

1313
MPC_CONF=${MPC_CONF:-MODCLUSTER-785/mod_proxy_cluster.conf}
14-
MPC_NAME=MODCLUSTER-785 httpd_start
14+
MPC_NAME=MODCLUSTER-785
15+
PORT=9000
1516

17+
httpd_start
1618

1719
# start tomcat1 on 8080
1820
tomcat_start 1
@@ -32,12 +34,12 @@ if [ $? -ne 0 ]; then
3234
fi
3335

3436
# Stop abruptly
35-
tomcat_remove 1
37+
tomcat_kill 1
3638

3739
# it return 503
3840
# make sure we use enough workers
39-
ab -c 10 -n100 http://localhost:8090/app/
40-
http_code=$(curl -s -m 20 -o /dev/null -w "%{http_code}" http://localhost:8090/app/)
41+
ab -c 10 -n 100 http://localhost:8090/app/status.jsp
42+
http_code=$(curl -s -m 20 -o /dev/null -w "%{http_code}" http://localhost:8090/app/status.jsp)
4143
if [ ${http_code} != 503 ]; then
4244
echo "MODCLUSTER-785 Failed! not 503 but ${http_code}"
4345
exit 1
@@ -46,7 +48,8 @@ fi
4648
sleep 15
4749

4850
# start tomcat1 on 8080
49-
tomcat_start 1
51+
tomcat_remove 1
52+
tomcat_start 1
5053

5154
# wait until tomcat1 is in mod_proxy_cluster tables
5255
tomcat_wait_for_n_nodes 1

test/MODCLUSTER-794/testit.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
tomcat_all_remove
77
httpd_remove
88

9+
# due to conflict with proxy's 8090 port we shift tomcats
10+
PORT=9000
911
MPC_CONF=${MPC_CONF:-MODCLUSTER-794/mod_proxy_cluster.conf}
10-
MPC_NAME=MODCLUSTER-794 httpd_start
12+
MPC_NAME=MODCLUSTER-794
13+
httpd_start
1114

12-
for i in {1..20}; do
15+
16+
for i in $(seq 1 20); do
1317
tomcat_start $i
1418
done
1519

@@ -26,5 +30,7 @@ for i in $(seq 1 10); do
2630
sleep 5
2731
done
2832

33+
tomcat_wait_for_n_nodes 20
34+
2935
tomcat_all_remove
3036

test/hangingtests.sh

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,36 @@
55
httpd_remove
66
tomcat_all_remove
77

8+
tomcat_jdbsuspend_prepare() {
9+
# Create files we need
10+
docker exec -i tomcat$1 sh -c 'echo cont > continue.txt; echo exit >> continue.txt'
11+
docker exec -i tomcat$1 sh -c 'echo suspend all > hang.txt; echo exit >> hang.txt'
12+
docker exec -i tomcat$1 sh -c 'jdb -attach 6660 < continue.txt'
13+
}
814

915
# This should suspend the tomcat for ~ 1000 seconds ~ causing it gets removed afterwhile.
10-
jdbsuspend() {
11-
rm -f /tmp/testpipein
12-
mkfifo /tmp/testpipein
13-
rm -f /tmp/testpipeout
14-
mkfifo /tmp/testpipeout
15-
sleep 1000 > /tmp/testpipein &
16-
jdb -attach 6660 < /tmp/testpipein > /tmp/testpipeout &
17-
echo "suspend" > /tmp/testpipein
18-
cat < /tmp/testpipeout &
16+
tomcat_jdbsuspend_start() {
17+
# suspend
18+
docker exec -i tomcat$1 sh -c 'rm -f /tmp/testpipein'
19+
docker exec -i tomcat$1 sh -c 'mkfifo /tmp/testpipein'
20+
docker exec -i tomcat$1 sh -c 'rm -f /tmp/testpipeout'
21+
docker exec -i tomcat$1 sh -c 'mkfifo /tmp/testpipeout'
22+
docker exec -i tomcat$1 sh -c 'sleep 1000 > /tmp/testpipein &'
23+
docker exec -i tomcat$1 sh -c 'jdb -attach 6660 < /tmp/testpipein > /tmp/testpipeout &'
24+
docker exec -i tomcat$1 sh -c 'echo "suspend" > /tmp/testpipein'
25+
docker exec -i tomcat$1 sh -c 'cat < /tmp/testpipeout &'
1926
}
2027

21-
jdbexit() {
22-
cat > /tmp/testpipeout &
23-
echo "exit" > /tmp/testpipein
28+
tomcat_jdbsuspend_exit() {
29+
docker exec -i tomcat$1 sh -c 'cat > /tmp/testpipeout &'
30+
docker exec -i tomcat$1 sh -c 'echo "exit" > /tmp/testpipein'
2431
}
2532

2633
####################################
2734
### S T A R T T E S T S ###
2835
####################################
2936
httpd_start
3037

31-
# Create files we need
32-
cat << EOF > continue.txt
33-
cont
34-
exit
35-
EOF
36-
cat << EOF > hang.txt
37-
suspend all
38-
exit
39-
EOF
40-
4138
# Check that hanging tomcat will be removed
4239
echo "hanging a tomcat checking it is removed after a while no requests"
4340
tomcat_start_two
@@ -46,58 +43,59 @@ tomcat_wait_for_n_nodes 2 || exit 1
4643
# curlloop.sh checks for http://localhost:8090/testapp/test.jsp
4744
docker cp testapp tomcat1:/usr/local/tomcat/webapps
4845
docker cp testapp tomcat2:/usr/local/tomcat/webapps
49-
5046
docker cp setenv.sh tomcat1:/usr/local/tomcat/bin
47+
5148
docker commit tomcat1 ${IMG}-debug
5249
tomcat_remove 1
5350
tomcat_wait_for_n_nodes 1
5451
# Start the node.
5552
IMG=${IMG}-debug tomcat_start 1
5653
sleep 10
57-
docker exec tomcat1 jdb -attach 6660 < continue.txt
54+
tomcat_jdbsuspend_prepare 1
5855
tomcat_wait_for_n_nodes 2 || exit 1
5956
echo "2 tomcat started"
6057
# Hang the node,
6158
# jdb and a pipe to hang the tomcat.
62-
jdbsuspend
59+
tomcat_jdbsuspend_start 1
6360
tomcat_wait_for_n_nodes 1 || exit 1
6461
echo "1 tomcat hanging and gone"
65-
jdbexit
62+
tomcat_jdbsuspend_exit 1
6663
# The tomcat is comming up again
6764
tomcat_wait_for_n_nodes 2 || exit 1
6865
echo "the tomcat is back"
6966

7067
# Same test with requests, make them in a loop
7168
echo "hanging tomcat removed after a while with requests"
7269
sh curlloop.sh 200 000 &
73-
jdbsuspend
70+
tomcat_jdbsuspend_start 1
7471
tomcat_wait_for_n_nodes 1 || exit 1
7572
ps -ef | grep curlloop | grep -v grep
7673
if [ $? -ne 0 ]; then
7774
echo "curlloop.sh FAILED!"
7875
exit 1
7976
fi
8077
ps -ef | grep curlloop | grep -v grep | awk ' { print $2 } ' | xargs kill
81-
jdbexit
78+
tomcat_jdbsuspend_exit 1
8279
# The tomcat is comming up again
8380
tomcat_wait_for_n_nodes 2 || exit 1
8481

8582
# Same test with requets but stop the other tomcat
8683
echo "single hanging tomcat removed after a while with requests"
87-
tomcat_remove 2
84+
# kill because we want to keep it in the DNS records
85+
tomcat_kill 2
8886
tomcat_wait_for_n_nodes 1 || exit 1
89-
jdbsuspend
87+
tomcat_jdbsuspend_start 1
9088
sleep 10
9189
sh curlloop.sh 000 404 503 &
92-
tomcat_wait_for_n_nodes 0 || exit 1
90+
tomcat_wait_for_n_nodes 0 || exit 1
9391
ps -ef | grep curlloop | grep -v grep
9492
if [ $? -ne 0 ]; then
9593
echo "curlloop.sh FAILED!"
9694
exit 1
9795
fi
9896
ps -ef | grep curlloop | grep -v grep | awk ' { print $2 } ' | xargs kill
99-
jdbexit
100-
# The tomcat is comming up again
97+
tomcat_jdbsuspend_exit 1
98+
# The tomcat is coming up again
10199
tomcat_wait_for_n_nodes 1 || exit 1
102100

103101
# Cleanup at the end

test/maintests.sh

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ echotestlabel "sticky: stopping one node and doing requests..."
8989
NODE=$(echo ${NEWCO} | awk -F = '{ print $2 }' | awk -F . '{ print $2 }')
9090
echo $NODE
9191
PORT=$(curl http://localhost:8090/mod_cluster_manager -m 20 | grep Node | grep $NODE | sed 's:)::' | awk -F : '{ print $3 } ')
92-
NAME=$(expr ${PORT} - 8080 + 1)
93-
echo "Will stop tomcat$NAME corresponding to ${NODE} and cookie: ${NEWCO}"
92+
NUMBER=$(expr ${PORT} - 8080 + 1)
9493
CODE="200"
9594
i=0
9695
while [ "$CODE" == "200" ]
@@ -102,8 +101,9 @@ do
102101
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --cookie "${NEWCO}" http://localhost:8090/testapp/test.jsp)
103102
if [ $i -eq 0 ]; then
104103
# stop the tomcat
105-
echo "tomcat${NAME} being stopped"
106-
tomcat_remove $NAME
104+
echo "tomcat${NUMBER} being stopped"
105+
# We're going to kill instead of removal because kill only tomcat proc (keeps the container in DNS)
106+
tomcat_kill $NUMBER
107107
fi
108108
i=$(expr $i + 1)
109109
done
@@ -114,7 +114,8 @@ if [ ${CODE} != "200" ]; then
114114
fi
115115

116116
# Restart the tomcat
117-
tomcat_start ${NAME}
117+
tomcat_remove ${NUMBER}
118+
tomcat_start ${NUMBER}
118119
tomcat_wait_for_n_nodes 2
119120

120121
# Test a keepalived connection finds the 2 webapps on each tomcat
@@ -139,36 +140,36 @@ docker commit tomcat2 ${IMG}-temporary
139140
tomcat_remove 2
140141
tomcat_wait_for_n_nodes 1
141142
# Start the node.
142-
IMG=${IMG}-temporary tomcat_start 2 &
143+
IMG=${IMG}-temporary tomcat_start 2
143144
tomcat_wait_for_n_nodes 2 || exit 1
144-
# Basically curl --header "Host: example.com" http://127.0.0.1:8090/test/test.jsp gives 200
145+
# Basically curl --header "Host: example.com" http://localhost:8090/test/test.jsp gives 200
145146
# in fact the headers are:
146-
# X-Forwarded-For: 127.0.0.1
147+
# X-Forwarded-For: localhost
147148
# X-Forwarded-Host: example.com
148149
# X-Forwarded-Server: fe80::faf4:935b:9dda:2adf
149150
# therefore don't forget ProxyPreserveHost On (otherwise UseAlias On failed...)
150151
#
151-
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --header "Host: example.com" http://127.0.0.1:8090/test/test.jsp)
152+
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --header "Host: example.com" http://localhost:8090/test/test.jsp)
152153
if [ ${CODE} != "200" ]; then
153-
echo "Failed can't rearch webapp at example.com: ${CODE}"
154+
echo "Failed can't reach webapp at example.com: ${CODE}"
154155
exit 1
155156
fi
156-
# Basically curl --header "Host: localhost" http://127.0.0.1:8090/test/test.jsp gives 400
157-
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --header "Host: localhost" http://127.0.0.1:8090/test/test.jsp)
157+
# Basically curl --header "Host: localhost" http://localhost:8090/test/test.jsp gives 400
158+
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --header "Host: localhost" http://localhost:8090/test/test.jsp)
158159
if [ ${CODE} != "404" ]; then
159-
echo "Failed should NOT rearch webapp at localhost: ${CODE}"
160+
echo "Failed should NOT reach webapp at localhost: ${CODE}"
160161
exit 1
161162
fi
162-
# Same using localhost/testapp2 and curl --header "Host: localhost" http://127.0.0.1:8090/testapp2/test.jsp
163-
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --header "Host: localhost" http://127.0.0.1:8090/testapp2/test.jsp)
163+
# Same using localhost/testapp2 and curl --header "Host: localhost" http://localhost:8090/testapp2/test.jsp
164+
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --header "Host: localhost" http://localhost:8090/testapp2/test.jsp)
164165
if [ ${CODE} != "200" ]; then
165-
echo "Failed can't rearch webapp at localhost: ${CODE}"
166+
echo "Failed can't reach webapp at localhost: ${CODE}"
166167
exit 1
167168
fi
168-
# Basically curl --header "Host: example.com" http://127.0.0.1:8090/testapp2/test.jsp gives 400
169-
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --header "Host: example.com" http://127.0.0.1:8090/testapp2/test.jsp)
169+
# Basically curl --header "Host: example.com" http://localhost:8090/testapp2/test.jsp gives 400
170+
CODE=$(curl -s -o /dev/null -m 20 -w "%{http_code}" --header "Host: example.com" http://localhost:8090/testapp2/test.jsp)
170171
if [ ${CODE} != "404" ]; then
171-
echo "Failed should NOT rearch webapp at localhost: ${CODE}"
172+
echo "Failed should NOT reach webapp at localhost: ${CODE}"
172173
exit 1
173174
fi
174175

0 commit comments

Comments
 (0)