Skip to content

Commit bc4878d

Browse files
committed
Add unfinished stress test
1 parent 433a826 commit bc4878d

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tests/test_text_messages.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,53 @@ def test_text_message_with_unicode_characters(session):
7676
msg = '$äüö^'
7777
server.send_message_to_all(msg)
7878
assert client.recv() == msg
79+
80+
81+
def test_text_message_stress_bursts(session):
82+
""" Scenario: server sends multiple different message to the same client
83+
at once """
84+
from threading import Thread
85+
NUM_THREADS = 100
86+
MESSAGE_LEN = 1000
87+
client, server = session
88+
messages_received = []
89+
90+
# Threads receing
91+
threads_receiving = []
92+
for i in range(NUM_THREADS):
93+
th = Thread(
94+
target=lambda fn: messages_received.append(fn()),
95+
args=(client.recv,)
96+
)
97+
th.daemon = True
98+
threads_receiving.append(th)
99+
100+
# Threads sending different characters each of them
101+
threads_sending = []
102+
for i in range(NUM_THREADS):
103+
message = chr(i)*MESSAGE_LEN
104+
th = Thread(
105+
target=server.send_message_to_all,
106+
args=(message,)
107+
)
108+
th.daemon = True
109+
threads_sending.append(th)
110+
111+
# Run scenario
112+
for th in threads_receiving:
113+
th.start()
114+
for th in threads_sending:
115+
th.start()
116+
117+
# Wait for all threads to finish
118+
print('WAITING FOR THREADS TO FINISH')
119+
for th in threads_receiving:
120+
th.join()
121+
for th in threads_sending:
122+
th.join()
123+
124+
for message in messages_received:
125+
first_char = message[0]
126+
assert message.count(first_char) == len(message)
127+
128+
print()

0 commit comments

Comments
 (0)