Continuous Integration and Load Testing
Continuous integration (CI) is a widely accepted way to speed up your software development process, by merging code frequently and testing through automation. Many teams run automated functional test suites as part of their build and deployment process.
It’s also a great idea to include load and performance testing in your continuous integration pipeline! Automating load tests with every build or deployment can help you detect performance regressions quickly, and also uncover certain kinds of bugs that might only surface when the system is under load.
Starting Tests with with the Loadster CLI
The Loadster CLI is the easiest way to launch Loadster tests from your CI pipeline, build server, or cron job. It’s available as a self-contained native binary for Windows, Mac, and Linux, and makes running and observing load tests a breeze.
To start a test:
$ loadster start WsHDupkZEYkSD7bT
To run a test and wait for it to finish, evaluating assertions:
$ loadster run WsHDupkZEYkSD7bT --assert="totalErrors == 0" --assert="averageResponseTime < 0.5"
Check out the Loadster Command Line Interface documentation for general help with installing and using the Loadster CLI.
Starting Tests with Your HTTP Client
If you don’t want to use the Loadster CLI or it’s unavailable on your platform, you can also run and observe tests with your HTTP client of choice. For this example, we’ll use curl.
Making a POST to your scenario’s trigger will start the test:
$ curl -X POST https://api.loadster.app/cloud/triggers/WsHDupkZEYkSD7bT
{
"message": "Test launched!",
"reportUrl": "https://loadster.app/dashboard/projects/2e05873a-6119-426d-bf45-25858c7d797e/scenarios/5390b231-40bd-4897-9922-733d2479e436/tests/2a8d9a67-2708-435a-8aec-5fc462323632",
"statusUrl":"https://api.loadster.app/cloud/triggers/WsHDupkZEYkSD7bT/status/15d27a12-f970-4c62-8284-485b48851cad"
}
If you want to keep an eye on the test as it runs, or cause your CI process to wait for the test to finish, you or your CI script will want to make note of these URLs.
Although starting a test with curl is easy enough, we recommend using the Loadster CLI instead of curl if it’s available, because it can evaluate pass/fail assertions and other things besides just starting a test.
Tracking Test Results from Continuous Integration
Finished tests will show up in the activity feed on your dashboard, alongside tests that were started manually by you and others on your team.
Examples of CI/CD Tools
While the basic approach to load testing is similar for any CI tool, the implementation will be different from one tool to the next. Here are a few examples to get you started.
Integrating Loadster with Azure DevOps Pipelines
Azure DevOps Pipelines stores build configurations in a file called azure-pipelines.yml
at the root
of your project. Here’s an example of that file that installs the Loadster CLI locally and uses it to run
a load test. You’ll need to replace j0PYS8ehQRt4AUVL
with the scenario trigger code from your scenario.
trigger:
- rmaster
pool:
vmImage: ubuntu-latest
steps:
- script: |
curl -L -o loadster-cli.zip https://github.com/loadster/loadster-cli/releases/download/2.0.0/loadster-cli-2.0.0-linux-x64.zip
unzip loadster-cli.zip
cd loadster-cli-2.0.0-linux-x64
./loadster run j0PYS8ehQRt4AUVL
displayName: 'Run a load test'
As the test runs, you can watch the logs from Azure DevOps Pipelines to see how it’s going. After the test finishes, Azure DevOps Pipelines will store the logs along with a link to view the test report in your browser.
Depending on how often you want to run your load tests, you might want to create a separate pipeline just to run the load test, or you might want to append these steps to an existing pipeline to run the test with each build or after each deployment.
Integrating Loadster with CircleCI
CircleCI looks for the build configuration in a .circleci/config.yml
file in your project. This example shows how
to install the Loadster CLI locally and run a load test as part of each build. You’ll need to replace
j0PYS8ehQRt4AUVL
with the unique trigger code from your Loadster scenario.
version: 2.1
jobs:
loadtest:
docker:
- image: buildpack-deps:trusty
working_directory: ~/repo
steps:
- run: |
curl -L -o loadster-cli.zip https://github.com/loadster/loadster-cli/releases/download/2.0.0/loadster-cli-2.0.0-linux-x64.zip
unzip loadster-cli.zip
cd loadster-cli-2.0.0-linux-x64
./loadster run j0PYS8ehQRt4AUVL
workflows:
version: 2
commit:
jobs:
- loadtest
nightly:
triggers:
- schedule:
cron: "5 0 * * *"
filters:
branches:
only:
- master
jobs:
- loadtest
In this example, we’ve defined a job called loadtest
, and we’re calling it after every commit and also running it nightly
at 12:05 AM with the cron expression. In real life, you may want to append this job to an existing workflow or call
it after every deployment instead.
As the test runs, CircleCI will display logs from the Loadster CLI so you can observe how the test is going. CircleCI will also store the logs with the build results, including a link you can use to view the full test report in your browser.
Continuous Integration Next Steps
There are a million ways to do continuous integration, and we haven’t tried all of them. If you have feature requests or questions, please get in touch with help@loadster.app and let’s work together on it!