|
| 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