- How to set up a CircleCI workflow to run your Artillery tests
- How to generate and view Artillery test reports from CircleCI
- How to schedule your Artillery tests to run at a specific time
- How to use Artillery Pro on CircleCI
Integrating Artillery with CircleCI allows you to continuously track your service’s performance while developing your applications. The following guide will show you how to load-test your services using CircleCI workflows.
You can find the complete source code used in this guide in the Artillery CI/CD Examples GitHub repo.
In this guide, we’ll use the following Artillery test script to run a load test on a running Socket.IO service, sending 50 virtual users per second for 10 minutes and ensuring the aggregate maximum latency for the test is under 500 milliseconds:
For this guide, we’ll use the cloud version of CircleCI and a GitHub code repository as an example. Currently, the cloud version of CircleCI only supports logging in to the service using your GitHub or Bitbucket credentials.
Go to the “Projects” section from the sidebar menu when logging in to CircleCI using either your GitHub or Bitbucket credentials. You’ll see the code repositories available in your GitHub or Bitbucket account. Search for the code repository containing your tests and click on the “Set Up Project” button to prepare the repo for use with CircleCI:
Next, you’ll have the option to choose a starter template configuration file or tell CircleCI to look for a configuration file in a branch from your code repository. CircleCI looks for the
.circleci/config.yml configuration file placed into your code repository to run your CI workflow. The configuration file uses YAML syntax to define the events that will trigger your workflow and the jobs and steps to execute.
Before proceeding on CircleCI, we’ll create a configuration file in the
main branch of the code repository. The configuration file will run the Artillery load test for the Socket.IO service after pushing new code to your GitHub repository’s
main branch. We’ll also use the official Docker image to execute the load test without setting up Artillery as part of the workflow.
In your code repository, create a new file placed in
.circleci/config.yml with the following contents:
Commit this file to the
main branch of your repository. Go back to CircleCI to finish setting up the project by telling the service to check the
main branch of the repo. It will detect the
.circleci/config.yml file in the branch:
Clicking on “Let’s Go” will immediately execute the load test on CircleCI:
Artillery can output a JSON file with additional details from the load test and use it to generate a self-contained HTML report.
First, your workflow needs to create a directory to place the test reports. Next, you can generate a JSON report when executing the Artillery load test. You can then use the
report command to generate the HTML report from the JSON file. Finally, you’ll need to upload the files as artifacts to access the reports upon completion of the workflow.
The configuration to accomplish these steps is the following:
After successful execution of the load test, CircleCI will store the contents of the
reports directory as part of the executed job:
For more details on uploading and accessing artifacts of a CircleCI job, read “Storing Build Artifacts” section in CircleCI’s documentation.
You can also schedule CircleCI to run a job on a recurring schedule using the
schedule trigger configuration setting in the workflow, which is helpful if you want to execute your Artillery load tests at a specific time. For instance, you may wish to load-test your production applications outside of peak hours.
schedule trigger requires two keys:
cron- A string using the POSIX cron syntax with the times in UTC. This setting will configure when to execute the job.
filters- A map to define rules for executing the recurring scheduled job on specific branches.
The following example configuration will automatically trigger the Artillery job on CircleCI every day at midnight UTC, running the job only on the
main branch of the code repository:
For more information about scheduling jobs on CircleCI, read the “Scheduling a workflow” section on CircleCI’s documentation.
You can scale your load tests by using Artillery Pro to execute your tests. Artillery Pro allows you to run your Artillery tests from different geographic regions within your AWS infrastructure.
To use Artillery Pro with CircleCI, you must have previously deployed the Artillery Pro backend to your AWS account. You also must set up the following environment variables as environment variables for your project:
AWS_ACCESS_KEY_ID- The access key ID of an IAM user with permissions to access the Artillery Pro backend resources.
AWS_SECRET_ACCESS_KEY- The secret access key of the IAM user.
Once the environment variables are set up for your project in CircleCI, the container running Artillery Pro will have access to its values. You won’t need to specify these values in the configuration file.
The following configuration will execute your Artillery test script on an Artillery Pro backend deployed in the
us-east-1 region (automatically using the
AWS_SECRET_ACCESS_KEY environment variables set up for the project):
For more options on executing your tests using Artillery Pro, check the Pro Commands section in the Command Line guide.