Skip to content

Commit 46d2ed4

Browse files
committed
Unifinished test refactoring
1 parent c257b0f commit 46d2ed4

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

tests/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Testing
22
--------
33

4+
Install prerequisites
5+
6+
pip install pytest websocket-client
7+
8+
49
Run unit tests
510

611
pytest

tests/test_message_lengths.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
from time import sleep
2+
import logging
3+
from threading import Thread
4+
5+
import _bootstrap_
6+
from websocket_server import WebsocketServer
7+
from testsuite.messages import *
8+
9+
from websocket import create_connection
10+
11+
'''
12+
This creates just a server that will send a different message to every new connection:
13+
14+
1. A message of length less than 126
15+
2. A message of length 126
16+
3. A message of length 127
17+
4. A message of length bigger than 127
18+
5. A message above 1024
19+
6. A message above 65K
20+
7. An enormous message (well beyond 65K)
21+
22+
Reconnect to get the next message
23+
'''
24+
25+
26+
counter = 0
27+
28+
# Called for every client connecting (after handshake)
29+
def new_client(client, server):
30+
print("New client connected and was given id %d" % client['id'])
31+
global counter
32+
if counter == 0:
33+
print("Sending message 1 of length %d" % len(msg_125B))
34+
server.send_message(client, msg_125B)
35+
elif counter == 1:
36+
print("Sending message 2 of length %d" % len(msg_126B))
37+
server.send_message(client, msg_126B)
38+
elif counter == 2:
39+
print("Sending message 3 of length %d" % len(msg_127B))
40+
server.send_message(client, msg_127B)
41+
elif counter == 3:
42+
print("Sending message 4 of length %d" % len(msg_208B))
43+
server.send_message(client, msg_208B)
44+
elif counter == 4:
45+
print("Sending message 5 of length %d" % len(msg_1251B))
46+
server.send_message(client, msg_1251B)
47+
elif counter == 5:
48+
print("Sending message 6 of length %d" % len(msg_68KB))
49+
server.send_message(client, msg_68KB)
50+
elif counter == 6:
51+
print("Sending message 7 of length %d" % len(msg_1500KB))
52+
server.send_message(client, msg_1500KB)
53+
else:
54+
print("No errors")
55+
counter += 1
56+
57+
58+
PORT = 9001
59+
server = WebsocketServer(PORT, loglevel=logging.DEBUG)
60+
server.set_fn_new_client(new_client)
61+
62+
server_thread = Thread(target=server.run_forever)
63+
64+
server_thread.start()
65+
66+
print('TEST')
67+
68+
ws = create_connection("ws://localhost:%d" % PORT)

0 commit comments

Comments
 (0)