forked from SvenskaSpel/locust-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocketio.py
executable file
·34 lines (26 loc) · 1.03 KB
/
socketio.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
#!/usr/bin/env python3
import locust_plugins.utils
locust_plugins.utils.gevent_debugger_patch()
from locust import task
from locust.core import TaskSet
from locust_plugins.locusts import SocketIOLocust # pylint: disable=ungrouped-imports
import locust_plugins.listeners # pylint: disable=ungrouped-imports
class UserBehaviour(TaskSet):
@task
def my_task(self):
# example of subscribe
self.locust.send('42["subscribe",{"url":"/sport/matches/11995208/draws","sendInitialUpdate": true}]')
# you can do http in the same taskset as well
self.client.get("/")
# wait for pushes, while occasionally sending heartbeats, like a real client would
self.locust.sleep_with_heartbeat(10)
class MySocketIOLocust(SocketIOLocust):
task_set = UserBehaviour
min_wait = 0
max_wait = 0
if __name__ == "__main__":
host = "http://example.com"
# allow running as executable for debugging
if __name__ == "__main__":
locust_plugins.listeners.PrintListener()
MySocketIOLocust().run()