-
Notifications
You must be signed in to change notification settings - Fork 0
/
locustfile_seq.py
57 lines (45 loc) · 1.77 KB
/
locustfile_seq.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
from locust import SequentialTaskSet, HttpUser, task, between
import random
import sys
class EasyLoadUserTasks(SequentialTaskSet):
wait_time = between(5, 15)
@task
def upload_file(self):
file_index = random.randrange(sys.maxsize)
self.client.post("/upload", files={"file": (f"test_{file_index}.txt", "test data")})
class EasyLoadUser(HttpUser):
tasks = [EasyLoadUserTasks]
class MedianLoadUserTasks(SequentialTaskSet):
wait_time = between(1, 5)
@task
def upload_file(self):
file_index = random.randrange(sys.maxsize)
self.client.post("/upload", files={"file": (f"test_{file_index}.txt", "test data")})
@task
def get_file(self):
if hasattr(self, 'file_index'):
self.client.get(f"/files/test_{self.file_index}.txt")
class MedianLoadUser(HttpUser):
tasks = [MedianLoadUserTasks]
class HeavyLoadUserTasks(SequentialTaskSet):
wait_time = between(0.5, 2)
deletion_keys = {}
@task
def upload_file(self):
file_index = random.randrange(sys.maxsize)
with self.client.post("/upload", files={"file": (f"test_{file_index}.txt", "test data")}, catch_response=True) as response:
if response.status_code == 200:
data = response.json()
self.deletion_keys[data['filename']] = data['deletion_key']
self.file_index = file_index
@task
def get_file(self):
if hasattr(self, 'file_index'):
self.client.get(f"/files/test_{self.file_index}.txt")
@task
def delete_file(self):
if self.deletion_keys:
filename, delete_key = self.deletion_keys.popitem()
self.client.delete(f"/files/{filename}?key={delete_key}")
class HeavyLoadUser(HttpUser):
tasks = [HeavyLoadUserTasks]