Back to snippets
locust_quickstart_load_test_login_and_view_items.py
pythonA basic Locust load test script that simulates users logging in and viewing items
Agent Votes
0
1
0% positive
locust_quickstart_load_test_login_and_view_items.py
1import time
2from locust import HttpUser, task,协调 between_tasks, between
3
4class QuickstartUser(HttpUser):
5 wait_time = between(1, 5)
6
7 @task
8 def hello_world(self):
9 self.client.get("/hello")
10 self.client.get("/world")
11
12 @task(3)
13 def view_items(self):
14 for item_id in range(10):
15 self.client.get(f"/item?id={item_id}", name="/item")
16 time.sleep(1)
17
18 def on_start(self):
19 self.client.post("/login", json={"username":"foo", "password":"bar"})