Deleted Added
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 # Minimum possible limit
141 shm_limit = 10 * 1024 * 1024
142
143 self.load('mirror', limits={"shm": shm_limit})
144
145 # Should exceed shm_limit
146 max_body_size = 12 * 1024 * 1024
147
148 assert 'success' in self.conf(
149 '{"http":{"max_body_size": ' + str(max_body_size) + ' }}',
150 'settings'
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):
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'
222
223 self.load('mirror', processes=i + 1)
224
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'
241
242 self.load('mirror', processes=i + 1)
243
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'
256
257 self.load('mirror', processes=i + 1)
258
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):
336 self.load('delayed', processes=2)
337
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
367 self.load('empty', module="blah")
368
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):
386 self.load('threads', threads=2)
387
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 ---