summaryrefslogtreecommitdiffhomepage
path: root/test/test_asgi_application.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_asgi_application.py')
-rw-r--r--test/test_asgi_application.py110
1 files changed, 77 insertions, 33 deletions
diff --git a/test/test_asgi_application.py b/test/test_asgi_application.py
index 948d9823..e90d78bc 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):
@@ -136,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'
@@ -203,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'
@@ -229,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)
@@ -249,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(
@@ -265,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')
@@ -346,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={
@@ -381,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'
@@ -400,3 +381,66 @@ 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', threads=2)
+
+ socks = []
+
+ for i in range(2):
+ (_, sock) = self.get(
+ headers={
+ 'Host': 'localhost',
+ 'X-Delay': '3',
+ 'Connection': 'close',
+ },
+ no_recv=True,
+ start=True,
+ )
+
+ socks.append(sock)
+
+ time.sleep(1.0) # 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'
+
+ 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'