Skip to content

Commit

Permalink
Add k6 performance test (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
ScenarioFactory authored Nov 5, 2024
1 parent 7a5feb1 commit fd69578
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ffc-grants-eligibility-checker",
"description": "FFC Grant Eligibility Checker",
"version": "1.0.21",
"version": "1.0.22",
"license": "OGL-UK-3.0",
"contributors": [
"Andrew Folga <[email protected]>",
Expand Down
6 changes: 6 additions & 0 deletions test/performance/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
.dockerignore
.env
docker-compose*
Dockerfile
README.md
4 changes: 4 additions & 0 deletions test/performance/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM grafana/k6
COPY script.js /script.js
USER k6
CMD ["run", "/script.js"]
19 changes: 19 additions & 0 deletions test/performance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Performance Tests
This folder contains the performance tests for the Grants Eligibility Checker app. The framework used is Grafana k6.

## Set up
k6 can be installed and run locally on the machine, or a docker container with k6 is available. See https://grafana.com/docs/k6/latest/set-up/install-k6/.

k6 does not use NodeJS but _npm install_ can be used to install the _@types/k6_ package to give intellisense in VS Code.

## Running tests in a container
```pwsh
# TEST_ENVIRONMENT_ROOT_URL environment variable must be set, and can be provided via local .env file
docker-compose run --build --rm perf-test
```

## Running tests against a local k6 installation
```pwsh
# TEST_ENVIRONMENT_ROOT_URL environment variable must be set, or can be provided on command line
k6 run -e TEST_ENVIRONMENT_ROOT_URL=http://localhost:3000 script.js
```
6 changes: 6 additions & 0 deletions test/performance/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
perf-test:
build: .
image: perf-test
environment:
TEST_ENVIRONMENT_ROOT_URL: ${TEST_ENVIRONMENT_ROOT_URL}
23 changes: 23 additions & 0 deletions test/performance/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions test/performance/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "performance",
"version": "1.0.0",
"main": "script.js",
"scripts": {
"test": "k6 run -e TEST_ENVIRONMENT_ROOT_URL=http://localhost:3000 script.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "Grants Eligibility Checker Performance Tests",
"devDependencies": {
"@types/k6": "^0.54.0"
}
}
37 changes: 37 additions & 0 deletions test/performance/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* global __ENV */
import http from 'k6/http';
import { describe, expect } from 'https://jslib.k6.io/k6chaijs/4.3.4.3/index.js';

export const options = {
scenarios: {
journey: {
executor: 'ramping-vus',
startVUs: 0,
stages: [
{ duration: '5s', target: 50 },
{ duration: '25s', target: 50 }
],
gracefulRampDown: '0s',
gracefulStop: '5s'
}
},
thresholds: {
http_req_duration: ['p(99)<250'] // 99% of requests should be below 250ms
}
};

/**
* Performs the checker journey.
* This default function is called for every iteration run by k6.
*/
export default function () {
describe('Checker Journey', (t) => {
const response = http.get(
`${__ENV.TEST_ENVIRONMENT_ROOT_URL}/eligibility-checker/example-grant/start`
);
expect(response.status).to.equal(200);

const heading = response.html().find('h1').text();
expect(heading).to.equal('Generic checker screens');
});
}

0 comments on commit fd69578

Please sign in to comment.