Skip to content

Commit

Permalink
test(docker): CI tests use case parallel execution
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
  • Loading branch information
VietND96 committed Feb 27, 2024
1 parent 0571fe7 commit a369379
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 12 deletions.
31 changes: 30 additions & 1 deletion .github/workflows/test-video.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ concurrency:

on:
workflow_dispatch:
inputs:
request-timeout:
description: 'Test parameter for different request timeout'
required: false
default: '400'
parallel-hardening:
description: 'Test parameter to enable hardening parallel tests'
required: false
default: 'true'
log-level:
description: 'Test parameter for different log level'
required: false
default: 'INFO'
push:
paths-ignore:
- '**.md'
Expand All @@ -23,7 +36,7 @@ jobs:
strategy:
fail-fast: false
matrix:
test-strategy: [test_video, test_parallel, test_parallel_likely_autoscaling]
test-strategy: [test_video, test_parallel]
steps:
- uses: actions/checkout@main
- name: Output Docker info
Expand All @@ -47,6 +60,22 @@ jobs:
run: echo ${BRANCH}
- name: Sets build date
run: echo "BUILD_DATE=$(date '+%Y%m%d')" >> $GITHUB_ENV
- name: Pre-build to reduce logs in test phase
run: |
VERSION=${BRANCH} BUILD_DATE=${BUILD_DATE} make hub
VERSION=${BRANCH} BUILD_DATE=${BUILD_DATE} make chrome
VERSION=${BRANCH} BUILD_DATE=${BUILD_DATE} make firefox
VERSION=${BRANCH} BUILD_DATE=${BUILD_DATE} make edge
- name: Set test parameters
if: (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')
run: |
echo "LOG_LEVEL=${LOG_LEVEL}" >> $GITHUB_ENV
echo "TEST_PARALLEL_HARDENING=${TEST_PARALLEL_HARDENING}" >> $GITHUB_ENV
echo "REQUEST_TIMEOUT=${REQUEST_TIMEOUT}" >> $GITHUB_ENV
env:
LOG_LEVEL: ${{ github.event.inputs.log-level || 'INFO' }}
TEST_PARALLEL_HARDENING: ${{ github.event.inputs.parallel-hardening || 'true' }}
REQUEST_TIMEOUT: ${{ github.event.inputs.request-timeout || '400' }}
- name: Run Docker Compose to ${{ matrix.test-strategy }}
run: USE_RANDOM_USER_ID=${USE_RANDOM_USER} VERSION=${BRANCH} BUILD_DATE=${BUILD_DATE} make ${{ matrix.test-strategy }}
- name: Upload recorded Chrome video
Expand Down
11 changes: 5 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -382,18 +382,17 @@ test_firefox:
test_firefox_standalone:
VERSION=$(TAG_VERSION) NAMESPACE=$(NAMESPACE) ./tests/bootstrap.sh StandaloneFirefox

test_parallel_likely_autoscaling:
TEST_DRAIN_AFTER_SESSION_COUNT=3 TEST_PARALLEL_HARDENING=false make test_parallel

test_parallel: hub chrome firefox edge
for node in DeploymentAutoscaling ; do \
for node in DeploymentAutoscaling JobAutoscaling ; do \
cd ./tests || true ; \
echo TAG=$(TAG_VERSION) > .env ; \
echo TEST_DRAIN_AFTER_SESSION_COUNT=$(or $(TEST_DRAIN_AFTER_SESSION_COUNT), 0) >> .env ; \
echo TEST_PARALLEL_HARDENING=$(or $(TEST_PARALLEL_HARDENING), "true") >> .env ; \
echo TEST_PARALLEL_HARDENING=$(or $(TEST_PARALLEL_HARDENING), "false") >> .env ; \
echo LOG_LEVEL=$(or $(LOG_LEVEL), "INFO") >> .env ; \
echo REQUEST_TIMEOUT=$(or $(REQUEST_TIMEOUT), 300) >> .env ; \
echo NODE=$$node >> .env ; \
echo UID=$$(id -u) >> .env ; \
docker-compose -f docker-compose-v3-test-parallel.yml up --exit-code-from tests --build ; \
docker-compose -f docker-compose-v3-test-parallel.yml up --no-log-prefix --exit-code-from tests --build ; \
done

# This should run on its own CI job. There is no need to combine it with the other tests.
Expand Down
9 changes: 7 additions & 2 deletions tests/SeleniumTests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def run(self, test_classes):
start_times[test] = time.time()
futures.append(executor.submit(test))
tests.append(test)
print(f"Number of tests were added to worker: {len(tests)}")
failed_tests = []
for future, test in zip(concurrent.futures.as_completed(futures), tests):
try:
Expand Down Expand Up @@ -220,12 +221,16 @@ def test_parallel_autoscaling(self):
if not TEST_PARALLEL_HARDENING:
runner.run([FirefoxTests, EdgeTests, ChromeTests])
else:
runner.run([FirefoxTests, EdgeTests, ChromeTests, FirefoxTests, EdgeTests, ChromeTests, FirefoxTests, EdgeTests, ChromeTests])
runner.run([FirefoxTests, EdgeTests, ChromeTests, FirefoxTests, EdgeTests, ChromeTests, FirefoxTests, EdgeTests, ChromeTests,
FirefoxTests, EdgeTests, ChromeTests, FirefoxTests, EdgeTests, ChromeTests, FirefoxTests, EdgeTests, ChromeTests,
FirefoxTests, EdgeTests, ChromeTests, FirefoxTests, EdgeTests, ChromeTests, FirefoxTests, EdgeTests, ChromeTests,])

class JobAutoscalingTests(unittest.TestCase):
def test_parallel_autoscaling(self):
runner = Autoscaling()
if not TEST_PARALLEL_HARDENING:
runner.run([FirefoxTests, EdgeTests, ChromeTests])
else:
runner.run([FirefoxTests, EdgeTests, ChromeTests, FirefoxTests, EdgeTests, ChromeTests, FirefoxTests, EdgeTests, ChromeTests])
runner.run([FirefoxTests, EdgeTests, ChromeTests, FirefoxTests, EdgeTests, ChromeTests, FirefoxTests, EdgeTests, ChromeTests,
FirefoxTests, EdgeTests, ChromeTests, FirefoxTests, EdgeTests, ChromeTests, FirefoxTests, EdgeTests, ChromeTests,
FirefoxTests, EdgeTests, ChromeTests, FirefoxTests, EdgeTests, ChromeTests, FirefoxTests, EdgeTests, ChromeTests,])
6 changes: 6 additions & 0 deletions tests/charts/make/chart_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ HELM_COMMAND_SET_IMAGES=" \
--set global.seleniumGrid.logLevel=${LOG_LEVEL} \
"

if [ -n "${SET_MAX_REPLICAS}" ]; then
HELM_COMMAND_SET_IMAGES="${HELM_COMMAND_SET_IMAGES} \
--set autoscaling.scaledOptions.maxReplicaCount=${SET_MAX_REPLICAS} \
"
fi

if [ "${CHART_ENABLE_INGRESS_HOSTNAME}" = "true" ]; then
if [[ ! $(cat /etc/hosts) == *"${HOSTNAME_ADDRESS}"* ]]; then
sudo -- sh -c -e "echo \"$(hostname -i) ${HOSTNAME_ADDRESS}\" >> /etc/hosts"
Expand Down
12 changes: 9 additions & 3 deletions tests/docker-compose-v3-test-parallel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
chrome:
deploy:
mode: replicated
replicas: 5
replicas: 10
image: selenium/node-chrome:${TAG}
user: ${UID}
shm_size: 2gb
Expand All @@ -18,11 +18,12 @@ services:
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
- SE_NODE_ENABLE_MANAGED_DOWNLOADS=true
- SE_LOG_LEVEL=${LOG_LEVEL}

firefox:
deploy:
mode: replicated
replicas: 5
replicas: 10
image: selenium/node-firefox:${TAG}
user: ${UID}
shm_size: 2gb
Expand All @@ -34,11 +35,12 @@ services:
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
- SE_NODE_ENABLE_MANAGED_DOWNLOADS=true
- SE_LOG_LEVEL=${LOG_LEVEL}

edge:
deploy:
mode: replicated
replicas: 5
replicas: 10
image: selenium/node-edge:${TAG}
user: ${UID}
shm_size: 2gb
Expand All @@ -50,6 +52,7 @@ services:
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
- SE_NODE_ENABLE_MANAGED_DOWNLOADS=true
- SE_LOG_LEVEL=${LOG_LEVEL}

selenium-hub:
image: selenium/hub:${TAG}
Expand All @@ -59,6 +62,9 @@ services:
- "4442:4442"
- "4443:4443"
- "4444:4444"
environment:
- SE_LOG_LEVEL=${LOG_LEVEL}
- SE_SESSION_REQUEST_TIMEOUT=${REQUEST_TIMEOUT}

tests:
image: docker-selenium-tests:latest
Expand Down

0 comments on commit a369379

Please sign in to comment.