Browse Source

Add performance test task

CLDC-3611-performance-testing
Kat 4 months ago
parent
commit
0c6f3b7b77
  1. 71
      .github/workflows/review_pipeline.yml
  2. 26
      lib/tasks/performance.rake

71
.github/workflows/review_pipeline.yml

@ -15,6 +15,10 @@ defaults:
run: run:
shell: bash shell: bash
env:
app_repo_role: arn:aws:iam::815624722760:role/core-application-repo
aws_region: eu-west-2
jobs: jobs:
infra: infra:
name: Deploy review app infrastructure name: Deploy review app infrastructure
@ -41,48 +45,41 @@ jobs:
performance: performance:
needs: [code] needs: [code]
runs-on: ubuntu-latest runs-on: ubuntu-latest
with:
aws_role_prefix: core-dev
aws_task_prefix: core-review-${{ github.event.pull_request.number }}
environment: review
steps: steps:
- name: Install Apache Benchmark (ab) - name: Configure AWS credentials
run: sudo apt-get update && sudo apt-get install -y apache2-utils uses: aws-actions/configure-aws-credentials@v3
with:
aws-region: ${{ env.aws_region }}
role-to-assume: ${{ env.app_repo_role }}
- name: Login to Amazon ECR
id: ecr-login
uses: aws-actions/amazon-ecr-login@v1
with:
mask-password: "true"
- name: Run Performance Test - name: Run Performance Test
env:
ad_hoc_task_definition: ${{ inputs.aws_task_prefix }}-ad-hoc
cluster: ${{ inputs.aws_task_prefix }}-app
service: ${{ inputs.aws_task_prefix }}-app
email: performance_testing_user@example.com
password: password
run: | run: |
echo "test curl" network=$(aws ecs describe-services --cluster $cluster --services $service --query services[0].networkConfiguration)
curl https://review.submit-social-housing-data.levellingup.gov.uk/${{ github.event.pull_request.number }}/account/sign-in overrides='{ "containerOverrides" : [{ "name" : "app", "command" : ["bundle", "exec", "rake", "performance:run_ab[$email,$password]"]}]}'
arn=$(aws ecs run-task --cluster $cluster --task-definition $ad_hoc_task_definition --network-configuration "$network" --overrides "$overrides" --group migrations --launch-type FARGATE --query tasks[0].taskArn)
echo "Fetching CSRF token..." echo "Waiting for performance test task to complete"
TOKEN=$(curl -c token_cookies.txt -s https://review.submit-social-housing-data.levellingup.gov.uk/${{ github.event.pull_request.number }}/account/sign-in | grep '<meta name="csrf-token"' | sed -n 's/.*content="\([^"]*\)".*/\1/p') temp=${arn##*/}
id=${temp%*\"}
if [ -z "$TOKEN" ]; then aws ecs wait tasks-stopped --cluster $cluster --tasks $id
echo "Failed to retrieve CSRF token." succeeded=$(aws ecs describe-tasks --cluster $cluster --tasks $id --query "tasks[0].stopCode == 'EssentialContainerExited' && to_string(tasks[0].containers[0].exitCode) == '0'")
exit 1 if [ $succeeded == true ]; then exit 0; else exit 1; fi
fi
if [ -f token_cookies.txt ]; then
echo "token_cookies.txt exists."
else
echo "token_cookies.txt does not exist."
fi
echo "Logging in..."
curl -L -c login_cookies.txt -b token_cookies.txt -X POST https://review.submit-social-housing-data.levellingup.gov.uk/${{ github.event.pull_request.number }}/account/sign-in \
-d "user[email]=$PERFORMANCE_TESTING_USER_EMAIL" \
-d "user[password]=$PERFORMANCE_TESTING_USER_PASSWORD" \
-d "authenticity_token=$TOKEN"
if [ -f login_cookies.txt ]; then
echo "login_cookies.txt exists."
else
echo "login_cookies.txt does not exist."
fi
# Extract cookies for use in the benchmark
COOKIES=$(awk '/_data_collector_session/ { print $6, $7 }' login_cookies.txt | tr ' ' '=')
# Run the Apache Benchmark
ab -n 50 -c 50 -C "$COOKIES" 'https://review.submit-social-housing-data.levellingup.gov.uk/${{ github.event.pull_request.number }}/lettings-logs'
env: env:
PERFORMANCE_TESTING_USER_EMAIL: coordinator1@example.com PERFORMANCE_TESTING_USER_EMAIL: coordinator1@example.com
PERFORMANCE_TESTING_USER_PASSWORD: password PERFORMANCE_TESTING_USER_PASSWORD: password

26
lib/tasks/performance.rake

@ -0,0 +1,26 @@
namespace :performance do
desc "Export data XMLs for import into Central Data System (CDS)"
task :run_ab, %i[email password] => :environment do |_task, args|
email = Rails.root.join(args[:email])
password = Rails.root.join(args[:password])
system("echo install apache2-utils")
system("apt-get update && apt-get install curl && apt-get install -y apache2-utils")
system("echo get token")
token = `curl -c token_cookies.txt -s https://review.submit-social-housing-data.levellingup.gov.uk/2621/account/sign-in | grep '<meta name="csrf-token"' | sed -n 's/.*content="\\([^"]*\\)".*/\\1/p'`
system <<-BASH
echo "Logging in..."
curl -L -o nul -c login_cookies.txt -b token_cookies.txt -X POST https://review.submit-social-housing-data.levellingup.gov.uk/2621/account/sign-in \
-d "user[email]=#{email}" \
-d "user[password]=#{password}" \
-d "authenticity_token=#{token}"
# Extract cookies for use in the benchmark
COOKIES=$(awk '/_data_collector_session/ { print $6, $7 }' login_cookies.txt | tr ' ' '=')
# Run the Apache Benchmark
ab -n 50 -c 50 -C "$COOKIES" 'https://review.submit-social-housing-data.levellingup.gov.uk/2621/lettings-logs'
BASH
end
end
Loading…
Cancel
Save