FreedomBox/.ci/functional-tests.yml
Joseph Nuthalapati fd1955a084
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>
2023-11-05 09:21:47 -08:00

67 lines
3.0 KiB
YAML

---
# SPDX-License-Identifier: AGPL-3.0-or-later
.app-server:
stage: functional-tests
dependencies: []
except:
- $GITLAB_USER_LOGIN == "weblate"
script:
- BUILD_JOB_ID=$(curl -s "https://salsa.debian.org/api/v4/projects/$CI_PROJECT_ID/pipelines/$CI_PIPELINE_ID/jobs?scope[]=success" | jq -r '.[] | select(.name==env.BUILD_JOB_NAME) | .id')
- 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_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:
reports:
dotenv: app-servers.env
.run-functional-tests:
stage: functional-tests
timeout: 3h
# 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.
start_in: 3 minutes
before_script:
- apt-get update
- apt-get install -y sudo curl wget
- ./plinth/tests/functional/install.sh
- adduser tester --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-password && echo "tester:password" | chpasswd
script:
- cp -r . /home/tester/freedombox && chown -R tester:tester /home/tester/freedombox
- |
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_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:
when: always
reports:
dotenv: app-servers.env
paths:
- functional-tests.html
- screenshots/
# Does not run if the previous job times out or is cancelled
.terminate-app-server:
stage: functional-tests
script:
- export AWS_DEFAULT_REGION=us-east-1
- |
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