-
Notifications
You must be signed in to change notification settings - Fork 0
/
locust-script.py
68 lines (62 loc) · 3.33 KB
/
locust-script.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from locust import HttpUser, task, between, events
import json
class QuickstartUser(HttpUser):
wait_time = between(1, 3)
def on_start(self):
files = ['hash_recurse', 'recursive_calls', 'storage_read_writes', 'storage_writes']
self.request_bodies = {}
for file_name in files:
with open(f'request_files/{file_name}.json') as f:
self.request_bodies[file_name] = json.load(f)
@task
def test_hash_recursive(self):
if self.request_bodies:
file_name = 'hash_recurse'
request_body = self.request_bodies[file_name]
with self.client.post("/", json=request_body, headers={'Content-Type': 'application/json'}, catch_response=True, name=file_name) as response:
if response.status_code == 200:
if 'error' in response.json():
response.failure(f"Request failed with status code {response.status_code}")
else:
response.success()
else:
response.failure(f"Request failed with status code {response.status_code}")
@task
def test_recursive_calls(self):
if self.request_bodies:
file_name = 'recursive_calls'
request_body = self.request_bodies[file_name]
with self.client.post("/", json=request_body, headers={'Content-Type': 'application/json'}, catch_response=True, name=file_name) as response:
if response.status_code == 200:
if 'error' in response.json():
response.failure(f"Request failed with status code {response.status_code}")
else:
response.success()
else:
response.failure(f"Request failed with status code {response.status_code}")
@task
def test_storage_read_writes(self):
if self.request_bodies:
file_name = 'storage_read_writes'
request_body = self.request_bodies[file_name]
with self.client.post("/", json=request_body, headers={'Content-Type': 'application/json'}, catch_response=True, name=file_name) as response:
if response.status_code == 200:
if 'error' in response.json():
response.failure(f"Request failed with status code {response.status_code}")
else:
response.success()
else:
response.failure(f"Request failed with status code {response.status_code}")
@task
def test_storage_writes(self):
if self.request_bodies:
file_name = 'storage_writes'
request_body = self.request_bodies[file_name]
with self.client.post("/", json=request_body, headers={'Content-Type': 'application/json'}, catch_response=True, name=file_name) as response:
if response.status_code == 200:
if 'error' in response.json():
response.failure(f"Request failed with status code {response.status_code}")
else:
response.success()
else:
response.failure(f"Request failed with status code {response.status_code}")