39
39
%s
40
40
"""
41
41
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
+
42
71
TEMPESTA_NGINX_CONFIG = """
43
72
listen 81;
44
73
listen 82 proto=https;
@@ -210,8 +239,7 @@ async def threaded_stress(self, i, port):
210
239
await asyncio .gather (* tasks , return_exceptions = True )
211
240
return 0
212
241
213
- def run_ws (self , port , proxy = False ):
214
- # print("Generate certs")
242
+ def run_ws (self , port , count = 1 , proxy = False ):
215
243
cert_gen ()
216
244
ssl ._create_default_https_context = ssl ._create_unverified_context
217
245
ssl_context = ssl .SSLContext (ssl .PROTOCOL_TLS_SERVER )
@@ -220,7 +248,8 @@ def run_ws(self, port, proxy=False):
220
248
self .start_tempesta ()
221
249
222
250
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 ))
224
253
loop .run_forever ()
225
254
226
255
def test_ping_websockets (self ):
@@ -267,9 +296,39 @@ class Wss_ping_with_nginx(Wss_ping):
267
296
}
268
297
269
298
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 ))
271
300
p2 = Process (target = self .run_test , args = (82 , 4 ))
272
301
p1 .start ()
273
302
p2 .start ()
274
303
p2 .join ()
275
304
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