-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlocustfile.py
60 lines (40 loc) · 1.47 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
import time
from locust import Locust, events, task, TaskSet
from errand_boy.transports.unixsocket import UNIXSocketTransport
def capture(func):
name = func.func_name
def wrapper(self, cmd, *args, **kwargs):
start_time = time.time()
response = None
e = None
try:
response = func(self, cmd, *args, **kwargs)
except Exception as e:
pass
total_time = int((time.time() - start_time) * 1000)
if e is None:
print 'response: %s' % (response,)
response_length = len(response[0]) + len(response[1])
events.request_success.fire(request_type=name, name=cmd, response_time=total_time, response_length=response_length)
else:
events.request_failure.fire(request_type=name, name=cmd, response_time=total_time, exception=e)
raise e
return response
return wrapper
class CustomUNIXSocketTransport(UNIXSocketTransport):
run_cmd = capture(UNIXSocketTransport.run_cmd)
class ErrandBoyLocust(Locust):
def __init__(self, *args, **kwargs):
super(ErrandBoyLocust, self).__init__(*args, **kwargs)
self.client = CustomUNIXSocketTransport()
class LoadTestTask(TaskSet):
@task
def run_cmd_ls(self):
self.client.run_cmd('ls -al')
@task
def run_cmd_date(self):
self.client.run_cmd('date')
class LoadTestUser(ErrandBoyLocust):
task_set = LoadTestTask
min_wait = 0
max_wait = 0