Skip to content

Latest commit

 

History

History
92 lines (66 loc) · 3.57 KB

File metadata and controls

92 lines (66 loc) · 3.57 KB

back

Performance Testing

GraphQL performance tests

The project uses a combination of k6 and Grafana with Prometheus for GraphQL performance testing.

The goal of the GraphQL performance tests is to get a picture of how performance changes over time (e.g., whether it improves or worsens for certain queries).

Automation

To ensure constant monitoring of the performance of selected GraphQL queries, the performance tests are run once an hour against each environment of the application. The results are then sent to the governmental Grafana dashboards.

How to add or modify the tests

The performance tests are located in the k6/performance-tests directory. The GitHub Action workflow that runs the tests is generated by running the yarn run github:codegen command; be sure to run it after modifying the generate-github-actions.mjs file (e.g. after adding another test or cube).

Load tests

The project uses k6 for load testing.

The goal of the load tests is to simulate real-world usage patterns and identify performance bottlenecks under various load conditions.

Automation

There is a dedicated GitHub Action that runs the API load tests against selected environment. You can investigate the results by going to Actions section in GitHub and checking the summary results.

Local setup

In order to run the tests locally, follow the documentation to install k6 on your machine.

Running the tests locally

To run a given load test, simply run

k6 run k6/script-name.js

replacing the script-name with an actual name of the test you want to run. Optionally, you can tweak the configuration of each test by directly modifying the options object inside a given script and running yarn k6:codegen to make the JavaScript files up-to-date.

For the GraphQL tests, you'll also need to pass --env ENV=(test|int|prod) flag to point to the proper environment and --env ENABLE_GQL_SERVER_SIDE_CACHE=(true | false) to control whether to use GQL server-side caching.

Recording the tests using Playwright

While some tests are written manually, other tests come from HAR recordings that span a broad set of actions. In order to record a HAR file and convert it into k6 script, use the testAndSaveHar inside e2e/har-utils.ts file.

Simply import that function inside a given e2e test and replace the regular test call with testAndSaveHar. Note that you need to specify environment against which to run the test, filename and path to save the file.

⚠️ The testAndSaveHar function exposes a baseUrl property, which needs to be injected into the page.goto calls.

After the HAR file has been recorded, use har-to-k6 library to convert the file into k6 script (and put it into the k6/har folder). Remember to add --add-sleep flag to include pauses between requests. Afterwards, edit the options variable at the top of the file to set the parameters for the test.

⚠️ You might want to remove requests to Google afterwards manually, to remove false-positives of blocked requests.