-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlocustfile.py
31 lines (27 loc) · 957 Bytes
/
locustfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from locust import HttpUser, task, between
import json
import uuid
class CheshireCatUser(HttpUser):
host = "http://localhost:1865"
wait_time = between(1, 3)
def on_start(self):
pass
@task(1)
def get_status(self):
with self.client.get("/", catch_response=True) as response:
if response.status_code == 200:
response.success()
else:
response.failure(f"Error: {response.text}")
@task(2)
def send_message(self):
payload = {"text": "Hello, Cheshire Cat!"}
headers = {
'Content-Type': 'application/json',
'user_id': str(uuid.uuid4())
}
with self.client.post("/message", data=json.dumps(payload), headers=headers, catch_response=True) as response:
if response.status_code == 200:
response.success()
else:
response.failure(f"Error: {response.text}")