summaryrefslogtreecommitdiffhomepage
path: root/test/test_python_application.py
diff options
context:
space:
mode:
authorAndrei Belov <defan@nginx.com>2020-11-19 21:19:57 +0300
committerAndrei Belov <defan@nginx.com>2020-11-19 21:19:57 +0300
commit7f9079a3cd4cdb6ac3fea53f10bd34fe8b82fe9c (patch)
treec79dc48a3260156f3f824ecd299e5a4934d749c5 /test/test_python_application.py
parent646d047e5d12515ceac02279b373601ce0752982 (diff)
parent806a9b2515c60b12a68cd97af04f7fa5cb4dffed (diff)
downloadunit-7f9079a3cd4cdb6ac3fea53f10bd34fe8b82fe9c.tar.gz
unit-7f9079a3cd4cdb6ac3fea53f10bd34fe8b82fe9c.tar.bz2
Merged with the default branch.1.21.0-1
Diffstat (limited to 'test/test_python_application.py')
-rw-r--r--test/test_python_application.py97
1 files changed, 54 insertions, 43 deletions
diff --git a/test/test_python_application.py b/test/test_python_application.py
index 3e27a24c..83b0c8f4 100644
--- a/test/test_python_application.py
+++ b/test/test_python_application.py
@@ -5,7 +5,9 @@ import time
import pytest
+from conftest import option
from conftest import skip_alert
+from conftest import unit_stop
from unit.applications.lang.python import TestApplicationPython
@@ -13,7 +15,7 @@ class TestPythonApplication(TestApplicationPython):
prerequisites = {'modules': {'python': 'all'}}
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_python_application_variables(self):
@@ -156,7 +158,7 @@ custom-header: BLAH
self.conf({"listeners": {}, "applications": {}})
- self.stop()
+ unit_stop()
assert (
self.wait_for_record(r'RuntimeError') is not None
@@ -195,11 +197,6 @@ custom-header: BLAH
assert resp['body'] == body, 'keep-alive 2'
def test_python_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'
@@ -221,9 +218,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)
@@ -241,9 +237,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(
@@ -257,9 +252,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_python_keepalive_reconfigure_2(self):
self.load('mirror')
@@ -344,16 +338,12 @@ Connection: close
self.conf({"listeners": {}, "applications": {}})
- self.stop()
+ unit_stop()
assert self.wait_for_record(r'At exit called\.') is not None, 'atexit'
def test_python_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={
@@ -507,7 +497,7 @@ last line: 987654321
self.get()
- self.stop()
+ unit_stop()
assert (
self.wait_for_record(r'\[error\].+Error in application\.')
@@ -539,9 +529,7 @@ last line: 987654321
def test_python_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'
@@ -550,7 +538,7 @@ last line: 987654321
self.get()
- self.stop()
+ unit_stop()
assert self.wait_for_record(r'Close called\.') is not None, 'close'
@@ -559,7 +547,7 @@ last line: 987654321
self.get()
- self.stop()
+ unit_stop()
assert (
self.wait_for_record(r'Close called\.') is not None
@@ -570,7 +558,7 @@ last line: 987654321
self.get()
- self.stop()
+ unit_stop()
assert (
self.wait_for_record(
@@ -742,7 +730,7 @@ last line: 987654321
try:
group_id = grp.getgrnam(group).gr_gid
- except:
+ except KeyError:
group = 'nogroup'
group_id = grp.getgrnam(group).gr_gid
@@ -787,7 +775,7 @@ last line: 987654321
try:
grp.getgrnam(group)
group = True
- except:
+ except KeyError:
group = False
if group:
@@ -809,24 +797,47 @@ last line: 987654321
assert self.get()['status'] == 204, 'default application response'
- assert 'success' in self.conf(
- '"app"', 'applications/callable/callable'
- )
+ self.load('callable', callable="app")
assert self.get()['status'] == 200, 'callable response'
- assert 'success' in self.conf(
- '"blah"', 'applications/callable/callable'
- )
+ self.load('callable', callable="blah")
assert self.get()['status'] not in [200, 204], 'callable response inv'
- assert 'success' in self.conf(
- '"app"', 'applications/callable/callable'
- )
+ def test_python_application_threads(self):
+ self.load('threads', threads=4)
+
+ 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)
+
+ 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'])
- assert self.get()['status'] == 200, 'callable response 2'
+ assert resp['headers']['Wsgi-Multithread'] == 'True', 'multithread'
- assert 'success' in self.conf_delete('applications/callable/callable')
+ sock.close()
- assert self.get()['status'] == 204, 'default response 2'
+ assert len(socks) == len(threads), 'threads differs'