This project performs simple unit load testing and scenario load testing on some example APIs using the k6 load testing tool.
The full description of the project can be found in instructions.pdf and report.pdf, in Persian. Some background explanation about concepts such as load testing, stress testing, checks and thresholds in k6 can also be found in the report.
A basic unit test that hits an endpoint and validates the response.
The scenarios simulate load on the test-api.k6.io API. The script uses ./users.json and ./crocos.json for user credentials and crocodile data.
- http_req_failed: The rate of failed HTTP requests should be kept below 1%.
- http_req_duration: 95% of requests should complete within 1000ms (1 second).
A gradual ramp-up of virtual users (VUs) is performed using the 'ramping-arrival-rate' executor. The goal is to simulate increasing load on the target API over time.
- Check Public Crocos: Verifies that the response status from the public crocodiles endpoint is 200 (OK).
- Check Selected Croco: Ensures that the response status from a randomly selected crocodile's endpoint is 200 and that the response contains all expected crocodile fields.
A fixed number of VUs (30) perform a specified number of iterations using the 'shared-iterations' executor. The goal is to simulate a consistent load on the target API.
- Check Login: Verifies that the login to the API was successful by checking the response status.
- Check Create Crocos: Ensures that newly created crocodiles have a response status of 201 (Created) and that the response includes an assigned ID for each crocodile.
Grafana was used to visualize the test results with k6 Grafana plugin. Explanation of this step can be found in the report.
To run the tests:
k6 run 1-unit-test.js
k6 run 2-scenario.js
The test hits endpoints on https://test-api.k6.io:
/user/register/
- register/auth/token/login/
- login/my/crocodiles/
- private crocodile management/my/crocodiles/{id}
- select a specific private crocodile/public/crocodiles/
- browse public crocodilespublic/crocodiles/{id}
- select a specific public crocodile
- Course: Software Engineering II
- University: Amirkabir University of Technology
- Semester: Fall 2022
Let me know if you have any questions.