-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
locustfile.py
63 lines (55 loc) · 2.19 KB
/
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
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
from random import randint
from typing import Dict, Tuple
from locust import task
from locust.contrib.fasthttp import FastHttpUser
HEADERS: Dict[str, str] = {"Content-Type": "application/json"}
INTERVAL: Tuple[int, int] = (0, 4096)
class LoadTest(FastHttpUser):
@task(50)
def get_url(self):
with self.client.get(
f"/{randint(*INTERVAL)}", allow_redirects=False, catch_response=True, headers=HEADERS
) as response:
if response.status_code not in [307, 404]:
response.failure(f"Got wrong response: {response.status_code}")
else:
response.success()
@task(20)
def shorten_url(self):
with self.client.post(
f"/?url={randint(*INTERVAL)}", allow_redirects=False, catch_response=True, headers=HEADERS
) as response:
if response.status_code not in [200, 400]:
response.failure(f"Got wrong response: {response.status_code}")
else:
response.success()
@task(5)
def delete_url(self):
with self.client.delete(
f"/{randint(*INTERVAL)}", allow_redirects=False, catch_response=True, headers=HEADERS
) as response:
if response.status_code not in [200, 400]:
response.failure(f"Got wrong response: {response.status_code}")
else:
response.success()
@task(10)
def modify_url(self):
with self.client.put(
f"/{randint(*INTERVAL)}?url={randint(*INTERVAL)}",
allow_redirects=False,
catch_response=True,
headers=HEADERS,
) as response:
if response.status_code not in [200, 400]:
response.failure(f"Got wrong response: {response.status_code}")
else:
response.success()
@task(15)
def get_url_stats(self):
with self.client.get(
f"/{randint(*INTERVAL)}/stats", allow_redirects=False, catch_response=True, headers=HEADERS
) as response:
if response.status_code not in [200, 404]:
response.failure(f"Got wrong response: {response.status_code}")
else:
response.success()