forked from Super-Ps/locustWebsocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestB.py
37 lines (31 loc) · 1.35 KB
/
testB.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
from locust import TaskSet, task, Locust, events
from socketclient import SocketIOClient
import time
import json
with open('./command.json', mode='r', encoding= 'utf-8') as f:
command = json.load(f)
command_data = (command['mcore'][1], command['mcore'][2])
class SocketIOLocust(Locust):
def __init__(self, *args, **kwargs):
super(SocketIOLocust, self).__init__(*args, **kwargs)
self.client = SocketIOClient()
class ArduinoCompileTask(TaskSet):
@task
def arduinoCompile(self):
start_time = time.time()
try:
self.client.connect('http://arduinoserver-test.makeblock.com')
resd = self.client.emit("compileReq", command_data)
print('emitEnd',resd)
self.client.wait()
except Exception as e:
total_time = int((time.time() - start_time) * 1000)
events.request_failure.fire(request_type="socket", name='total', response_time=total_time, exception=e)
else:
# total_time = int((time.time() - start_time) * 1000)
total_time = int((self.client.get_result_time() - start_time) * 1000)
events.request_success.fire(request_type="socket", name='total', response_time=total_time, response_length=0)
class ExtServiceLocust(SocketIOLocust):
task_set = ArduinoCompileTask
min_wait = 5000
max_wait = 5000