I am running this script with 1000 users and 20 rate.
I know a login API is slow but create_device() is quite fast and I want to benchmark create_device API.
How can I configure/run this test, so create_device() task should be running if all login() went fine. (I want to trigger create_device() at the same time)
from locust import HttpUser, task, between, events
class UserBehavior(HttpUser):
wait_time = between(1, 3)
def on_start(self):
# Perform login
response = self.client.post("/login", json={"username": "your_username", "password": "your_password"})
if response.status_code != 200:
print("Failed to login")
self.environment.runner.quit()
@task
def create_device(self):
# Perform create_device task
response = self.client.post("/create_device", json={"device_name": "test_device"})
if response.status_code != 200:
print("Failed to create device")
@events.quitting.add_listener
def on_quitting(**kwargs):
print("All users have completed on_start() method")