-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_long_request.py
297 lines (239 loc) · 8.02 KB
/
test_long_request.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
"""Testing for long body in request."""
__author__ = 'Tempesta Technologies, Inc.'
__copyright__ = 'Copyright (C) 2022 Tempesta Technologies, Inc.'
__license__ = 'GPL2'
from framework import tester, wrk_client, external_client, deproxy_server
from helpers import control, tf_cfg, deproxy
from long_body import utils
NGINX_CONFIG = """
pid ${pid};
worker_processes auto;
events {
worker_connections 1024;
use epoll;
}
http {
keepalive_timeout ${server_keepalive_timeout};
keepalive_requests ${server_keepalive_requests};
sendfile on;
tcp_nopush on;
tcp_nodelay on;
open_file_cache max=1000;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors off;
# [ debug | info | notice | warn | error | crit | alert | emerg ]
# Fully disable log errors.
error_log /dev/null emerg;
# Disable access log altogether.
access_log off;
server {
listen ${server_ip}:8000;
location / {
return 200;
}
location /nginx_status {
stub_status on;
}
}
}
"""
CONCURRENT_CONNECTIONS = int(tf_cfg.cfg.get('General', 'concurrent_connections'))
class RequestTestBase(tester.TempestaTest, base=True):
"""Base class for tests with long body in request."""
tempesta = {
'config': """
listen 80;
listen 443 proto=https;
server ${server_ip}:8000;
tls_certificate ${general_workdir}/tempesta.crt;
tls_certificate_key ${general_workdir}/tempesta.key;
tls_match_any_server_name;
cache 0;
"""
}
clients = [
{
'id': 'wrk-http',
'type': 'wrk',
'addr': '${tempesta_ip}:80',
},
{
'id': 'wrk-https',
'type': 'wrk',
'ssl': True,
'addr': '${tempesta_ip}:443',
},
]
backends = [
{
'id': 'nginx',
'type': 'nginx',
'port': '8000',
'status_uri': 'http://${server_ip}:8000/nginx_status',
'config': NGINX_CONFIG,
},
]
wrk_method: str
wrk_path = '/'
wrk_body: str
client_id: str
wrk_content = (
'wrk.method = "%(method)s"\n'
+ 'wrk.path = "%(path)s"\n'
+ 'wrk.header = {\n'
+ '}\n'
+ 'wrk.body = "%(body)s"\n'
)
def setUp(self):
"""Set 'wrk' content for tests"""
self.wrk_content = self.wrk_content % {
'method': self.wrk_method,
'path': self.wrk_path,
'body': self.wrk_body,
}
super().setUp()
def start_all(self):
"""Start servers, tempesta and check servers is running"""
self.start_all_servers()
self.start_tempesta()
self.assertTrue(self.wait_all_connections())
def test(self):
"""Send requests for wrk client with body and check tempesta/wrk statistic."""
self.start_all()
tempesta: control.Tempesta = self.get_tempesta()
client: wrk_client.Wrk = self.get_client(self.client_id)
client.set_script(script='request_1k', content=self.wrk_content)
client.start()
self.wait_while_busy(client)
client.stop()
tempesta.get_stats()
results = client.results()
statuses = client.statuses
utils.debug_tempesta(results, tempesta)
self.assertEqual(
results[1],
utils.get_sum_5xx_and_connection_errors(statuses),
msg='HTTP client detected %i/%i errors. Results: %s' % (
results[0], results[1], str(statuses),
),
)
self.assertTrue(
results[0] <= tempesta.stats.cl_msg_received <= (results[0] + client.connections),
msg='Tempesta received bad number %d of messages, expected [%d:%d]'
% (tempesta.stats.cl_msg_received, results[0], (results[0] + client.connections)),
)
self.assertGreater(client.statuses[200], 0, 'Client has not received 200 responses.')
class HttpPostRequestTest1k(RequestTestBase):
"""Send many POST HTTP requests with 1k body and check tempesta/wrk statistic."""
wrk_method = 'POST'
wrk_body = 'x' * 1024
client_id = 'wrk-http'
class HttpPostRequestTest1M(RequestTestBase):
"""Send many POST HTTP requests with 1M body and check tempesta/wrk statistic."""
wrk_method = 'POST'
wrk_body = 'x' * 1024 ** 2
client_id = 'wrk-http'
class HttpPutRequestTest1k(RequestTestBase):
"""Send many PUT HTTP requests with 1k body and check tempesta/wrk statistic."""
wrk_method = 'PUT'
wrk_body = 'x' * 1024
client_id = 'wrk-http'
class HttpPutRequestTest1M(RequestTestBase):
"""Send many PUT HTTP requests with 1M body and check tempesta/wrk statistic."""
wrk_method = 'PUT'
wrk_body = 'x' * 1024 ** 2
client_id = 'wrk-http'
class HttpsPostRequestTest1k(RequestTestBase):
"""Send many POST HTTPS requests with 1k body and check tempesta/wrk statistic."""
wrk_method = 'POST'
wrk_body = 'x' * 1024
client_id = 'wrk-https'
class HttpsPostRequestTest1M(RequestTestBase):
"""Send many POST HTTPS requests with 1M body and check tempesta/wrk statistic."""
wrk_method = 'POST'
wrk_body = 'x' * 1024 ** 2
client_id = 'wrk-https'
class HttpsPutRequestTest1k(RequestTestBase):
"""Send many PUT HTTPS requests with 1k body and check tempesta/wrk statistic."""
wrk_method = 'PUT'
wrk_body = 'x' * 1024
client_id = 'wrk-https'
class HttpsPutRequestTest1M(RequestTestBase):
"""Send many PUT HTTPS requests with 1M body and check tempesta/wrk statistic."""
wrk_method = 'PUT'
wrk_body = 'x' * 1024 ** 2
client_id = 'wrk-https'
class H2RequestTestBase(tester.TempestaTest, base=True):
"""Base class for h2 tests with long body in request."""
tempesta = {'config': """
listen 443 proto=h2;
server ${server_ip}:8000;
tls_certificate ${general_workdir}/tempesta.crt;
tls_certificate_key ${general_workdir}/tempesta.key;
tls_match_any_server_name;
cache 0;
"""}
body = 'x' * 1024
clients = [
{
'id': 'concurrent',
'type': 'external',
'binary': 'curl',
'ssl': True,
'cmd_args': (
' --http2-prior-knowledge'
+ ' --insecure'
+ ' --parallel'
+ ' --parallel-immediate'
+ f' --parallel-max {CONCURRENT_CONNECTIONS}'
+ f' --max-time {tf_cfg.cfg.get("General", "duration")}'
),
}
]
backends = [
{
'id': 'deproxy',
'type': 'deproxy',
'port': '8000',
'response': 'static',
'response_content': (
'HTTP/1.1 200 OK\r\n'
+ 'Server: deproxy\r\n'
+ f'Date: {deproxy.HttpMessage.date_time_string()}\r\n'
+ 'Content-Length: 0\r\n'
+ '\r\n'
),
},
]
method: str
body_length: int
def start_all(self):
self.start_all_servers()
self.start_tempesta()
self.deproxy_manager.start()
self.assertTrue(self.wait_all_connections())
def test_request_long_body(self):
"""Send many h2 requests with long body and """
self.start_all()
client: external_client.ExternalTester = self.get_client('concurrent')
server: deproxy_server.StaticDeproxyServer = self.get_server('deproxy')
tempesta = self.get_tempesta()
count_requests = 10000
client.options[0] += (
f' -X {self.method}'
+ f" -H 'Content-Length: {self.body_length}'"
+ f" -d '{'x' * self.body_length}'"
+ f" https://127.0.0.1:443/[1-{count_requests}]"
)
client.start()
self.wait_while_busy()
client.stop()
class H2PostRequestTest1k(H2RequestTestBase):
"""Send many POST h2 requests with 1k body."""
method = 'POST'
body_length = 1024
class H2PutRequestTest1k(H2RequestTestBase):
"""Send many PUT h2 requests with 1k body."""
method = 'PUT'
body_length = 1024