Skip to content

Commit

Permalink
test(docker): setup parallel tests use docker-compose on CI
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 committed Feb 26, 2024
1 parent be90342 commit e4d40c9
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 5 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/test-video.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ on:
pull_request:
paths-ignore:
- '**.md'
schedule:
- cron: '0 0 * * *'

permissions:
contents: read

jobs:
build-and-test:
name: Test video recorded through Docker Selenium
name: Test Docker Selenium
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
test-strategy: [test_video, test_parallel, test_parallel_likely_autoscaling]
steps:
- uses: actions/checkout@main
- name: Output Docker info
Expand All @@ -41,19 +47,22 @@ jobs:
run: echo ${BRANCH}
- name: Sets build date
run: echo "BUILD_DATE=$(date '+%Y%m%d')" >> $GITHUB_ENV
- name: Run Docker Compose to record video
run: USE_RANDOM_USER_ID=${USE_RANDOM_USER} VERSION=${BRANCH} BUILD_DATE=${BUILD_DATE} make test_video
- 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
if: matrix.test-strategy == 'test_video'
uses: actions/upload-artifact@main
with:
name: chrome_video
path: ./tests/videos/chrome_video.mp4
- name: Upload recorded Edge video
if: matrix.test-strategy == 'test_video'
uses: actions/upload-artifact@main
with:
name: edge_video
path: ./tests/videos/edge_video.mp4
- name: Upload recorded Firefox video
if: matrix.test-strategy == 'test_video'
uses: actions/upload-artifact@main
with:
name: firefox_video
Expand Down
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,20 @@ 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 \
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 NODE=$$node >> .env ; \
echo UID=$$(id -u) >> .env ; \
docker-compose -f docker-compose-v3-test-parallel.yml up --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.
# Its main purpose is to check that a video file was generated.
test_video: video hub chrome firefox edge
Expand Down
11 changes: 9 additions & 2 deletions tests/SeleniumTests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
SELENIUM_GRID_PASSWORD = os.environ.get('SELENIUM_GRID_PASSWORD', '')
SELENIUM_GRID_TEST_HEADLESS = os.environ.get('SELENIUM_GRID_TEST_HEADLESS', 'false').lower() == 'true'
WEB_DRIVER_WAIT_TIMEOUT = int(os.environ.get('WEB_DRIVER_WAIT_TIMEOUT', 60))
TEST_PARALLEL_HARDENING = os.environ.get('TEST_PARALLEL_HARDENING', 'false').lower() == 'true'

if SELENIUM_GRID_USERNAME and SELENIUM_GRID_PASSWORD:
SELENIUM_GRID_HOST = f"{SELENIUM_GRID_USERNAME}:{SELENIUM_GRID_PASSWORD}@{SELENIUM_GRID_HOST}"
Expand Down Expand Up @@ -216,9 +217,15 @@ def run(self, test_classes):
class DeploymentAutoscalingTests(unittest.TestCase):
def test_parallel_autoscaling(self):
runner = Autoscaling()
runner.run([FirefoxTests, EdgeTests, ChromeTests])
if not TEST_PARALLEL_HARDENING:
runner.run([FirefoxTests, EdgeTests, ChromeTests])
else:
runner.run([FirefoxTests, EdgeTests, ChromeTests, FirefoxTests, EdgeTests, ChromeTests, FirefoxTests, EdgeTests, ChromeTests])

class JobAutoscalingTests(unittest.TestCase):
def test_parallel_autoscaling(self):
runner = Autoscaling()
runner.run([FirefoxTests, EdgeTests, ChromeTests])
if not TEST_PARALLEL_HARDENING:
runner.run([FirefoxTests, EdgeTests, ChromeTests])
else:
runner.run([FirefoxTests, EdgeTests, ChromeTests, FirefoxTests, EdgeTests, ChromeTests, FirefoxTests, EdgeTests, ChromeTests])
74 changes: 74 additions & 0 deletions tests/docker-compose-v3-test-parallel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# How to run this?
# docker-compose -f docker-compose-v3-test-video.yml up --abort-on-container-exit --build
# To clean up, `docker-compose -f docker-compose-v3-test-video.yml down`
version: "3"
services:
chrome:
deploy:
mode: replicated
replicas: 5
image: selenium/node-chrome:${TAG}
user: ${UID}
shm_size: 2gb
depends_on:
- selenium-hub
environment:
- SE_DRAIN_AFTER_SESSION_COUNT=${TEST_DRAIN_AFTER_SESSION_COUNT}
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
- SE_NODE_ENABLE_MANAGED_DOWNLOADS=true

firefox:
deploy:
mode: replicated
replicas: 5
image: selenium/node-firefox:${TAG}
user: ${UID}
shm_size: 2gb
depends_on:
- selenium-hub
environment:
- SE_DRAIN_AFTER_SESSION_COUNT=${TEST_DRAIN_AFTER_SESSION_COUNT}
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
- SE_NODE_ENABLE_MANAGED_DOWNLOADS=true

edge:
deploy:
mode: replicated
replicas: 5
image: selenium/node-edge:${TAG}
user: ${UID}
shm_size: 2gb
depends_on:
- selenium-hub
environment:
- SE_DRAIN_AFTER_SESSION_COUNT=${TEST_DRAIN_AFTER_SESSION_COUNT}
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
- SE_NODE_ENABLE_MANAGED_DOWNLOADS=true

selenium-hub:
image: selenium/hub:${TAG}
user: ${UID}
container_name: selenium-hub
ports:
- "4442:4442"
- "4443:4443"
- "4444:4444"

tests:
image: docker-selenium-tests:latest
build:
context: ./
dockerfile: ./Dockerfile
depends_on:
- selenium-hub
environment:
- RUN_IN_DOCKER_COMPOSE=true
- SELENIUM_GRID_HOST=selenium-hub
- TEST_PARALLEL_HARDENING=${TEST_PARALLEL_HARDENING}
command: ["./bootstrap.sh", "${NODE}"]

0 comments on commit e4d40c9

Please sign in to comment.