A suite of load tests for the DPC API, running on K6 in GitHub Actions.
Developer documentation for K6 can be found on the official website.
In GitHub Actions, the load tests must be manually triggered. Developers can run them here.
Environment variables are stored in Ansible Vault. These will all populate automatically when you run the make command. To test locally, follow these steps:
- Run
yarnin order to get IDE integration for K6 libraries. - Run
make load-tests.
This will trigger the build of a new API environment with AUTH_DISABLED=true. It then triggers the load test suite to run, and finally tears down the new API environment.
A few of our utilities require unit tests, which live in the __tests__ directory. Run unit tests by running yarn test from this directory.
The K6 docker image that we rely on to run this both in GH Actions and locally does not actually run a Node.js environment. Therefore, we are unable to use most standard Node.js runtime utilities, including built-in library functions and the usual import syntax.
A workaround for Node.js libraries is to pull them directly from a CDN, e.g. import KJUR from 'https://unpkg.com/jsrsasign@11.1.0/lib/jsrsasign.js';. Currently, we don't need any third-party packages; this note is for future reference.
Many utilities are provided by K6. See: https://jslib.k6.io/. In addition, K6 provides a JavaScript API with utilities including HTTP requests, various cryptographic functions, and more.
When importing local files, you'll need to include the file extension, e.g. import generateDPCToken from './generate-dpc-token.js';
You can run the k6 tests we use for ci separately.
First, ensure the java services are running:
make docker-base
make api
make start-api
Run the tests from the project root directory:
docker run --rm -v $(pwd)/dpc-load-testing:/src --env-file $(pwd)/ops/config/decrypted/local.env --add-host host.docker.internal=host-gateway -e ENVIRONMENT=local -i grafana/k6 run /src/ci-app.js
Ensure the java images have been built (the portals will build themselves if necessary). In the project root directory:
make docker-base
make api
Run make command for smoke tests in the project root directory:
make smoke/local