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

Commit a3d723e

Browse files
committed
Add script_scenario_zalenium for Zalenium integration tests
1 parent 9781578 commit a3d723e

File tree

7 files changed

+418
-2
lines changed

7 files changed

+418
-2
lines changed

.travis.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
# Travis requires us to pick a language else it will pick Ruby by default.
33
# Let's choose a lightweight base image then we provide our own build tools.
44
# Note: `language: generic` was failing in OSX so in that case you can use language: c
5-
language: generic
5+
# UPDATE: Switching to python as we want to run Zalenium tests from the host
6+
language: python
7+
python:
8+
- "3.6"
69

710
sudo: required
811

@@ -60,6 +63,11 @@ jobs:
6063
- travis_retry ./test/before_install_pull
6164
- travis_retry ./test/script_scenario_compose_N_N
6265

66+
- env: test=Zalenium
67+
script:
68+
- travis_retry ./test/before_install_pull
69+
- travis_retry ./test/script_scenario_zalenium
70+
6371
- stage: Push Image (only with a tag) & Git push
6472
script:
6573
- travis_retry ./test/before_install_pull

test/before_install_pull

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ if [[ ${TRAVIS_PULL_REQUEST_SLUG} != "" && \
2828
else
2929
docker pull elgalu/build_selenium:${TRAVIS_BUILD_NUMBER}
3030
docker tag elgalu/build_selenium:${TRAVIS_BUILD_NUMBER} selenium:latest
31+
docker tag elgalu/build_selenium:${TRAVIS_BUILD_NUMBER} elgalu/selenium:latest
3132
fi
3233

3334
docker images selenium

test/parallel.sh

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/usr/bin/env bash
2+
3+
# Usage
4+
# bash parallel.sh {browser} {threads} {test-per-thread=5}
5+
# bash parallel.sh chrome 2
6+
# bash parallel.sh firefox 2
7+
# time ( VIDEO=true bash parallel.sh hybrid 4 )
8+
# VIDEO=true bash parallel.sh hybrid 2
9+
10+
set -e
11+
12+
echoerr() { printf "%s\n" "$*" >&2; }
13+
14+
# print error and exit
15+
die () {
16+
echoerr "ERROR: $1"
17+
# if $2 is defined AND NOT EMPTY, use $2; otherwise, set to "3"
18+
errnum=${2-3}
19+
( ps aux | grep -i "python test/x chrome" | grep -v grep | awk '{print $2}' | xargs kill >/dev/null 2>&1 ) || true
20+
( ps aux | grep -i "python test/x firefox" | grep -v grep | awk '{print $2}' | xargs kill >/dev/null 2>&1 ) || true
21+
( ps aux | grep parallel.sh | grep -v grep | awk '{print $2}' | xargs kill >/dev/null 2>&1 ) || true
22+
( ps aux | grep -i "python test/x chrome" | grep -v grep | awk '{print $2}' | xargs kill -9 >/dev/null 2>&1 ) || true
23+
( ps aux | grep -i "python test/x firefox" | grep -v grep | awk '{print $2}' | xargs kill -9 >/dev/null 2>&1 ) || true
24+
( ps aux | grep parallel.sh | grep -v grep | awk '{print $2}' | xargs kill -9 >/dev/null 2>&1 ) || true
25+
exit $errnum
26+
}
27+
28+
TEST_TYPE=$1
29+
TOT_THREADS=$2
30+
TESTS_PER_THREAD=$3
31+
32+
[ "${TEST_TYPE}" == "" ] && die "1st param must be one of 'chrome', 'firefox', 'hybrid'"
33+
34+
[ "${TOT_THREADS}" == "" ] && die "2nd param should be the amount of parallel tests to run!"
35+
[ $((TOT_THREADS%2)) -eq 0 ] || die "The amount of threads needs to be an even number!"
36+
37+
# By default 5 tests per thread, for stress testing
38+
[ "${TESTS_PER_THREAD}" == "" ] && TESTS_PER_THREAD=5
39+
40+
function get_mock_port() {
41+
echo $(docker inspect -f='{{(index (index .NetworkSettings.Ports "8082/tcp") 0).HostPort}}' adwords_mock)
42+
}
43+
44+
function mock_is_running() {
45+
docker inspect -f {{.State.Running}} adwords_mock | grep true
46+
}
47+
48+
export MOCK_SERVER_PORT=8082
49+
50+
if mock_is_running >/dev/null 2>&1; then
51+
docker stop adwords_mock || true
52+
fi
53+
54+
docker rm adwords_mock || true
55+
docker run -d --name=adwords_mock -e MOCK_SERVER_PORT \
56+
-p $MOCK_SERVER_PORT:$MOCK_SERVER_PORT elgalu/google_adwords_mock
57+
58+
export MOCK_SERVER_HOST=`docker inspect -f='{{.NetworkSettings.IPAddress}}' adwords_mock`
59+
60+
if [ "${MOCK_SERVER_HOST}" == "" ]; then
61+
die "Failed to grab IP from adwords_mock"
62+
fi
63+
64+
if [ "$(uname)" == 'Darwin' ]; then
65+
MOCK_URL="http://localhost:${MOCK_SERVER_PORT}/adwords"
66+
else
67+
MOCK_URL="http://${MOCK_SERVER_HOST}:${MOCK_SERVER_PORT}/adwords"
68+
fi
69+
70+
echo "Mock server should be found at ${MOCK_URL}"
71+
72+
while ! curl -s "${MOCK_URL}"; do
73+
echo -n '.'
74+
sleep 0.2
75+
done
76+
77+
if [ "${TEST_TYPE}" == "hybrid" ]; then
78+
LOOP_END_NUM=$(($TOT_THREADS/2-1))
79+
else
80+
LOOP_END_NUM=$(($TOT_THREADS-1))
81+
fi
82+
83+
echo "Mock server is running. Will now run ${1} threads. LOOP_END_NUM=${LOOP_END_NUM}"
84+
85+
for i in `seq 0 $LOOP_END_NUM`; do
86+
if [ "${TEST_TYPE}" == "chrome" ] || [ "${TEST_TYPE}" == "hybrid" ]; then
87+
(
88+
if [ "${TEST_TYPE}" == "hybrid" ]; then
89+
chrome_thread_num="$((i*2+1))"
90+
else
91+
chrome_thread_num="$((i+1))"
92+
fi
93+
94+
for j in `seq 1 $TESTS_PER_THREAD`; do
95+
test_id_chrome=${STAGE}thread-${chrome_thread_num}_seq-$j
96+
TEST_ID=$test_id_chrome python test/x chrome || \
97+
TEST_ID=$test_id_chrome python test/x chrome || \
98+
die "Test failed on chrome $test_id_chrome"
99+
done
100+
) &
101+
fi
102+
103+
if [ "${TEST_TYPE}" == "firefox" ] || [ "${TEST_TYPE}" == "hybrid" ]; then
104+
(
105+
if [ "${TEST_TYPE}" == "hybrid" ]; then
106+
firefox_thread_num="$((i*2+2))"
107+
else
108+
firefox_thread_num="$((i+1))"
109+
fi
110+
111+
for j in `seq 1 $TESTS_PER_THREAD`; do
112+
test_id_firefox=${STAGE}thread-${firefox_thread_num}_seq-$j
113+
TEST_ID=$test_id_firefox python test/x firefox || \
114+
TEST_ID=$test_id_firefox python test/x firefox || \
115+
die "Test failed on firefox $test_id_firefox"
116+
done
117+
) &
118+
fi
119+
done
120+
121+
wait

test/script_run_all_tests

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# set -x: print each command right before it is executed
55
set -xe
66

7-
rm -rf ./videos
7+
rm -rf ./videos ./tmp_videos
88
./test/script_bats
99

1010
# In Travis these ones require travis_retry
@@ -15,4 +15,5 @@ if [ "${CI}" != "true" ]; then
1515
./test/script_scenario_node_dies
1616
./test/script_scenario_make
1717
./test/script_scenario_compose_N_N
18+
./test/script_scenario_zalenium
1819
fi

test/script_scenario_zalenium

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env bash
2+
3+
# set -e: exit asap if a command exits with a non-zero status
4+
# set -x: print each command right before it is executed
5+
set -xe
6+
7+
echoerr() { printf "%s\n" "$*" >&2; }
8+
9+
# print error and exit
10+
die () {
11+
echoerr "ERROR: $1"
12+
# if $2 is defined AND NOT EMPTY, use $2; otherwise, set to "150"
13+
errnum=${2-188}
14+
exit $errnum
15+
}
16+
17+
set +x
18+
echo "#===================================================="
19+
echo "# Scenario 7a [zalenium]: Integration"
20+
echo "# with Zalenium and the one-liner should still work"
21+
echo "#===================================================="
22+
set -x
23+
24+
function stop_zalenium() {
25+
curl -sSL https://raw.githubusercontent.com/dosel/t/i/p | \
26+
PULL_DEPENDENCIES=false bash -s \
27+
stop
28+
}
29+
30+
# Cleanup
31+
stop_zalenium
32+
rm -rf $(pwd)/tmp_videos
33+
34+
# Dependencies
35+
pip install --upgrade -r test/requirements.txt
36+
docker pull dosel/zalenium
37+
38+
# Use Zalenium one-liner but don't pull
39+
# TODO: --maxTestSessions 5
40+
curl -sSL https://raw.githubusercontent.com/dosel/t/i/p | \
41+
PULL_DEPENDENCIES=false bash -s \
42+
start --firefoxContainers 0 \
43+
--chromeContainers 0 \
44+
--videos-dir $(pwd)/tmp_videos
45+
46+
set +x
47+
48+
docker logs zalenium
49+
50+
# Usage
51+
# bash parallel.sh {browser} {threads} {test-per-thread=5}
52+
VIDEO=true bash test/parallel.sh hybrid 2 3
53+
54+
# There should be a dashboard
55+
if ! ls -la tmp_videos/dashboard.html; then
56+
die "The dashboard.html file is missing but should be there" 110
57+
fi
58+
59+
# There should be (2 * 3) videos
60+
if ! ls -la tmp_videos/zalenium-build/*.mp4; then
61+
ls -la tmp_videos/ || true
62+
die "Video files were not found in the expected folder" 120
63+
fi
64+
65+
export VID_EXT="mp4"
66+
export EXPECTED_VID_COUNT="6"
67+
export VID_FOLDER="tmp_videos/zalenium-build"
68+
69+
# Wait up to 40 seconds for the videos to be there
70+
if ! timeout --foreground 40s test/wait_videos_count; then
71+
ls -la tmp_videos/zalenium-build/ || true
72+
die "Waited a few seconds for '${EXPECTED_VID_COUNT}' '${VID_EXT}' videos to be at ${VID_FOLDER}"
73+
fi
74+
75+
# Cleanup
76+
stop_zalenium

test/wait_videos_count

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
# set -e: exit asap if a command exits with a non-zero status
4+
set -e
5+
6+
echoerr() { printf "%s\n" "$*" >&2; }
7+
8+
# print error and exit
9+
die () {
10+
echoerr "ERROR: $1"
11+
# if $2 is defined AND NOT EMPTY, use $2; otherwise, set to "160"
12+
errnum=${2-160}
13+
exit $errnum
14+
}
15+
16+
# Required params
17+
[ -z "${VID_EXT}" ] && die "Need env var VID_EXT"
18+
[ -z "${EXPECTED_VID_COUNT}" ] && die "Need env var EXPECTED_VID_COUNT"
19+
[ -z "${VID_FOLDER}" ] && die "Need env var VID_FOLDER"
20+
21+
echo "Waiting for total ${VID_EXT} videos to be ${EXPECTED_VID_COUNT}"
22+
while [ $(ls -1q ${VID_FOLDER}/*.${VID_EXT} 2>/dev/null | wc -l) -lt ${EXPECTED_VID_COUNT} ]; do
23+
echo -n '.'
24+
sleep 0.2;
25+
done
26+
echo "SUCCESS: Videos count ${EXPECTED_VID_COUNT} was reached."

0 commit comments

Comments
 (0)