test_asgi_application.py (1692:d9af486b8a38) test_asgi_application.py (1695:48cd8f20dea4)
1import re
2import time
3from distutils.version import LooseVersion
4
5import pytest
6
7from conftest import option
8from conftest import skip_alert

--- 123 unchanged lines hidden (view full) ---

132 def test_asgi_application_204_transfer_encoding(self):
133 self.load('204_no_content')
134
135 assert (
136 'Transfer-Encoding' not in self.get()['headers']
137 ), '204 header transfer encoding'
138
139 def test_asgi_application_shm_ack_handle(self):
1import re
2import time
3from distutils.version import LooseVersion
4
5import pytest
6
7from conftest import option
8from conftest import skip_alert

--- 123 unchanged lines hidden (view full) ---

132 def test_asgi_application_204_transfer_encoding(self):
133 self.load('204_no_content')
134
135 assert (
136 'Transfer-Encoding' not in self.get()['headers']
137 ), '204 header transfer encoding'
138
139 def test_asgi_application_shm_ack_handle(self):
140 self.load('mirror')
141
142 # Minimum possible limit
143 shm_limit = 10 * 1024 * 1024
144
140 # Minimum possible limit
141 shm_limit = 10 * 1024 * 1024
142
145 assert (
146 'success' in self.conf('{"shm": ' + str(shm_limit) + '}',
147 'applications/mirror/limits')
148 )
143 self.load('mirror', limits={"shm": shm_limit})
149
150 # Should exceed shm_limit
151 max_body_size = 12 * 1024 * 1024
152
144
145 # Should exceed shm_limit
146 max_body_size = 12 * 1024 * 1024
147
153 assert (
154 'success' in self.conf('{"http":{"max_body_size": '
155 + str(max_body_size) + ' }}',
156 'settings')
148 assert 'success' in self.conf(
149 '{"http":{"max_body_size": ' + str(max_body_size) + ' }}',
150 'settings'
157 )
158
159 assert self.get()['status'] == 200, 'init'
160
161 body = '0123456789AB' * 1024 * 1024 # 12 Mb
162 resp = self.post(
163 headers={
164 'Host': 'localhost',

--- 34 unchanged lines hidden (view full) ---

199 },
200 sock=sock,
201 body=body,
202 )
203
204 assert resp['body'] == body, 'keep-alive 2'
205
206 def test_asgi_keepalive_reconfigure(self):
151 )
152
153 assert self.get()['status'] == 200, 'init'
154
155 body = '0123456789AB' * 1024 * 1024 # 12 Mb
156 resp = self.post(
157 headers={
158 'Host': 'localhost',

--- 34 unchanged lines hidden (view full) ---

193 },
194 sock=sock,
195 body=body,
196 )
197
198 assert resp['body'] == body, 'keep-alive 2'
199
200 def test_asgi_keepalive_reconfigure(self):
207 skip_alert(
208 r'pthread_mutex.+failed',
209 r'failed to apply',
210 r'process \d+ exited on signal',
211 )
212 self.load('mirror')
213
214 assert self.get()['status'] == 200, 'init'
215
216 body = '0123456789'
217 conns = 3
218 socks = []
219

--- 5 unchanged lines hidden (view full) ---

225 'Content-Type': 'text/html',
226 },
227 start=True,
228 body=body,
229 read_timeout=1,
230 )
231
232 assert resp['body'] == body, 'keep-alive open'
201 self.load('mirror')
202
203 assert self.get()['status'] == 200, 'init'
204
205 body = '0123456789'
206 conns = 3
207 socks = []
208

--- 5 unchanged lines hidden (view full) ---

214 'Content-Type': 'text/html',
215 },
216 start=True,
217 body=body,
218 read_timeout=1,
219 )
220
221 assert resp['body'] == body, 'keep-alive open'
233 assert 'success' in self.conf(
234 str(i + 1), 'applications/mirror/processes'
235 ), 'reconfigure'
236
222
223 self.load('mirror', processes=i + 1)
224
237 socks.append(sock)
238
239 for i in range(conns):
240 (resp, sock) = self.post(
241 headers={
242 'Host': 'localhost',
243 'Connection': 'keep-alive',
244 'Content-Type': 'text/html',
245 },
246 start=True,
247 sock=socks[i],
248 body=body,
249 read_timeout=1,
250 )
251
252 assert resp['body'] == body, 'keep-alive request'
225 socks.append(sock)
226
227 for i in range(conns):
228 (resp, sock) = self.post(
229 headers={
230 'Host': 'localhost',
231 'Connection': 'keep-alive',
232 'Content-Type': 'text/html',
233 },
234 start=True,
235 sock=socks[i],
236 body=body,
237 read_timeout=1,
238 )
239
240 assert resp['body'] == body, 'keep-alive request'
253 assert 'success' in self.conf(
254 str(i + 1), 'applications/mirror/processes'
255 ), 'reconfigure 2'
256
241
242 self.load('mirror', processes=i + 1)
243
257 for i in range(conns):
258 resp = self.post(
259 headers={
260 'Host': 'localhost',
261 'Connection': 'close',
262 'Content-Type': 'text/html',
263 },
264 sock=socks[i],
265 body=body,
266 )
267
268 assert resp['body'] == body, 'keep-alive close'
244 for i in range(conns):
245 resp = self.post(
246 headers={
247 'Host': 'localhost',
248 'Connection': 'close',
249 'Content-Type': 'text/html',
250 },
251 sock=socks[i],
252 body=body,
253 )
254
255 assert resp['body'] == body, 'keep-alive close'
269 assert 'success' in self.conf(
270 str(i + 1), 'applications/mirror/processes'
271 ), 'reconfigure 3'
272
256
257 self.load('mirror', processes=i + 1)
258
273 def test_asgi_keepalive_reconfigure_2(self):
274 self.load('mirror')
275
276 assert self.get()['status'] == 200, 'init'
277
278 body = '0123456789'
279
280 (resp, sock) = self.post(

--- 61 unchanged lines hidden (view full) ---

342""",
343 sock=sock,
344 raw=True,
345 )
346
347 assert resp['status'] == 200, 'reconfigure 3'
348
349 def test_asgi_process_switch(self):
259 def test_asgi_keepalive_reconfigure_2(self):
260 self.load('mirror')
261
262 assert self.get()['status'] == 200, 'init'
263
264 body = '0123456789'
265
266 (resp, sock) = self.post(

--- 61 unchanged lines hidden (view full) ---

328""",
329 sock=sock,
330 raw=True,
331 )
332
333 assert resp['status'] == 200, 'reconfigure 3'
334
335 def test_asgi_process_switch(self):
350 self.load('delayed')
336 self.load('delayed', processes=2)
351
337
352 assert 'success' in self.conf(
353 '2', 'applications/delayed/processes'
354 ), 'configure 2 processes'
355
356 self.get(
357 headers={
358 'Host': 'localhost',
359 'Content-Length': '0',
360 'X-Delay': '5',
361 'Connection': 'close',
362 },
363 no_recv=True,

--- 13 unchanged lines hidden (view full) ---

377 for _ in range(10):
378 self.get(headers=headers_delay_1, no_recv=True)
379
380 self.get(headers=headers_delay_1)
381
382 def test_asgi_application_loading_error(self):
383 skip_alert(r'Python failed to import module "blah"')
384
338 self.get(
339 headers={
340 'Host': 'localhost',
341 'Content-Length': '0',
342 'X-Delay': '5',
343 'Connection': 'close',
344 },
345 no_recv=True,

--- 13 unchanged lines hidden (view full) ---

359 for _ in range(10):
360 self.get(headers=headers_delay_1, no_recv=True)
361
362 self.get(headers=headers_delay_1)
363
364 def test_asgi_application_loading_error(self):
365 skip_alert(r'Python failed to import module "blah"')
366
385 self.load('empty')
367 self.load('empty', module="blah")
386
368
387 assert 'success' in self.conf('"blah"', 'applications/empty/module')
388
389 assert self.get()['status'] == 503, 'loading error'
390
391 def test_asgi_application_threading(self):
392 """wait_for_record() timeouts after 5s while every thread works at
393 least 3s. So without releasing GIL test should fail.
394 """
395
396 self.load('threading')
397
398 for _ in range(10):
399 self.get(no_recv=True)
400
401 assert (
402 self.wait_for_record(r'\(5\) Thread: 100') is not None
403 ), 'last thread finished'
404
405 def test_asgi_application_threads(self):
369 assert self.get()['status'] == 503, 'loading error'
370
371 def test_asgi_application_threading(self):
372 """wait_for_record() timeouts after 5s while every thread works at
373 least 3s. So without releasing GIL test should fail.
374 """
375
376 self.load('threading')
377
378 for _ in range(10):
379 self.get(no_recv=True)
380
381 assert (
382 self.wait_for_record(r'\(5\) Thread: 100') is not None
383 ), 'last thread finished'
384
385 def test_asgi_application_threads(self):
406 self.load('threads')
386 self.load('threads', threads=2)
407
387
408 assert 'success' in self.conf(
409 '2', 'applications/threads/threads'
410 ), 'configure 2 threads'
411
412 socks = []
413
414 for i in range(2):
415 (_, sock) = self.get(
416 headers={
417 'Host': 'localhost',
418 'X-Delay': '3',
419 'Connection': 'close',

--- 25 unchanged lines hidden ---
388 socks = []
389
390 for i in range(2):
391 (_, sock) = self.get(
392 headers={
393 'Host': 'localhost',
394 'X-Delay': '3',
395 'Connection': 'close',

--- 25 unchanged lines hidden ---