xref: /unit/test/test_ruby_application.py (revision 2094:bd03c2f490d7)
11596Szelenkov@nginx.comimport re
21842Szelenkov@nginx.comimport subprocess
31477Szelenkov@nginx.com
41635Szelenkov@nginx.comimport pytest
51019Szelenkov@nginx.comfrom unit.applications.lang.ruby import TestApplicationRuby
6585Szelenkov@nginx.com
71017Szelenkov@nginx.com
81019Szelenkov@nginx.comclass TestRubyApplication(TestApplicationRuby):
91467Szelenkov@nginx.com    prerequisites = {'modules': {'ruby': 'all'}}
10585Szelenkov@nginx.com
11585Szelenkov@nginx.com    def test_ruby_application(self):
12585Szelenkov@nginx.com        self.load('variables')
13585Szelenkov@nginx.com
14585Szelenkov@nginx.com        body = 'Test body string.'
15585Szelenkov@nginx.com
161017Szelenkov@nginx.com        resp = self.post(
171017Szelenkov@nginx.com            headers={
181017Szelenkov@nginx.com                'Host': 'localhost',
191017Szelenkov@nginx.com                'Content-Type': 'text/html',
201017Szelenkov@nginx.com                'Custom-Header': 'blah',
211017Szelenkov@nginx.com                'Connection': 'close',
221017Szelenkov@nginx.com            },
231017Szelenkov@nginx.com            body=body,
241017Szelenkov@nginx.com        )
25585Szelenkov@nginx.com
261596Szelenkov@nginx.com        assert resp['status'] == 200, 'status'
27585Szelenkov@nginx.com        headers = resp['headers']
28674Szelenkov@nginx.com        header_server = headers.pop('Server')
291596Szelenkov@nginx.com        assert re.search(r'Unit/[\d\.]+', header_server), 'server header'
301596Szelenkov@nginx.com        assert (
311596Szelenkov@nginx.com            headers.pop('Server-Software') == header_server
321596Szelenkov@nginx.com        ), 'server software header'
33599Szelenkov@nginx.com
34599Szelenkov@nginx.com        date = headers.pop('Date')
351596Szelenkov@nginx.com        assert date[-4:] == ' GMT', 'date header timezone'
361596Szelenkov@nginx.com        assert (
371596Szelenkov@nginx.com            abs(self.date_to_sec_epoch(date) - self.sec_epoch()) < 5
381596Szelenkov@nginx.com        ), 'date header'
39599Szelenkov@nginx.com
401596Szelenkov@nginx.com        assert headers == {
411596Szelenkov@nginx.com            'Connection': 'close',
421596Szelenkov@nginx.com            'Content-Length': str(len(body)),
431596Szelenkov@nginx.com            'Content-Type': 'text/html',
441596Szelenkov@nginx.com            'Request-Method': 'POST',
451596Szelenkov@nginx.com            'Request-Uri': '/',
461596Szelenkov@nginx.com            'Http-Host': 'localhost',
472088Szelenkov@nginx.com            'Script-Name': 'config.ru',
481596Szelenkov@nginx.com            'Server-Protocol': 'HTTP/1.1',
491596Szelenkov@nginx.com            'Custom-Header': 'blah',
501596Szelenkov@nginx.com            'Rack-Version': '13',
511596Szelenkov@nginx.com            'Rack-Url-Scheme': 'http',
521596Szelenkov@nginx.com            'Rack-Multithread': 'false',
531596Szelenkov@nginx.com            'Rack-Multiprocess': 'true',
541596Szelenkov@nginx.com            'Rack-Run-Once': 'false',
551596Szelenkov@nginx.com            'Rack-Hijack-Q': 'false',
561596Szelenkov@nginx.com            'Rack-Hijack': '',
571596Szelenkov@nginx.com            'Rack-Hijack-IO': '',
581596Szelenkov@nginx.com        }, 'headers'
591596Szelenkov@nginx.com        assert resp['body'] == body, 'body'
60585Szelenkov@nginx.com
61585Szelenkov@nginx.com    def test_ruby_application_query_string(self):
62585Szelenkov@nginx.com        self.load('query_string')
63585Szelenkov@nginx.com
64585Szelenkov@nginx.com        resp = self.get(url='/?var1=val1&var2=val2')
65585Szelenkov@nginx.com
661596Szelenkov@nginx.com        assert (
671596Szelenkov@nginx.com            resp['headers']['Query-String'] == 'var1=val1&var2=val2'
681596Szelenkov@nginx.com        ), 'Query-String header'
69585Szelenkov@nginx.com
70894Szelenkov@nginx.com    def test_ruby_application_query_string_empty(self):
71894Szelenkov@nginx.com        self.load('query_string')
72894Szelenkov@nginx.com
73894Szelenkov@nginx.com        resp = self.get(url='/?')
74894Szelenkov@nginx.com
751596Szelenkov@nginx.com        assert resp['status'] == 200, 'query string empty status'
761596Szelenkov@nginx.com        assert resp['headers']['Query-String'] == '', 'query string empty'
77894Szelenkov@nginx.com
78894Szelenkov@nginx.com    def test_ruby_application_query_string_absent(self):
79894Szelenkov@nginx.com        self.load('query_string')
80894Szelenkov@nginx.com
81894Szelenkov@nginx.com        resp = self.get()
82894Szelenkov@nginx.com
831596Szelenkov@nginx.com        assert resp['status'] == 200, 'query string absent status'
841596Szelenkov@nginx.com        assert resp['headers']['Query-String'] == '', 'query string absent'
85894Szelenkov@nginx.com
861596Szelenkov@nginx.com    @pytest.mark.skip('not yet')
87585Szelenkov@nginx.com    def test_ruby_application_server_port(self):
88585Szelenkov@nginx.com        self.load('server_port')
89585Szelenkov@nginx.com
901596Szelenkov@nginx.com        assert (
911596Szelenkov@nginx.com            self.get()['headers']['Server-Port'] == '7080'
921596Szelenkov@nginx.com        ), 'Server-Port header'
93585Szelenkov@nginx.com
94585Szelenkov@nginx.com    def test_ruby_application_status_int(self):
95585Szelenkov@nginx.com        self.load('status_int')
96585Szelenkov@nginx.com
971596Szelenkov@nginx.com        assert self.get()['status'] == 200, 'status int'
98585Szelenkov@nginx.com
99585Szelenkov@nginx.com    def test_ruby_application_input_read_empty(self):
100585Szelenkov@nginx.com        self.load('input_read_empty')
101585Szelenkov@nginx.com
1021596Szelenkov@nginx.com        assert self.get()['body'] == '', 'read empty'
103585Szelenkov@nginx.com
104585Szelenkov@nginx.com    def test_ruby_application_input_read_parts(self):
105585Szelenkov@nginx.com        self.load('input_read_parts')
106585Szelenkov@nginx.com
1071596Szelenkov@nginx.com        assert (
1081596Szelenkov@nginx.com            self.post(body='0123456789')['body'] == '012345678'
1091596Szelenkov@nginx.com        ), 'input read parts'
110585Szelenkov@nginx.com
111585Szelenkov@nginx.com    def test_ruby_application_input_read_buffer(self):
112585Szelenkov@nginx.com        self.load('input_read_buffer')
113585Szelenkov@nginx.com
1141596Szelenkov@nginx.com        assert (
1151596Szelenkov@nginx.com            self.post(body='0123456789')['body'] == '0123456789'
1161596Szelenkov@nginx.com        ), 'input read buffer'
117585Szelenkov@nginx.com
118585Szelenkov@nginx.com    def test_ruby_application_input_read_buffer_not_empty(self):
119585Szelenkov@nginx.com        self.load('input_read_buffer_not_empty')
120585Szelenkov@nginx.com
1211596Szelenkov@nginx.com        assert (
1221596Szelenkov@nginx.com            self.post(body='0123456789')['body'] == '0123456789'
1231596Szelenkov@nginx.com        ), 'input read buffer not empty'
124585Szelenkov@nginx.com
125585Szelenkov@nginx.com    def test_ruby_application_input_gets(self):
126585Szelenkov@nginx.com        self.load('input_gets')
127585Szelenkov@nginx.com
128585Szelenkov@nginx.com        body = '0123456789'
129585Szelenkov@nginx.com
1301596Szelenkov@nginx.com        assert self.post(body=body)['body'] == body, 'input gets'
131585Szelenkov@nginx.com
132585Szelenkov@nginx.com    def test_ruby_application_input_gets_2(self):
133585Szelenkov@nginx.com        self.load('input_gets')
134585Szelenkov@nginx.com
1351596Szelenkov@nginx.com        assert (
1361596Szelenkov@nginx.com            self.post(body='01234\n56789\n')['body'] == '01234\n'
1371596Szelenkov@nginx.com        ), 'input gets 2'
138585Szelenkov@nginx.com
139585Szelenkov@nginx.com    def test_ruby_application_input_gets_all(self):
140585Szelenkov@nginx.com        self.load('input_gets_all')
141585Szelenkov@nginx.com
142585Szelenkov@nginx.com        body = '\n01234\n56789\n\n'
143585Szelenkov@nginx.com
1441596Szelenkov@nginx.com        assert self.post(body=body)['body'] == body, 'input gets all'
145585Szelenkov@nginx.com
146585Szelenkov@nginx.com    def test_ruby_application_input_each(self):
147585Szelenkov@nginx.com        self.load('input_each')
148585Szelenkov@nginx.com
149585Szelenkov@nginx.com        body = '\n01234\n56789\n\n'
150585Szelenkov@nginx.com
1511596Szelenkov@nginx.com        assert self.post(body=body)['body'] == body, 'input each'
152585Szelenkov@nginx.com
1531596Szelenkov@nginx.com    @pytest.mark.skip('not yet')
154585Szelenkov@nginx.com    def test_ruby_application_input_rewind(self):
155585Szelenkov@nginx.com        self.load('input_rewind')
156585Szelenkov@nginx.com
157585Szelenkov@nginx.com        body = '0123456789'
158585Szelenkov@nginx.com
1591596Szelenkov@nginx.com        assert self.post(body=body)['body'] == body, 'input rewind'
160585Szelenkov@nginx.com
1611596Szelenkov@nginx.com    @pytest.mark.skip('not yet')
1621736Szelenkov@nginx.com    def test_ruby_application_syntax_error(self, skip_alert):
1631596Szelenkov@nginx.com        skip_alert(
1641596Szelenkov@nginx.com            r'Failed to parse rack script',
1651596Szelenkov@nginx.com            r'syntax error',
1661596Szelenkov@nginx.com            r'new_from_string',
1671596Szelenkov@nginx.com            r'parse_file',
1681017Szelenkov@nginx.com        )
169585Szelenkov@nginx.com        self.load('syntax_error')
170585Szelenkov@nginx.com
1711596Szelenkov@nginx.com        assert self.get()['status'] == 500, 'syntax error'
172585Szelenkov@nginx.com
173585Szelenkov@nginx.com    def test_ruby_application_errors_puts(self):
174585Szelenkov@nginx.com        self.load('errors_puts')
175585Szelenkov@nginx.com
176*2094Szelenkov@nginx.com        assert self.get()['status'] == 200
177585Szelenkov@nginx.com
1781596Szelenkov@nginx.com        assert (
1792073Szelenkov@nginx.com            self.wait_for_record(r'\[error\].+Error in application') is not None
1801596Szelenkov@nginx.com        ), 'errors puts'
181585Szelenkov@nginx.com
182585Szelenkov@nginx.com    def test_ruby_application_errors_puts_int(self):
183585Szelenkov@nginx.com        self.load('errors_puts_int')
184585Szelenkov@nginx.com
185*2094Szelenkov@nginx.com        assert self.get()['status'] == 200
186585Szelenkov@nginx.com
1871596Szelenkov@nginx.com        assert (
1881596Szelenkov@nginx.com            self.wait_for_record(r'\[error\].+1234567890') is not None
1891596Szelenkov@nginx.com        ), 'errors puts int'
190585Szelenkov@nginx.com
191585Szelenkov@nginx.com    def test_ruby_application_errors_write(self):
192585Szelenkov@nginx.com        self.load('errors_write')
193585Szelenkov@nginx.com
194*2094Szelenkov@nginx.com        assert self.get()['status'] == 200
1951596Szelenkov@nginx.com        assert (
1962073Szelenkov@nginx.com            self.wait_for_record(r'\[error\].+Error in application') is not None
1971596Szelenkov@nginx.com        ), 'errors write'
198585Szelenkov@nginx.com
199585Szelenkov@nginx.com    def test_ruby_application_errors_write_to_s_custom(self):
200585Szelenkov@nginx.com        self.load('errors_write_to_s_custom')
201585Szelenkov@nginx.com
2021596Szelenkov@nginx.com        assert self.get()['status'] == 200, 'errors write to_s custom'
203585Szelenkov@nginx.com
204585Szelenkov@nginx.com    def test_ruby_application_errors_write_int(self):
205585Szelenkov@nginx.com        self.load('errors_write_int')
206585Szelenkov@nginx.com
207*2094Szelenkov@nginx.com        assert self.get()['status'] == 200
2081596Szelenkov@nginx.com        assert (
2091596Szelenkov@nginx.com            self.wait_for_record(r'\[error\].+1234567890') is not None
2101596Szelenkov@nginx.com        ), 'errors write int'
211585Szelenkov@nginx.com
212585Szelenkov@nginx.com    def test_ruby_application_at_exit(self):
213585Szelenkov@nginx.com        self.load('at_exit')
214585Szelenkov@nginx.com
215*2094Szelenkov@nginx.com        assert self.get()['status'] == 200
216585Szelenkov@nginx.com
2171775Szelenkov@nginx.com        assert 'success' in self.conf({"listeners": {}, "applications": {}})
218585Szelenkov@nginx.com
2191596Szelenkov@nginx.com        assert (
2201596Szelenkov@nginx.com            self.wait_for_record(r'\[error\].+At exit called\.') is not None
2211596Szelenkov@nginx.com        ), 'at exit'
222585Szelenkov@nginx.com
2231842Szelenkov@nginx.com    def test_ruby_application_encoding(self):
2241842Szelenkov@nginx.com        self.load('encoding')
2251842Szelenkov@nginx.com
2261842Szelenkov@nginx.com        try:
2271848Szelenkov@nginx.com            locales = (
2281848Szelenkov@nginx.com                subprocess.check_output(
2292073Szelenkov@nginx.com                    ['locale', '-a'],
2302073Szelenkov@nginx.com                    stderr=subprocess.STDOUT,
2311848Szelenkov@nginx.com                )
2321848Szelenkov@nginx.com                .decode()
2331848Szelenkov@nginx.com                .split('\n')
2341848Szelenkov@nginx.com            )
2351842Szelenkov@nginx.com
2361842Szelenkov@nginx.com        except (FileNotFoundError, subprocess.CalledProcessError):
2371842Szelenkov@nginx.com            pytest.skip('require locale')
2381842Szelenkov@nginx.com
2391842Szelenkov@nginx.com        def get_locale(pattern):
2401842Szelenkov@nginx.com            return next(
2411842Szelenkov@nginx.com                (
2421842Szelenkov@nginx.com                    l
2431842Szelenkov@nginx.com                    for l in locales
2441842Szelenkov@nginx.com                    if re.match(pattern, l.upper()) is not None
2451842Szelenkov@nginx.com                ),
2461842Szelenkov@nginx.com                None,
2471842Szelenkov@nginx.com            )
2481842Szelenkov@nginx.com
2491842Szelenkov@nginx.com        utf8 = get_locale(r'.*UTF[-_]?8')
2501842Szelenkov@nginx.com        iso88591 = get_locale(r'.*ISO[-_]?8859[-_]?1')
2511842Szelenkov@nginx.com
2521842Szelenkov@nginx.com        def check_locale(enc):
2531842Szelenkov@nginx.com            assert 'success' in self.conf(
2541847Szelenkov@nginx.com                {"LC_CTYPE": enc, "LC_ALL": ""},
2551847Szelenkov@nginx.com                '/config/applications/encoding/environment',
2561842Szelenkov@nginx.com            )
2571842Szelenkov@nginx.com
2581842Szelenkov@nginx.com            resp = self.get()
2591842Szelenkov@nginx.com            assert resp['status'] == 200, 'status'
2601842Szelenkov@nginx.com
2611842Szelenkov@nginx.com            enc_default = re.sub(r'[-_]', '', resp['headers']['X-Enc']).upper()
2621842Szelenkov@nginx.com            assert (
2631842Szelenkov@nginx.com                enc_default == re.sub(r'[-_]', '', enc.split('.')[-1]).upper()
2641842Szelenkov@nginx.com            )
2651842Szelenkov@nginx.com
2661842Szelenkov@nginx.com        if utf8:
2671842Szelenkov@nginx.com            check_locale(utf8)
2681842Szelenkov@nginx.com
2691842Szelenkov@nginx.com        if iso88591:
2701842Szelenkov@nginx.com            check_locale(iso88591)
2711842Szelenkov@nginx.com
2721842Szelenkov@nginx.com        if not utf8 and not iso88591:
2731842Szelenkov@nginx.com            pytest.skip('no available locales')
2741842Szelenkov@nginx.com
275585Szelenkov@nginx.com    def test_ruby_application_header_custom(self):
276585Szelenkov@nginx.com        self.load('header_custom')
277585Szelenkov@nginx.com
278585Szelenkov@nginx.com        resp = self.post(body="\ntc=one,two\ntc=three,four,\n\n")
279585Szelenkov@nginx.com
2801596Szelenkov@nginx.com        assert resp['headers']['Custom-Header'] == [
2811596Szelenkov@nginx.com            '',
2821596Szelenkov@nginx.com            'tc=one,two',
2831596Szelenkov@nginx.com            'tc=three,four,',
2841596Szelenkov@nginx.com            '',
2851596Szelenkov@nginx.com            '',
2861596Szelenkov@nginx.com        ], 'header custom'
287585Szelenkov@nginx.com
2881596Szelenkov@nginx.com    @pytest.mark.skip('not yet')
289585Szelenkov@nginx.com    def test_ruby_application_header_custom_non_printable(self):
290585Szelenkov@nginx.com        self.load('header_custom')
291585Szelenkov@nginx.com
2921596Szelenkov@nginx.com        assert (
2931596Szelenkov@nginx.com            self.post(body='\b')['status'] == 500
2941596Szelenkov@nginx.com        ), 'header custom non printable'
295585Szelenkov@nginx.com
296585Szelenkov@nginx.com    def test_ruby_application_header_status(self):
297585Szelenkov@nginx.com        self.load('header_status')
298585Szelenkov@nginx.com
2991596Szelenkov@nginx.com        assert self.get()['status'] == 200, 'header status'
300585Szelenkov@nginx.com
3011596Szelenkov@nginx.com    @pytest.mark.skip('not yet')
302585Szelenkov@nginx.com    def test_ruby_application_header_rack(self):
303585Szelenkov@nginx.com        self.load('header_rack')
304585Szelenkov@nginx.com
3051596Szelenkov@nginx.com        assert self.get()['status'] == 500, 'header rack'
306585Szelenkov@nginx.com
307585Szelenkov@nginx.com    def test_ruby_application_body_empty(self):
308585Szelenkov@nginx.com        self.load('body_empty')
309585Szelenkov@nginx.com
3101596Szelenkov@nginx.com        assert self.get()['body'] == '', 'body empty'
311585Szelenkov@nginx.com
312585Szelenkov@nginx.com    def test_ruby_application_body_array(self):
313585Szelenkov@nginx.com        self.load('body_array')
314585Szelenkov@nginx.com
3151596Szelenkov@nginx.com        assert self.get()['body'] == '0123456789', 'body array'
316585Szelenkov@nginx.com
317585Szelenkov@nginx.com    def test_ruby_application_body_large(self):
318585Szelenkov@nginx.com        self.load('mirror')
319585Szelenkov@nginx.com
320585Szelenkov@nginx.com        body = '0123456789' * 1000
321585Szelenkov@nginx.com
3221596Szelenkov@nginx.com        assert self.post(body=body)['body'] == body, 'body large'
323585Szelenkov@nginx.com
3241596Szelenkov@nginx.com    @pytest.mark.skip('not yet')
325585Szelenkov@nginx.com    def test_ruby_application_body_each_error(self):
326585Szelenkov@nginx.com        self.load('body_each_error')
327585Szelenkov@nginx.com
3281596Szelenkov@nginx.com        assert self.get()['status'] == 500, 'body each error status'
329585Szelenkov@nginx.com
3301596Szelenkov@nginx.com        assert (
3311596Szelenkov@nginx.com            self.wait_for_record(r'\[error\].+Failed to run ruby script')
3321596Szelenkov@nginx.com            is not None
3331596Szelenkov@nginx.com        ), 'body each error'
334585Szelenkov@nginx.com
335585Szelenkov@nginx.com    def test_ruby_application_body_file(self):
336585Szelenkov@nginx.com        self.load('body_file')
337585Szelenkov@nginx.com
3381596Szelenkov@nginx.com        assert self.get()['body'] == 'body\n', 'body file'
339585Szelenkov@nginx.com
340585Szelenkov@nginx.com    def test_ruby_keepalive_body(self):
341585Szelenkov@nginx.com        self.load('mirror')
342585Szelenkov@nginx.com
3431596Szelenkov@nginx.com        assert self.get()['status'] == 200, 'init'
3441029Szelenkov@nginx.com
3451453Szelenkov@nginx.com        body = '0123456789' * 500
3461017Szelenkov@nginx.com        (resp, sock) = self.post(
3471017Szelenkov@nginx.com            headers={
3481017Szelenkov@nginx.com                'Host': 'localhost',
3491017Szelenkov@nginx.com                'Connection': 'keep-alive',
3501017Szelenkov@nginx.com                'Content-Type': 'text/html',
3511017Szelenkov@nginx.com            },
3521017Szelenkov@nginx.com            start=True,
3531453Szelenkov@nginx.com            body=body,
3541029Szelenkov@nginx.com            read_timeout=1,
3551017Szelenkov@nginx.com        )
356585Szelenkov@nginx.com
3571596Szelenkov@nginx.com        assert resp['body'] == body, 'keep-alive 1'
358585Szelenkov@nginx.com
3591453Szelenkov@nginx.com        body = '0123456789'
3601017Szelenkov@nginx.com        resp = self.post(
3611017Szelenkov@nginx.com            headers={
3621017Szelenkov@nginx.com                'Host': 'localhost',
3631017Szelenkov@nginx.com                'Connection': 'close',
3641017Szelenkov@nginx.com                'Content-Type': 'text/html',
3651017Szelenkov@nginx.com            },
3661017Szelenkov@nginx.com            sock=sock,
3671453Szelenkov@nginx.com            body=body,
3681017Szelenkov@nginx.com        )
369585Szelenkov@nginx.com
3701596Szelenkov@nginx.com        assert resp['body'] == body, 'keep-alive 2'
371585Szelenkov@nginx.com
3721259Szelenkov@nginx.com    def test_ruby_application_constants(self):
3731259Szelenkov@nginx.com        self.load('constants')
3741259Szelenkov@nginx.com
3751259Szelenkov@nginx.com        resp = self.get()
3761259Szelenkov@nginx.com
3771596Szelenkov@nginx.com        assert resp['status'] == 200, 'status'
3781259Szelenkov@nginx.com
3791259Szelenkov@nginx.com        headers = resp['headers']
3801596Szelenkov@nginx.com        assert len(headers['X-Copyright']) > 0, 'RUBY_COPYRIGHT'
3811596Szelenkov@nginx.com        assert len(headers['X-Description']) > 0, 'RUBY_DESCRIPTION'
3821596Szelenkov@nginx.com        assert len(headers['X-Engine']) > 0, 'RUBY_ENGINE'
3831596Szelenkov@nginx.com        assert len(headers['X-Engine-Version']) > 0, 'RUBY_ENGINE_VERSION'
3841596Szelenkov@nginx.com        assert len(headers['X-Patchlevel']) > 0, 'RUBY_PATCHLEVEL'
3851596Szelenkov@nginx.com        assert len(headers['X-Platform']) > 0, 'RUBY_PLATFORM'
3861596Szelenkov@nginx.com        assert len(headers['X-Release-Date']) > 0, 'RUBY_RELEASE_DATE'
3871596Szelenkov@nginx.com        assert len(headers['X-Revision']) > 0, 'RUBY_REVISION'
3881596Szelenkov@nginx.com        assert len(headers['X-Version']) > 0, 'RUBY_VERSION'
3891688Smax.romanov@nginx.com
3901688Smax.romanov@nginx.com    def test_ruby_application_threads(self):
3911688Smax.romanov@nginx.com        self.load('threads')
3921688Smax.romanov@nginx.com
3931688Smax.romanov@nginx.com        assert 'success' in self.conf(
3941688Smax.romanov@nginx.com            '4', 'applications/threads/threads'
3951688Smax.romanov@nginx.com        ), 'configure 4 threads'
3961688Smax.romanov@nginx.com
3971688Smax.romanov@nginx.com        socks = []
3981688Smax.romanov@nginx.com
3991688Smax.romanov@nginx.com        for i in range(4):
4001688Smax.romanov@nginx.com            (_, sock) = self.get(
4011688Smax.romanov@nginx.com                headers={
4021688Smax.romanov@nginx.com                    'Host': 'localhost',
4031688Smax.romanov@nginx.com                    'X-Delay': '2',
4041688Smax.romanov@nginx.com                    'Connection': 'close',
4051688Smax.romanov@nginx.com                },
4061688Smax.romanov@nginx.com                no_recv=True,
4071688Smax.romanov@nginx.com                start=True,
4081688Smax.romanov@nginx.com            )
4091688Smax.romanov@nginx.com
4101688Smax.romanov@nginx.com            socks.append(sock)
4111688Smax.romanov@nginx.com
4121688Smax.romanov@nginx.com        threads = set()
4131688Smax.romanov@nginx.com
4141688Smax.romanov@nginx.com        for sock in socks:
4151688Smax.romanov@nginx.com            resp = self.recvall(sock).decode('utf-8')
4161688Smax.romanov@nginx.com
4171688Smax.romanov@nginx.com            self.log_in(resp)
4181688Smax.romanov@nginx.com
4191688Smax.romanov@nginx.com            resp = self._resp_to_dict(resp)
4201688Smax.romanov@nginx.com
4211688Smax.romanov@nginx.com            assert resp['status'] == 200, 'status'
4221688Smax.romanov@nginx.com
4231688Smax.romanov@nginx.com            threads.add(resp['headers']['X-Thread'])
4241688Smax.romanov@nginx.com
4251688Smax.romanov@nginx.com            assert resp['headers']['Rack-Multithread'] == 'true', 'multithread'
4261688Smax.romanov@nginx.com
4271688Smax.romanov@nginx.com            sock.close()
4281688Smax.romanov@nginx.com
4291688Smax.romanov@nginx.com        assert len(socks) == len(threads), 'threads differs'
430