Skip to content
This repository was archived by the owner on Jun 30, 2021. It is now read-only.

Commit a726a36

Browse files
committed
Chore fixes + reseach race cond
1 parent 536e506 commit a726a36

File tree

13 files changed

+198
-133
lines changed

13 files changed

+198
-133
lines changed

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -933,14 +933,16 @@ ENV FIREFOX_VERSION="${FF_VER}" \
933933
BIN_UTILS="/usr/bin" \
934934
# JVM uses only 1/4 of system memory by default
935935
MEM_JAVA_PERCENT=80 \
936+
# Max amount of time to wait on Xvfb or Xmanager while retrying
937+
WAIT_FOREGROUND_RETRY="1s" \
936938
# Max amount of time to wait for other processes dependencies
937-
WAIT_TIMEOUT="15s" \
939+
WAIT_TIMEOUT="25s" \
938940
SCREEN_WIDTH=1900 \
939941
SCREEN_HEIGHT=1480 \
940942
SCREEN_MAIN_DEPTH=24 \
941943
SCREEN_SUB_DEPTH=32 \
942944
# Display number; see entry.sh for $DISPLAY
943-
DISP_N="${DEFAULT_DISP_N}" \
945+
DISP_N="-1" \
944946
# Maximum searches for a free DISPLAY number
945947
MAX_DISPLAY_SEARCH=99 \
946948
SCREEN_NUM=0 \
@@ -1112,8 +1114,6 @@ ENV FIREFOX_VERSION="${FF_VER}" \
11121114
#================
11131115
ADD bin/* ${BIN_UTILS}/
11141116
ADD **/bin/* ${BIN_UTILS}/
1115-
ADD utils/bin/selenium-grep.sh /usr/bin/errors
1116-
ADD xterm/bin/timeout-wait-xterm.sh /usr/bin/wait_all_done
11171117
ADD host-scripts/* /host-scripts/
11181118
ADD test/* /test/
11191119
ADD test/run_test.sh /usr/bin/run_test

bin/entry.sh

Lines changed: 96 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,97 @@ if [ "${BSTACK_TUNNEL}" = "true" ]; then
9292
export SUPERVISOR_REQUIRED_SRV_LIST="${SUPERVISOR_REQUIRED_SRV_LIST}|browserstack"
9393
fi
9494

95+
if [ "${SELENIUM_HUB_PORT}" = "" ]; then
96+
echo "FATAL: SELENIUM_HUB_PORT is empty but should be a number" 1>&2
97+
exit 120
98+
fi
99+
100+
# TODO: Remove this duplicated logic
101+
if [ "${SELENIUM_HUB_PORT}" = "0" ]; then
102+
export SELENIUM_HUB_PORT=$(get_unused_port)
103+
elif [ "${PICK_ALL_RANDMON_PORTS}" = "true" ]; then
104+
# User want to pick random ports but may also want to fix some others
105+
if [ "${SELENIUM_HUB_PORT}" = "${DEFAULT_SELENIUM_HUB_PORT}" ]; then
106+
export SELENIUM_HUB_PORT=$(get_unused_port)
107+
fi
108+
fi
109+
110+
if [ "${SELENIUM_NODE_CH_PORT}" = "0" ]; then
111+
export SELENIUM_NODE_CH_PORT=$(get_unused_port)
112+
elif [ "${PICK_ALL_RANDMON_PORTS}" = "true" ]; then
113+
# User want to pick random ports but may also want to fix some others
114+
if [ "${SELENIUM_NODE_CH_PORT}" = "${DEFAULT_SELENIUM_NODE_CH_PORT}" ]; then
115+
export SELENIUM_NODE_CH_PORT=$(get_unused_port)
116+
fi
117+
fi
118+
119+
if [ "${SELENIUM_NODE_FF_PORT}" = "0" ]; then
120+
export SELENIUM_NODE_FF_PORT=$(get_unused_port)
121+
elif [ "${PICK_ALL_RANDMON_PORTS}" = "true" ]; then
122+
# User want to pick random ports but may also want to fix some others
123+
if [ "${SELENIUM_NODE_FF_PORT}" = "${DEFAULT_SELENIUM_NODE_FF_PORT}" ]; then
124+
export SELENIUM_NODE_FF_PORT=$(get_unused_port)
125+
fi
126+
fi
127+
128+
if [ "${VNC_PORT}" = "0" ]; then
129+
export VNC_PORT=$(get_unused_port)
130+
elif [ "${PICK_ALL_RANDMON_PORTS}" = "true" ]; then
131+
# User want to pick random ports but may also want to fix some others
132+
if [ "${VNC_PORT}" = "${DEFAULT_VNC_PORT}" ]; then
133+
export VNC_PORT=$(get_unused_port)
134+
fi
135+
fi
136+
137+
if [ "${NOVNC_PORT}" = "0" ]; then
138+
export NOVNC_PORT=$(get_unused_port)
139+
elif [ "${PICK_ALL_RANDMON_PORTS}" = "true" ]; then
140+
# User want to pick random ports but may also want to fix some others
141+
if [ "${NOVNC_PORT}" = "${DEFAULT_NOVNC_PORT}" ]; then
142+
export NOVNC_PORT=$(get_unused_port)
143+
fi
144+
fi
145+
146+
if [ "${SSHD_PORT}" = "0" ]; then
147+
export SSHD_PORT=$(get_unused_port)
148+
elif [ "${PICK_ALL_RANDMON_PORTS}" = "true" ]; then
149+
# User want to pick random ports but may also want to fix some others
150+
if [ "${SSHD_PORT}" = "${DEFAULT_SSHD_PORT}" ]; then
151+
export SSHD_PORT=$(get_unused_port)
152+
fi
153+
fi
154+
155+
if [ "${SAUCE_LOCAL_SEL_PORT}" = "0" ]; then
156+
export SAUCE_LOCAL_SEL_PORT=$(get_unused_port)
157+
elif [ "${PICK_ALL_RANDMON_PORTS}" = "true" ]; then
158+
# User want to pick random ports but may also want to fix some others
159+
if [ "${SAUCE_LOCAL_SEL_PORT}" = "${DEFAULT_SAUCE_LOCAL_SEL_PORT}" ]; then
160+
export SAUCE_LOCAL_SEL_PORT=$(get_unused_port)
161+
fi
162+
fi
163+
164+
if [ "${SUPERVISOR_HTTP_PORT}" = "0" ]; then
165+
export SUPERVISOR_HTTP_PORT=$(get_unused_port)
166+
elif [ "${PICK_ALL_RANDMON_PORTS}" = "true" ]; then
167+
# User want to pick random ports but may also want to fix some others
168+
if [ "${SUPERVISOR_HTTP_PORT}" = "${DEFAULT_SUPERVISOR_HTTP_PORT}" ]; then
169+
export SUPERVISOR_HTTP_PORT=$(get_unused_port)
170+
fi
171+
fi
172+
173+
#----------------------------------------
174+
# Remove lock files, thanks @garagepoort
175+
clear_x_locks.sh
176+
177+
#--------------------------------
178+
# Improve etc/hosts and fix dirs
179+
improve_etc_hosts.sh
180+
fix_dirs.sh
181+
182+
#-------------------------
183+
# Docker alongside docker
184+
docker_alongside_docker.sh
185+
95186
#----------------------------------------
96187
# Fix autoassigned ports
97188
#----------------------------------------
@@ -109,13 +200,13 @@ function get_free_display() {
109200
# -s file is not zero size
110201
if [ -s /tmp/netstatX11.log ]; then
111202
# important: while loops are executed in a subshell
112-
# var assignments will be lost unless using <<<
113-
# while true ; do
114-
# let find_display_num=${find_display_num}+1
203+
# var assignments will be lost unless using <<<
204+
# using 11.0 12.3 1.8 and so on didn't work, left as a reference
205+
# local pythonCmd="from random import shuffle;list1 = list(range($MAX_DISPLAY_SEARCH));shuffle(list1);list2 = [x/10 for x in list1];str_res = ' '.join(str(e) for e in list2);print (str_res)"
115206
local pythonCmd="from random import shuffle;list1 = list(range($MAX_DISPLAY_SEARCH));shuffle(list1);print (' '.join(str(e) for e in list1))"
116207
local displayNums=$(python -c "${pythonCmd}")
117208
# Always find a free DISPLAY port starting with current DISP_N if it was provided
118-
[ "${DISP_N}" != "-1" ] && displayNums=" ${DISP_N} ${displayNums}"
209+
[ "${DISP_N}" != "-1" ] && displayNums="${DISP_N} ${displayNums}"
119210
IFS=' ' read -r -a arrayDispNums <<< "$displayNums"
120211
for find_display_num in ${arrayDispNums[@]}; do
121212
# read -r Do not treat a backslash character in any special way.
@@ -163,7 +254,6 @@ function start_xvfb() {
163254
${XVFB_CLI_OPTS_TCP} ${XVFB_CLI_OPTS_BASE} ${XVFB_CLI_OPTS_EXT} \
164255
1> "${LOGS_DIR}/xvfb-tryouts-stdout.log" \
165256
2> "${LOGS_DIR}/xvfb-tryouts-stderr.log" &
166-
echo "$!" > /tmp/xvfb.pid
167257
}
168258

169259
if [ ! -z "${XE_DISP_NUM}" ]; then
@@ -184,7 +274,7 @@ else
184274
if ! start_xvfb; then
185275
echo "-- WARN: start_xvfb() failed!" 1>&3
186276
fi
187-
if timeout --foreground "1s" wait-xvfb.sh &> "${LOGS_DIR}/wait-xvfb.log"; then
277+
if timeout --foreground "${WAIT_FOREGROUND_RETRY}" wait-xvfb.sh &> "${LOGS_DIR}/wait-xvfb-stdout.log"; then
188278
break
189279
else
190280
echo "-- WARN: wait-xvfb.sh failed! for DISPLAY=${DISPLAY}" 1>&3
@@ -202,102 +292,11 @@ fi
202292

203293

204294
# Validations
205-
if [ "${SELENIUM_HUB_PORT}" = "" ]; then
206-
echo "FATAL: SELENIUM_HUB_PORT is empty but should be a number" 1>&2
207-
exit 120
208-
fi
209-
210295
if [ ":$DISP_N" != "${DISPLAY}" ]; then
211296
echo "FATAL: DISP_N '${DISP_N}' doesn't match DISPLAY '${DISPLAY}'" 1>&2
212297
exit 122
213298
fi
214299

215-
# TODO: Remove this duplicated logic
216-
if [ "${SELENIUM_HUB_PORT}" = "0" ]; then
217-
export SELENIUM_HUB_PORT=$(get_unused_port)
218-
elif [ "${PICK_ALL_RANDMON_PORTS}" = "true" ]; then
219-
# User want to pick random ports but may also want to fix some others
220-
if [ "${SELENIUM_HUB_PORT}" = "${DEFAULT_SELENIUM_HUB_PORT}" ]; then
221-
export SELENIUM_HUB_PORT=$(get_unused_port)
222-
fi
223-
fi
224-
225-
if [ "${SELENIUM_NODE_CH_PORT}" = "0" ]; then
226-
export SELENIUM_NODE_CH_PORT=$(get_unused_port)
227-
elif [ "${PICK_ALL_RANDMON_PORTS}" = "true" ]; then
228-
# User want to pick random ports but may also want to fix some others
229-
if [ "${SELENIUM_NODE_CH_PORT}" = "${DEFAULT_SELENIUM_NODE_CH_PORT}" ]; then
230-
export SELENIUM_NODE_CH_PORT=$(get_unused_port)
231-
fi
232-
fi
233-
234-
if [ "${SELENIUM_NODE_FF_PORT}" = "0" ]; then
235-
export SELENIUM_NODE_FF_PORT=$(get_unused_port)
236-
elif [ "${PICK_ALL_RANDMON_PORTS}" = "true" ]; then
237-
# User want to pick random ports but may also want to fix some others
238-
if [ "${SELENIUM_NODE_FF_PORT}" = "${DEFAULT_SELENIUM_NODE_FF_PORT}" ]; then
239-
export SELENIUM_NODE_FF_PORT=$(get_unused_port)
240-
fi
241-
fi
242-
243-
if [ "${VNC_PORT}" = "0" ]; then
244-
export VNC_PORT=$(get_unused_port)
245-
elif [ "${PICK_ALL_RANDMON_PORTS}" = "true" ]; then
246-
# User want to pick random ports but may also want to fix some others
247-
if [ "${VNC_PORT}" = "${DEFAULT_VNC_PORT}" ]; then
248-
export VNC_PORT=$(get_unused_port)
249-
fi
250-
fi
251-
252-
if [ "${NOVNC_PORT}" = "0" ]; then
253-
export NOVNC_PORT=$(get_unused_port)
254-
elif [ "${PICK_ALL_RANDMON_PORTS}" = "true" ]; then
255-
# User want to pick random ports but may also want to fix some others
256-
if [ "${NOVNC_PORT}" = "${DEFAULT_NOVNC_PORT}" ]; then
257-
export NOVNC_PORT=$(get_unused_port)
258-
fi
259-
fi
260-
261-
if [ "${SSHD_PORT}" = "0" ]; then
262-
export SSHD_PORT=$(get_unused_port)
263-
elif [ "${PICK_ALL_RANDMON_PORTS}" = "true" ]; then
264-
# User want to pick random ports but may also want to fix some others
265-
if [ "${SSHD_PORT}" = "${DEFAULT_SSHD_PORT}" ]; then
266-
export SSHD_PORT=$(get_unused_port)
267-
fi
268-
fi
269-
270-
if [ "${SAUCE_LOCAL_SEL_PORT}" = "0" ]; then
271-
export SAUCE_LOCAL_SEL_PORT=$(get_unused_port)
272-
elif [ "${PICK_ALL_RANDMON_PORTS}" = "true" ]; then
273-
# User want to pick random ports but may also want to fix some others
274-
if [ "${SAUCE_LOCAL_SEL_PORT}" = "${DEFAULT_SAUCE_LOCAL_SEL_PORT}" ]; then
275-
export SAUCE_LOCAL_SEL_PORT=$(get_unused_port)
276-
fi
277-
fi
278-
279-
if [ "${SUPERVISOR_HTTP_PORT}" = "0" ]; then
280-
export SUPERVISOR_HTTP_PORT=$(get_unused_port)
281-
elif [ "${PICK_ALL_RANDMON_PORTS}" = "true" ]; then
282-
# User want to pick random ports but may also want to fix some others
283-
if [ "${SUPERVISOR_HTTP_PORT}" = "${DEFAULT_SUPERVISOR_HTTP_PORT}" ]; then
284-
export SUPERVISOR_HTTP_PORT=$(get_unused_port)
285-
fi
286-
fi
287-
288-
#----------------------------------------
289-
# Remove lock files, thanks @garagepoort
290-
clear_x_locks.sh
291-
292-
#--------------------------------
293-
# Improve etc/hosts and fix dirs
294-
improve_etc_hosts.sh
295-
fix_dirs.sh
296-
297-
#-------------------------
298-
# Docker alongside docker
299-
docker_alongside_docker.sh
300-
301300
#------------------
302301
# Fix running user
303302
#------------------

docs/docker-compose.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Scale up and down the nodes by using [docker-compose](https://docs.docker.com/co
44
docker-compose --version #=> version 1.7.1, build 0a9ab35
55

66
## Usage
7-
Either clone this repository or download the files [docker-compose.yml](../docker-compose.yml) using `wget`
7+
Either clone this repository or download the file [docker-compose.yml](../docker-compose.yml) using `wget`
88

99
wget -nv "https://raw.githubusercontent.com/elgalu/docker-selenium/master/docker-compose.yml"
1010

@@ -15,9 +15,9 @@ Either start with `docker-compose up` and `scale` later or scale directly and ru
1515

1616
Wait until the grid starts properly before starting the tests _(Optional but recommended)_
1717

18-
docker exec selenium_firefox_5 wait_all_done 30s
18+
docker-compose -p selenium exec -T --index=3 chrome wait_all_done 30s
1919

2020
### Cleanup
2121
The `down` compose command stops and remove containers, networks, volumes, and images created by `up` or `scale`
2222

23-
docker-compose down
23+
docker-compose -p selenium down

host-scripts/wait-docker-selenium.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ else
4747
bash -c 'tail --lines=${TAIL_LOG_LINES} /var/log/cont/*' || true
4848
echo "" && echo "" && echo "==> errors <=="
4949
docker exec ${CONTAINER_ID} \
50-
bash -c 'selenium-grep.sh' || true
50+
bash -c 'errors' || true
5151

5252
die "
5353
Your docker-selenium didn't start properly.

supervisor/bin/run-supervisord.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ shutdown () {
2828
if [ "$(cat ${DOCKER_SELENIUM_STATUS})" = "failed" ]; then
2929
tail --lines=${TAIL_LOG_LINES} /var/log/cont/*
3030
echo "" && echo "" && echo "==> errors <=="
31-
selenium-grep.sh
31+
errors
3232

3333
if [ "${DISABLE_ROLLBACK}" = "true" ]; then
3434
echo ""
3535
echo "DEBUGGING: to find out what happened please analyze logs or run"
36-
echo " selenium-grep.sh"
36+
echo " errors"
3737
echo ""
3838

3939
exec bash

test/compose-test.sh

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,58 @@ die () {
2121
[ -z "${NUM_NODES}" ] && die "Required env var NUM_NODES"
2222
[ -z "${PARAL_TESTS}" ] && die "Required env var PARAL_TESTS"
2323
[ -z "${SELENIUM_HUB_PORT}" ] && die "Required env var SELENIUM_HUB_PORT"
24-
[ -z "${WAIT_TIMEOUT}" ] && export WAIT_TIMEOUT="15s"
2524
[ -z "${WAIT_ALL_DONE}" ] && export WAIT_ALL_DONE="40s"
2625

2726
# Compose up!
2827
docker-compose -p selenium scale hub=1 chrome=${NUM_NODES} firefox=${NUM_NODES}
2928

29+
# FIXME: We still need to wait a bit because the nodes registration is not
30+
# being waited on wait_all_done script :(
31+
# mabe related to issue #83
32+
sleep 3
33+
[ "${TRAVIS}" = "true" ] && sleep 3
34+
3035
# Wait then show errors, if any
31-
docker exec selenium_hub_1 wait_all_done ${WAIT_ALL_DONE}
32-
docker exec selenium_hub_1 errors || true
36+
if ! docker exec selenium_hub_1 wait_all_done ${WAIT_ALL_DONE}; then
37+
docker exec selenium_hub_1 errors || true
38+
docker-compose -p selenium logs hub
39+
die "Failed to start the Hub"
40+
fi
41+
3342
for i in $(seq 1 ${NUM_NODES}); do
34-
docker exec selenium_chrome_${NUM_NODES} wait_all_done ${WAIT_ALL_DONE}
35-
docker exec selenium_chrome_${i} errors || true
36-
docker exec selenium_firefox_${NUM_NODES} wait_all_done ${WAIT_ALL_DONE}
37-
docker exec selenium_firefox_${i} errors || true
43+
if ! docker-compose -p selenium exec --index ${i} chrome wait_all_done ${WAIT_ALL_DONE}; then
44+
docker logs selenium_chrome_${i}
45+
docker-compose -p selenium exec --index ${i} chrome errors || true
46+
die "Failed to start Node chrome ${i}"
47+
fi
48+
if ! docker-compose -p selenium exec --index ${i} firefox wait_all_done ${WAIT_ALL_DONE}; then
49+
docker logs selenium_firefox_${i}
50+
docker-compose -p selenium exec --index ${i} firefox errors || true
51+
die "Failed to start Node firefox ${i}"
52+
fi
3853
done
3954

4055
# FIXME: We still need to wait a bit because the nodes registration is not
4156
# being waited on wait_all_done script :(
4257
# mabe related to issue #83
43-
sleep 5
58+
sleep 4
59+
[ "${TRAVIS}" = "true" ] && sleep 4
4460

4561
# Tests can run anywere, in the hub, in the host, doesn't matter
4662
for i in $(seq 1 ${PARAL_TESTS}); do
63+
# Docker-ompose exec is giving me error:
64+
# in dockerpty/io.py", line 42, in set_blocking
65+
# ValueError: file descriptor cannot be a negative integer (-1)
66+
# docker-compose -p selenium exec --index 1 hub run_test &
4767
docker exec -t selenium_hub_1 run_test &
4868
done
4969

70+
# sleep a moment to let the UI tests start
71+
sleep 4
72+
[ "${TRAVIS}" = "true" ] && sleep 4
73+
5074
# not so verbose from here
51-
set -e +x
75+
set +x
5276

5377
# http://jeremy.zawodny.com/blog/archives/010717.html
5478
FAIL_COUNT=0

0 commit comments

Comments
 (0)