This repository demonstrates an example of k6 Load tester which implements Smoke, Load, Stress and Soak tests scenarios on an AUT(Application Under Test). Additionally it stores the results in Influxdb an could be visualized in Grafana.
- npm
- python 3.6+
- Docker
The AUT example is https://github.com/testdrivenio/flask-vue-crud which uses a flask application as server and vueJs as client. Clone, install and setup the requirements just as the readme guideline. You should be able to see the app on http://localhost:8080.
Follow the instructions provided in https://k6.io/docs/getting-started/installation/ or for Ubuntu distributions:
sudo apt-get update && sudo apt-get install ca-certificates gnupg2 -y
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
$ echo "deb https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
$ sudo apt-get update
$ sudo apt-get install k6
- Up the
docker-compose.yaml
file with:
docker-compose -d up
You should be able to see Grafana dashboard on http://localhost:3000
Its default username and password is: admin
- Create a data source with below configurations:
- Import the pre-configured Exa dashboard by id:
15080
or by the link
Now everything is ready to get the test.
-
Clone the repository
-
change directory to files:
cd files
Run k6 with the desired test mode. Wait for the test to get accomplished.
k6 run -e test_mode=smoke --out influxdb=http://localhost:8086/myk6db test.js
You can choose the test_mode value according to the below options.
-
smoke: Targets the functionality of the system under the lowest load: Is it working with only one user?
-
load: Targets the system under normal usage by the users. You should ask: How many users are using the system simultaneously typically and how long is their session?
-
stress: What is the maximum capacity of the system? How many users with what kind of behavior should use the site to disrate its quality due to the SLO: i.e. availability, request latency, throughput and etc.
-
soak: Would the system last for a long time(normally hours to days) under normal conditions? It’s working for 15min under normal condition in the load test but is feasible for a much longer time?
- Now you can get back to the imported grafana dashboard and see the results.
You can use the k6 official docker image to run the tests. This is a practical approach specially for CI/CD purposes like run the tests with cronjob. The Dockerfile in the root of the repository will do that for you. Furthermore, you can use it in docker-compose along with other containers by commenting out the k6-tester service.