I would like to invoke Locust load tests through an API to be able to start tests from a CI tool.
I dont see much documentation about such a scenario, there is no "Runner" or a similar class in the locust API documentation.
I checked the "locust" command which becomes available, after installation in Windows . It is a .exe so not sure what it does and how it actually starts the test
So , the specific question is, is there an interface to start the test from another Python program
To run API performance tests well, you'll need to write multiple types of tests. The good news is that you can simplify this process by extending your API functional tests into API functional load tests, which provide the most nuanced level of insight into your API's overall performance.
To start the load test, run locust -f locust_files/my_locust_file.py --host=http://example.com where host would be your IP. You can then go to 127.0. 0.1:8089 to select the number of virtual users to simulate. On windows there's a limitation of 1024 users only.
just do what you do in the locust web UI and do it in python.
if you monitor the network in the locust UI, you'll notice that invoking a swarm is just a GET request towards 127.0.0.1:8089/swarm
with two arguments, locust_count
and hatch_rate
.
to answer your question, here's the api you asked for and example:
import requests
payload = {
'locust_count': 12,
'hatch_rate': 22,
}
res = requests.get('http://127.0.0.1:8089/swarm', params=payload)
print(res.json())
didn't test it, let me know if it doesn't work.
Currently, there is no documented API for controlling locust, except for the command line interface. The CLI can be used to start running load tests, though currently one can't run locust distributed without the web UI.
You could also use the web UI as an API, and just make the HTTP requests, that the browser sends to the web UI, yourself from your program.
The locust.exe file that is created (by python's setuptools) in Windows, is just a small wrapper that will run main()
in locust/main.py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With