Skip to content

Commit 0bc9143

Browse files
committed
Stress for 1000 conns added
Stress after proxy
1 parent c685666 commit 0bc9143

File tree

1 file changed

+63
-4
lines changed

1 file changed

+63
-4
lines changed

ws/test_ws_ping.py

+63-4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,35 @@
3939
%s
4040
"""
4141

42+
TEMPESTA_STRESS_CONFIG = """
43+
listen 81;
44+
listen 82 proto=https;
45+
46+
srv_group localhost {
47+
48+
server ${server_ip}:8099;
49+
server ${server_ip}:8100;
50+
server ${server_ip}:8101;
51+
server ${server_ip}:8102;
52+
server ${server_ip}:8103;
53+
server ${server_ip}:8104;
54+
server ${server_ip}:8105;
55+
server ${server_ip}:8106;
56+
}
57+
58+
vhost localhost {
59+
tls_certificate /tmp/cert.pem;
60+
tls_certificate_key /tmp/key.pem;
61+
62+
proxy_pass localhost;
63+
64+
}
65+
66+
http_chain {
67+
-> localhost;
68+
}
69+
"""
70+
4271
TEMPESTA_NGINX_CONFIG = """
4372
listen 81;
4473
listen 82 proto=https;
@@ -210,8 +239,7 @@ async def threaded_stress(self, i, port):
210239
await asyncio.gather(*tasks, return_exceptions=True)
211240
return 0
212241

213-
def run_ws(self, port, proxy=False):
214-
# print("Generate certs")
242+
def run_ws(self, port, count=1, proxy=False):
215243
cert_gen()
216244
ssl._create_default_https_context = ssl._create_unverified_context
217245
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
@@ -220,7 +248,8 @@ def run_ws(self, port, proxy=False):
220248
self.start_tempesta()
221249

222250
loop = asyncio.get_event_loop()
223-
asyncio.ensure_future(websockets.serve(self.handler, hostname, port))
251+
for i in range(count):
252+
asyncio.ensure_future(websockets.serve(self.handler, hostname, port+i))
224253
loop.run_forever()
225254

226255
def test_ping_websockets(self):
@@ -267,9 +296,39 @@ class Wss_ping_with_nginx(Wss_ping):
267296
}
268297

269298
def test_ping_websockets(self):
270-
p1 = Process(target=self.run_ws, args=(8099, True))
299+
p1 = Process(target=self.run_ws, args=(8099, 1, True))
271300
p2 = Process(target=self.run_test, args=(82, 4))
272301
p1.start()
273302
p2.start()
274303
p2.join()
275304
p1.terminate()
305+
306+
307+
class Wss_stress(Wss_ping):
308+
309+
tempesta = {
310+
'config': TEMPESTA_STRESS_CONFIG,
311+
}
312+
313+
def run_test(self, port, n):
314+
time.sleep(2.0)
315+
asyncio.run(self.wss_ping_test(port, n))
316+
317+
def test_ping_websockets(self):
318+
p1 = Process(target=self.run_ws, args=(8099, 8))
319+
p2 = Process(target=self.run_test, args=(82, 1000))
320+
p1.start()
321+
p2.start()
322+
p2.join()
323+
p1.terminate()
324+
325+
async def wss_ping_test(self, port, n):
326+
host = hostname
327+
ping_message = "ping_test"
328+
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
329+
ssl_context.load_verify_locations("/tmp/cert.pem")
330+
for _ in range(n):
331+
async with websockets.connect(f"wss://{host}:{port}",
332+
ssl=ssl_context) as websocket:
333+
await websocket.send(ping_message)
334+
await websocket.recv()

0 commit comments

Comments
 (0)