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

Commit 8b45f51

Browse files
committed
Add node registerCycle. Suicide nodes on selenium exited node.
1 parent f77893c commit 8b45f51

File tree

9 files changed

+193
-12
lines changed

9 files changed

+193
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ Note image ids also change after scm-source.json has being updated which trigger
99

1010
## TBD_DOCKER_TAG
1111
+ Date: TBD_DATE
12-
+ TBD_COMMIT_MSG
12+
+ Add node -registerCycle customization via SELENIUM_NODE_REGISTER_CYCLE
13+
+ Suicide nodes on selenium exited node.
14+
+ WIP to add OSX support #111 #110
1315
+ Image tag details:
1416
+ Selenium: vTBD_SELENIUM_VERSION (TBD_SELENIUM_REVISION)
1517
+ Chrome stable: TBD_CHROME_STABLE

CONTRIBUTING.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ For pull requests or local commits:
88
open ./images/grid_console.png #to verify the versions are correct
99
git checkout ./images/grid_console.png && open ./videos/chrome/test.mkv
1010
travis lint #if you changed .travis.yml
11-
git checkout -b tmp-2.53.1e #name your branch according to your changes
11+
git checkout -b tmp-2.53.1f #name your branch according to your changes
1212
#git add ... git commit ... git push ... open pull request
1313

1414
For repository owners only:
1515

16-
git commit -m "Add OSX support. Closes #111 #110"
16+
git commit -m "Add node registerCycle. Suicide nodes on selenium exited node."
1717
git tag -d latest #tag latest will be updated from TravisCI
18-
git tag 2.53.1e && git push origin tmp-2.53.1e && git push --tags
18+
git tag 2.53.1f && git push origin tmp-2.53.1f && git push --tags
1919

2020
-- Wait for Travis to pass OK
2121
-- Make sure changes got merged into master by elgalubot
2222

23-
git checkout master && git pull && git branch -d tmp-2.53.1e && git push origin --delete tmp-2.53.1e
23+
git checkout master && git pull && git branch -d tmp-2.53.1f && git push origin --delete tmp-2.53.1f
2424

2525
-- Re-add TBD_* section in CHANGELOG.md starting with TBD_DOCKER_TAG
2626
-- Upgrade release tag in github.com with latest CHANGELOG.md
@@ -37,9 +37,9 @@ Keep certain bins if chrome version changed for example:
3737
## Retry
3838
Failed in Travis? retry
3939

40-
git tag -d 2.53.1e && git push origin :2.53.1e
40+
git tag -d 2.53.1f && git push origin :2.53.1f
4141
#git add ...
42-
git commit --amend && git tag 2.53.1e && git push --force origin tmp-2.53.1e && git push --tags
42+
git commit --amend && git tag 2.53.1f && git push --force origin tmp-2.53.1f && git push --tags
4343

4444
## Docker push from Travis CI
4545
Travis [steps](https://docs.travis-ci.com/user/docker/#Pushing-a-Docker-Image-to-a-Registry) involve `docker login` and docker credentials encryptions.

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,7 @@ ENV FIREFOX_VERSION="${FF_VER}" \
964964
SELENIUM_HUB_PARAMS="" \
965965
SELENIUM_NODE_PARAMS="" \
966966
SELENIUM_NODE_PROXY_PARAMS="" \
967+
SELENIUM_NODE_REGISTER_CYCLE="" \
967968
# To taggle issue #58 see https://goo.gl/fz6RTu
968969
CHROME_ARGS="--no-sandbox" \
969970
# e.g. CHROME_ARGS="--no-sandbox --ignore-certificate-errors" \

bin/entry.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ else
177177
export CUSTOM_SELENIUM_NODE_PROXY_PARAMS=""
178178
fi
179179

180+
# Allow node's -registerCycle customizations without having to use SELENIUM_NODE_PARAMS
181+
if [ "${SELENIUM_NODE_REGISTER_CYCLE}" != "" ]; then
182+
export CUSTOM_SELENIUM_NODE_REGISTER_CYCLE="-registerCycle ${SELENIUM_NODE_REGISTER_CYCLE}"
183+
else
184+
export CUSTOM_SELENIUM_NODE_REGISTER_CYCLE=""
185+
fi
186+
180187
#----------------------------------------
181188
# Remove lock files, thanks @garagepoort
182189
# clear_x_locks.sh

selenium-node-chrome/bin/start-selenium-node-chrome.sh

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
# set -e: exit asap if a command exits with a non-zero status
44
set -e
55

6+
echoerr() {
7+
cat <<< "$@" 1>&2;
8+
}
9+
610
# Wait for this process dependencies
711
timeout --foreground ${WAIT_TIMEOUT} wait-xvfb.sh
812
timeout --foreground ${WAIT_TIMEOUT} wait-xmanager.sh
@@ -27,7 +31,37 @@ java ${JAVA_OPTS} \
2731
-nodePolling ${SEL_NODEPOLLING_MS} \
2832
-Dwebdriver.chrome.driver="${SEL_HOME}/chromedriver" \
2933
${SELENIUM_NODE_PARAMS} \
30-
${CUSTOM_SELENIUM_NODE_PROXY_PARAMS}
34+
${CUSTOM_SELENIUM_NODE_PROXY_PARAMS} \
35+
${CUSTOM_SELENIUM_NODE_REGISTER_CYCLE} \
36+
&
37+
NODE_PID=$!
38+
39+
function shutdown {
40+
echo "-- INFO: Shutting down Chrome NODE gracefully..."
41+
kill -SIGINT ${NODE_PID} || true
42+
kill -SIGTERM ${NODE_PID} || true
43+
kill -SIGKILL ${NODE_PID} || true
44+
wait ${NODE_PID}
45+
echo "-- INFO: Chrome node shutdown complete."
46+
# First stop video recording because it needs some time to flush it
47+
supervisorctl -c /etc/supervisor/supervisord.conf stop video-rec || true
48+
killall supervisord
49+
exit 0
50+
}
51+
52+
function trappedFn {
53+
echo "-- INFO: Trapped SIGTERM/SIGINT on Chrome NODE"
54+
shutdown
55+
}
56+
# Run function shutdown() when this process a killer signal
57+
trap trappedFn SIGTERM SIGINT SIGKILL
58+
59+
# tells bash to wait until child processes have exited
60+
wait ${NODE_PID}
61+
echo "-- INFO: Passed after wait java Chrome node"
62+
63+
# Always shutdown if the node dies
64+
shutdown
3165

3266
# Note to double pipe output and keep this process logs add at the end:
3367
# 2>&1 | tee $SELENIUM_LOG

selenium-node-firefox/bin/start-selenium-node-firefox.sh

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
# set -e: exit asap if a command exits with a non-zero status
44
set -e
55

6+
echoerr() {
7+
cat <<< "$@" 1>&2;
8+
}
9+
610
# Wait for this process dependencies
711
timeout --foreground ${WAIT_TIMEOUT} wait-xvfb.sh
812
timeout --foreground ${WAIT_TIMEOUT} wait-xmanager.sh
@@ -27,7 +31,37 @@ java ${JAVA_OPTS} \
2731
-cleanUpCycle ${SEL_CLEANUPCYCLE_MS} \
2832
-nodePolling ${SEL_NODEPOLLING_MS} \
2933
${SELENIUM_NODE_PARAMS} \
30-
${CUSTOM_SELENIUM_NODE_PROXY_PARAMS}
34+
${CUSTOM_SELENIUM_NODE_PROXY_PARAMS} \
35+
${CUSTOM_SELENIUM_NODE_REGISTER_CYCLE} \
36+
&
37+
NODE_PID=$!
38+
39+
function shutdown {
40+
echo "-- INFO: Shutting down Firefox NODE gracefully..."
41+
kill -SIGINT ${NODE_PID} || true
42+
kill -SIGTERM ${NODE_PID} || true
43+
kill -SIGKILL ${NODE_PID} || true
44+
wait ${NODE_PID}
45+
echo "-- INFO: Firefox node shutdown complete."
46+
# First stop video recording because it needs some time to flush it
47+
supervisorctl -c /etc/supervisor/supervisord.conf stop video-rec || true
48+
killall supervisord
49+
exit 0
50+
}
51+
52+
function trappedFn {
53+
echo "-- INFO: Trapped SIGTERM/SIGINT on Firefox NODE"
54+
shutdown
55+
}
56+
# Run function shutdown() when this process a killer signal
57+
trap trappedFn SIGTERM SIGINT SIGKILL
58+
59+
# tells bash to wait until child processes have exited
60+
wait ${NODE_PID}
61+
echo "-- INFO: Passed after wait java Firefox node"
62+
63+
# Always shutdown if the node dies
64+
shutdown
3165

3266
# Note to double pipe output and keep this process logs add at the end:
3367
# 2>&1 | tee $SELENIUM_LOG

test/script

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set -xe
77
./test/script_bats
88
./test/script_scenario_basic
99
./test/script_scenario_restart
10-
# ./test/script_scenario_node_dies
10+
./test/script_scenario_node_dies
1111
./test/script_scenario_compose_1_1
1212
./test/script_scenario_compose_N_N
1313
./test/script_archive

test/script_scenario_compose_N_N

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ set -xe
1111
export SELENIUM_HUB_PORT="4444"
1212

1313
if [ "${TRAVIS}" = "true" ]; then
14-
export NUM_NODES=2 PARAL_TESTS=2 WAIT_ALL_DONE="390s" SLEEP_TIME=15
14+
export NUM_NODES=2 PARAL_TESTS=2 WAIT_ALL_DONE="390s" SLEEP_TIME=17
1515
else
1616
# My local laptop has more power so hit it harder
17-
export NUM_NODES=6 PARAL_TESTS=6 WAIT_ALL_DONE="90s" SLEEP_TIME=5
17+
export NUM_NODES=6 PARAL_TESTS=6 WAIT_ALL_DONE="90s" SLEEP_TIME=10
1818
fi
1919

2020
./test/compose-test.sh

test/script_scenario_node_dies

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/usr/bin/env bash
2+
3+
echo "#======================================================"
4+
echo "# Scenario 3 [node_dies]: Node dies then container dies"
5+
echo "#======================================================"
6+
7+
###################
8+
# Echo with Error #
9+
###################
10+
# echo fn that outputs to stderr http://stackoverflow.com/a/2990533/511069
11+
echoerr() {
12+
cat <<< "$@" 1>&2;
13+
}
14+
15+
########################
16+
# Print error and exit #
17+
########################
18+
die () {
19+
echoerr "ERROR: $1"
20+
# if $2 is defined AND NOT EMPTY, use $2; otherwise, set to "160"
21+
errnum=${2-160}
22+
exit $errnum
23+
}
24+
25+
# set -e: exit asap if a command exits with a non-zero status
26+
# set -x: print each command right before it is executed
27+
set -xe
28+
29+
export SELENIUM_NODE_CH_PORT=5757 \
30+
SELENIUM_NODE_FF_PORT=6868 \
31+
SHUTDOWN_END_POINT="selenium-server/driver/?cmd=shutDownSeleniumServer" \
32+
NODE_SUICIDE_WAIT_TIME=20
33+
34+
echo "#================================================="
35+
echo "# Scenario 3a [node_dies]: Dies by killing Chrome"
36+
echo "#================================================="
37+
38+
# Ensure clean env
39+
docker rm -vf mynodes || true
40+
41+
# Create container for Chrome
42+
docker run --name=mynodes -d \
43+
-e FIREFOX=false \
44+
-e SELENIUM_NODE_CH_PORT -p ${SELENIUM_NODE_CH_PORT}:${SELENIUM_NODE_CH_PORT} \
45+
-v /dev/shm:/dev/shm \
46+
selenium
47+
48+
docker exec mynodes wait_all_done 40s
49+
docker exec mynodes errors || true
50+
docker logs mynodes
51+
52+
# Basic checkup
53+
docker exec -t mynodes selenium_test chrome
54+
docker exec mynodes errors || true
55+
56+
if curl -s "http://localhost:${SELENIUM_NODE_CH_PORT}/${SHUTDOWN_END_POINT}" | grep "OKOK"; then
57+
# The container should have been removed
58+
sleep ${NODE_SUICIDE_WAIT_TIME}
59+
if docker rm mynodes; then
60+
echo "Chrome 3a PASSED"
61+
else
62+
die "Test failed for Chrome at $0 during docker rm mynodes"
63+
fi
64+
else
65+
echoerr "Expected OKOK at $0 for Chrome but got something else"
66+
curl "http://localhost:${SELENIUM_NODE_CH_PORT}/${SHUTDOWN_END_POINT}"
67+
die "Test failed for Chrome at $0 during curl"
68+
fi
69+
70+
echo "#================================================="
71+
echo "# Scenario 3b [node_dies]: Dies by killing Firefox"
72+
echo "#================================================="
73+
74+
# Ensure clean env
75+
docker rm -vf mynodes || true
76+
77+
# Create container for Firefox
78+
docker run --name=mynodes -d \
79+
-e CHROME=false \
80+
-e SELENIUM_NODE_FF_PORT -p ${SELENIUM_NODE_FF_PORT}:${SELENIUM_NODE_FF_PORT} \
81+
selenium
82+
83+
docker exec mynodes wait_all_done 40s
84+
docker exec mynodes errors || true
85+
docker logs mynodes
86+
87+
# Basic checkup
88+
docker exec -t mynodes selenium_test firefox
89+
docker exec mynodes errors || true
90+
91+
if curl -s "http://localhost:${SELENIUM_NODE_FF_PORT}/${SHUTDOWN_END_POINT}" | grep "OKOK"; then
92+
# The container should have been removed
93+
sleep ${NODE_SUICIDE_WAIT_TIME}
94+
if docker rm mynodes; then
95+
echo "Firefox 3a PASSED"
96+
else
97+
die "Test failed for Firefox at $0 during docker rm mynodes"
98+
fi
99+
else
100+
echoerr "Expected OKOK at $0 for Firefox but got something else"
101+
curl "http://localhost:${SELENIUM_NODE_FF_PORT}/${SHUTDOWN_END_POINT}"
102+
die "Test failed for Firefox at $0 during curl"
103+
fi

0 commit comments

Comments
 (0)