tests: functional: Run tests on two app servers

- Using `--dist=loadscope` splits the tests based on module, thus
  ensuring each app's tests get assigned to one worker only.
- Though app servers run in 2 separate VMs, the pytest-xdist workers
  simply run in two Python subprocesses (`-n 2`). This allows us to
  generate a unified test report.

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Joseph Nuthalapati 2023-10-25 06:44:03 +05:30 committed by Sunil Mohan Adapa
parent f4d8d3d046
commit fd1955a084
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
2 changed files with 24 additions and 9 deletions

View File

@ -11,8 +11,12 @@
- export AWS_DEFAULT_REGION=us-east-1
- |
aws lambda invoke --function-name launch_app_server --payload '{"launch_template_name": "'"$LAUNCH_TEMPLATE_NAME"'", "instance_name": "'"$INSTANCE_NAME"'", "ci_project_id": "'"$CI_PROJECT_ID"'", "build_job_id": "'"$BUILD_JOB_ID"'"}' response.json
- echo "APP_SERVER_IP=$(jq -r '.app_server_ip' response.json)" >> app-servers.env
- echo "INSTANCE_ID=$(jq -r '.instance_id' response.json)" >> app-servers.env
- echo "APP_SERVER_IP_1=$(jq -r '.app_server_ip' response.json)" >> app-servers.env
- echo "INSTANCE_ID_1=$(jq -r '.instance_id' response.json)" >> app-servers.env
- |
aws lambda invoke --function-name launch_app_server --payload '{"launch_template_name": "'"$LAUNCH_TEMPLATE_NAME"'", "instance_name": "'"$INSTANCE_NAME"'", "ci_project_id": "'"$CI_PROJECT_ID"'", "build_job_id": "'"$BUILD_JOB_ID"'"}' response.json
- echo "APP_SERVER_IP_2=$(jq -r '.app_server_ip' response.json)" >> app-servers.env
- echo "INSTANCE_ID_2=$(jq -r '.instance_id' response.json)" >> app-servers.env
tags:
- functional-tests
artifacts:
@ -22,7 +26,7 @@
.run-functional-tests:
stage: functional-tests
timeout: 3h
# Need to find a way of running the cleanup step even on failure
# Need to find another way of running the cleanup step even on failure
allow_failure: true
when: delayed
# Wait for the app-server to come up. Saves time for the CI runners.
@ -35,10 +39,11 @@
script:
- cp -r . /home/tester/freedombox && chown -R tester:tester /home/tester/freedombox
- |
sudo FREEDOMBOX_URL="https://$APP_SERVER_IP" -u tester bash -c \
'cd /home/tester/freedombox && py.test-3 -v --durations=10 --include-functional --splinter-headless --template=html1/index.html --report=functional-tests.html'
sudo APP_SERVER_URL_1="https://$APP_SERVER_IP_1" APP_SERVER_URL_2="https://$APP_SERVER_IP_2" -u tester bash -c \
'cd /home/tester/freedombox && py.test-3 -v --durations=10 --include-functional --splinter-headless -n 2 --dist=loadscope --template=html1/index.html --report=functional-tests.html'
after_script:
- echo "INSTANCE_ID=$INSTANCE_ID" >> app-servers.env
- echo "INSTANCE_ID_1=$INSTANCE_ID_1" >> app-servers.env
- echo "INSTANCE_ID_2=$INSTANCE_ID_2" >> app-servers.env
- cp /home/tester/freedombox/functional-tests.html .
- cp -r /home/tester/freedombox/screenshots/ .
artifacts:
@ -55,6 +60,7 @@
script:
- export AWS_DEFAULT_REGION=us-east-1
- |
aws lambda invoke --function-name terminate_app_server --payload '{"instance_id": "'"$INSTANCE_ID"'"}' response.json
aws lambda invoke --function-name terminate_app_server --payload '{"instance_id": "'"$INSTANCE_ID_1"'"}' response.json
aws lambda invoke --function-name terminate_app_server --payload '{"instance_id": "'"$INSTANCE_ID_2"'"}' response.json
tags:
- functional-tests

View File

@ -22,8 +22,17 @@ from selenium.webdriver.support.ui import WebDriverWait
config = configparser.ConfigParser()
config.read(pathlib.Path(__file__).with_name('config.ini'))
config['DEFAULT']['url'] = os.environ.get('FREEDOMBOX_URL',
config['DEFAULT']['url']).rstrip('/')
# Configuration to allow each pytest-xdist worker to hit a dedicated
# app server. See .ci/functional-tests.yml for usage.
worker = os.environ.get('PYTEST_XDIST_WORKER', 'master')
if worker == 'master':
config['DEFAULT']['url'] = os.environ.get(
'FREEDOMBOX_URL', config['DEFAULT']['url']).rstrip('/')
else:
# worker_ids are like gw0, gw1, ...
worker_number = int(worker.lstrip('gw')) + 1
config['DEFAULT']['url'] = os.environ[f'APP_SERVER_URL_{worker_number}']
config['DEFAULT']['ssh_port'] = os.environ.get('FREEDOMBOX_SSH_PORT',
config['DEFAULT']['ssh_port'])
config['DEFAULT']['samba_port'] = os.environ.get(