-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* clean up ws session handling, limit potential contacts list * setup locust
- Loading branch information
1 parent
2d4e319
commit a21ff0a
Showing
5 changed files
with
1,059 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# locustfile.py | ||
# For more options read the following | ||
# - https://docs.locust.io/en/stable/writing-a-locustfile.html | ||
# - https://docs.locust.io/en/stable/tasksets.html | ||
|
||
from locust import HttpUser, task, between | ||
import gevent, json | ||
from websockets.sync.client import connect | ||
|
||
class TinychatUser(HttpUser): | ||
""" | ||
This class represents simulated users interacting with | ||
a website. | ||
""" | ||
# What tasks should be done | ||
# tasks = [TaskSet] | ||
# how long between clicks a user should take | ||
wait_time = between(2, 20) | ||
# The default host of the target client. This can be changed | ||
# at any time | ||
host = 'http://localhost:5001/' | ||
|
||
def ws_connect(self): | ||
session_cookie = self.client.cookies.get_dict().get('session_') | ||
self.ws = connect("ws://localhost:5001/ws?mid=3", additional_headers={"Cookie": f"session_={session_cookie}"}) | ||
self.ws_greenlet = gevent.spawn(self.ws_receive_loop) | ||
self.ping_greenlet = gevent.spawn(self.ping_loop) | ||
|
||
def ws_receive_loop(self): | ||
while True: | ||
message = self.ws.recv() | ||
print(f"WS Received: {message}") | ||
|
||
def ping_loop(self): | ||
while True: | ||
self.ws.send(json.dumps({"cmd": "ping", "d": {"cid": 1}})) | ||
gevent.sleep(5) | ||
|
||
|
||
@task | ||
def chat(self): | ||
# User goes to the root of the project | ||
self.client.get('/') | ||
self.client.get('/login') | ||
self.client.post('/login', dict(name='locust')) | ||
self.client.post('messages/send/1', dict(msg='Hello, world!')) | ||
|
||
self.ws_connect() | ||
|
||
r = self.client.get('/c/1') | ||
assert r.status_code == 200 |
Oops, something went wrong.