From 54837759f36eddb80af22c8d73e103a948221dc7 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Mon, 19 Oct 2020 22:25:29 +0100 Subject: Tests: fixed unit.log print. --- test/test_asgi_application.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/test_asgi_application.py') diff --git a/test/test_asgi_application.py b/test/test_asgi_application.py index 948d9823..1a654ebf 100644 --- a/test/test_asgi_application.py +++ b/test/test_asgi_application.py @@ -4,6 +4,7 @@ from distutils.version import LooseVersion import pytest +from conftest import option from conftest import skip_alert from unit.applications.lang.python import TestApplicationPython @@ -14,7 +15,7 @@ class TestASGIApplication(TestApplicationPython): load_module = 'asgi' def findall(self, pattern): - with open(self.temp_dir + '/unit.log', 'r', errors='ignore') as f: + with open(option.temp_dir + '/unit.log', 'r', errors='ignore') as f: return re.findall(pattern, f.read()) def test_asgi_application_variables(self): -- cgit From f27953af6103db390aa3eee012a254f130fdf5f4 Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Thu, 5 Nov 2020 00:05:02 +0300 Subject: Tests: added Python threading tests. --- test/test_asgi_application.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'test/test_asgi_application.py') diff --git a/test/test_asgi_application.py b/test/test_asgi_application.py index 1a654ebf..179a69ee 100644 --- a/test/test_asgi_application.py +++ b/test/test_asgi_application.py @@ -401,3 +401,44 @@ Connection: close assert ( self.wait_for_record(r'\(5\) Thread: 100') is not None ), 'last thread finished' + + def test_asgi_application_threads(self): + self.load('threads') + + assert 'success' in self.conf( + '4', 'applications/threads/threads' + ), 'configure 4 threads' + + socks = [] + + for i in range(4): + (_, sock) = self.get( + headers={ + 'Host': 'localhost', + 'X-Delay': '2', + 'Connection': 'close', + }, + no_recv=True, + start=True, + ) + + socks.append(sock) + + time.sleep(0.25) # required to avoid greedy request reading + + threads = set() + + for sock in socks: + resp = self.recvall(sock).decode('utf-8') + + self.log_in(resp) + + resp = self._resp_to_dict(resp) + + assert resp['status'] == 200, 'status' + + threads.add(resp['headers']['x-thread']) + + sock.close() + + assert len(socks) == len(threads), 'threads differs' -- cgit From 78599f0d3f71953914880138fcfcdd929951fd07 Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Fri, 6 Nov 2020 16:45:03 +0300 Subject: Tests: fixing racing condition in ASGI threads test. ASGI threads read all the requests from the queue before start processing it. This why test need to wait a little to let the ASGI thread start request processing and block. In virtual environment any thread or process may be delayed and only method to avoid racing is a reasonable sleep increase. --- test/test_asgi_application.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test/test_asgi_application.py') diff --git a/test/test_asgi_application.py b/test/test_asgi_application.py index 179a69ee..b382e2f2 100644 --- a/test/test_asgi_application.py +++ b/test/test_asgi_application.py @@ -406,16 +406,16 @@ Connection: close self.load('threads') assert 'success' in self.conf( - '4', 'applications/threads/threads' - ), 'configure 4 threads' + '2', 'applications/threads/threads' + ), 'configure 2 threads' socks = [] - for i in range(4): + for i in range(2): (_, sock) = self.get( headers={ 'Host': 'localhost', - 'X-Delay': '2', + 'X-Delay': '3', 'Connection': 'close', }, no_recv=True, @@ -424,7 +424,7 @@ Connection: close socks.append(sock) - time.sleep(0.25) # required to avoid greedy request reading + time.sleep(1.0) # required to avoid greedy request reading threads = set() -- cgit From a8a9d80f8dcff98a99c74a923a2a37b9e3e177eb Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Tue, 10 Nov 2020 22:27:08 +0300 Subject: Tests: supporting instant app parameters in load(). --- test/test_asgi_application.py | 50 +++++++++++-------------------------------- 1 file changed, 13 insertions(+), 37 deletions(-) (limited to 'test/test_asgi_application.py') diff --git a/test/test_asgi_application.py b/test/test_asgi_application.py index b382e2f2..2e73e529 100644 --- a/test/test_asgi_application.py +++ b/test/test_asgi_application.py @@ -137,23 +137,17 @@ custom-header: BLAH ), '204 header transfer encoding' def test_asgi_application_shm_ack_handle(self): - self.load('mirror') - # Minimum possible limit shm_limit = 10 * 1024 * 1024 - assert ( - 'success' in self.conf('{"shm": ' + str(shm_limit) + '}', - 'applications/mirror/limits') - ) + self.load('mirror', limits={"shm": shm_limit}) # Should exceed shm_limit max_body_size = 12 * 1024 * 1024 - assert ( - 'success' in self.conf('{"http":{"max_body_size": ' - + str(max_body_size) + ' }}', - 'settings') + assert 'success' in self.conf( + '{"http":{"max_body_size": ' + str(max_body_size) + ' }}', + 'settings' ) assert self.get()['status'] == 200, 'init' @@ -204,11 +198,6 @@ custom-header: BLAH assert resp['body'] == body, 'keep-alive 2' def test_asgi_keepalive_reconfigure(self): - skip_alert( - r'pthread_mutex.+failed', - r'failed to apply', - r'process \d+ exited on signal', - ) self.load('mirror') assert self.get()['status'] == 200, 'init' @@ -230,9 +219,8 @@ custom-header: BLAH ) assert resp['body'] == body, 'keep-alive open' - assert 'success' in self.conf( - str(i + 1), 'applications/mirror/processes' - ), 'reconfigure' + + self.load('mirror', processes=i + 1) socks.append(sock) @@ -250,9 +238,8 @@ custom-header: BLAH ) assert resp['body'] == body, 'keep-alive request' - assert 'success' in self.conf( - str(i + 1), 'applications/mirror/processes' - ), 'reconfigure 2' + + self.load('mirror', processes=i + 1) for i in range(conns): resp = self.post( @@ -266,9 +253,8 @@ custom-header: BLAH ) assert resp['body'] == body, 'keep-alive close' - assert 'success' in self.conf( - str(i + 1), 'applications/mirror/processes' - ), 'reconfigure 3' + + self.load('mirror', processes=i + 1) def test_asgi_keepalive_reconfigure_2(self): self.load('mirror') @@ -347,11 +333,7 @@ Connection: close assert resp['status'] == 200, 'reconfigure 3' def test_asgi_process_switch(self): - self.load('delayed') - - assert 'success' in self.conf( - '2', 'applications/delayed/processes' - ), 'configure 2 processes' + self.load('delayed', processes=2) self.get( headers={ @@ -382,9 +364,7 @@ Connection: close def test_asgi_application_loading_error(self): skip_alert(r'Python failed to import module "blah"') - self.load('empty') - - assert 'success' in self.conf('"blah"', 'applications/empty/module') + self.load('empty', module="blah") assert self.get()['status'] == 503, 'loading error' @@ -403,11 +383,7 @@ Connection: close ), 'last thread finished' def test_asgi_application_threads(self): - self.load('threads') - - assert 'success' in self.conf( - '2', 'applications/threads/threads' - ), 'configure 2 threads' + self.load('threads', threads=2) socks = [] -- cgit From 5fd2933d2e54a7b5781698a670abf89b1031db44 Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Tue, 10 Nov 2020 22:27:08 +0300 Subject: Python: supporting ASGI legacy protocol. Introducing manual protocol selection for 'universal' apps and frameworks. --- test/test_asgi_application.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/test_asgi_application.py') diff --git a/test/test_asgi_application.py b/test/test_asgi_application.py index 2e73e529..e90d78bc 100644 --- a/test/test_asgi_application.py +++ b/test/test_asgi_application.py @@ -418,3 +418,29 @@ Connection: close sock.close() assert len(socks) == len(threads), 'threads differs' + + def test_asgi_application_legacy(self): + self.load('legacy') + + resp = self.get( + headers={ + 'Host': 'localhost', + 'Content-Length': '0', + 'Connection': 'close', + }, + ) + + assert resp['status'] == 200, 'status' + + def test_asgi_application_legacy_force(self): + self.load('legacy_force', protocol='asgi') + + resp = self.get( + headers={ + 'Host': 'localhost', + 'Content-Length': '0', + 'Connection': 'close', + }, + ) + + assert resp['status'] == 200, 'status' -- cgit