summaryrefslogtreecommitdiffhomepage
path: root/test/unit/applications
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/unit/applications
parent646d047e5d12515ceac02279b373601ce0752982 (diff)
parent806a9b2515c60b12a68cd97af04f7fa5cb4dffed (diff)
downloadunit-7f9079a3cd4cdb6ac3fea53f10bd34fe8b82fe9c.tar.gz
unit-7f9079a3cd4cdb6ac3fea53f10bd34fe8b82fe9c.tar.bz2
Merged with the default branch.1.21.0-1
Diffstat (limited to '')
-rw-r--r--test/unit/applications/lang/go.py16
-rw-r--r--test/unit/applications/lang/java.py29
-rw-r--r--test/unit/applications/lang/node.py13
-rw-r--r--test/unit/applications/lang/perl.py6
-rw-r--r--test/unit/applications/lang/php.py18
-rw-r--r--test/unit/applications/lang/python.py25
-rw-r--r--test/unit/applications/lang/ruby.py6
-rw-r--r--test/unit/applications/proto.py11
-rw-r--r--test/unit/applications/tls.py14
9 files changed, 80 insertions, 58 deletions
diff --git a/test/unit/applications/lang/go.py b/test/unit/applications/lang/go.py
index 7715bd6c..866dec47 100644
--- a/test/unit/applications/lang/go.py
+++ b/test/unit/applications/lang/go.py
@@ -7,8 +7,8 @@ from unit.applications.proto import TestApplicationProto
class TestApplicationGo(TestApplicationProto):
def prepare_env(self, script, name, static=False):
- if not os.path.exists(self.temp_dir + '/go'):
- os.mkdir(self.temp_dir + '/go')
+ if not os.path.exists(option.temp_dir + '/go'):
+ os.mkdir(option.temp_dir + '/go')
env = os.environ.copy()
env['GOPATH'] = option.current_dir + '/build/go'
@@ -22,7 +22,7 @@ class TestApplicationGo(TestApplicationProto):
'-ldflags',
'-extldflags "-static"',
'-o',
- self.temp_dir + '/go/' + name,
+ option.temp_dir + '/go/' + name,
option.test_dir + '/go/' + script + '/' + name + '.go',
]
else:
@@ -30,14 +30,20 @@ class TestApplicationGo(TestApplicationProto):
'go',
'build',
'-o',
- self.temp_dir + '/go/' + name,
+ option.temp_dir + '/go/' + name,
option.test_dir + '/go/' + script + '/' + name + '.go',
]
+ if option.detailed:
+ print("\n$ GOPATH=" + env['GOPATH'] + " " + " ".join(args))
+
try:
process = subprocess.Popen(args, env=env)
process.communicate()
+ except KeyboardInterrupt:
+ raise
+
except:
return None
@@ -47,7 +53,7 @@ class TestApplicationGo(TestApplicationProto):
static_build = False
wdir = option.test_dir + "/go/" + script
- executable = self.temp_dir + "/go/" + name
+ executable = option.temp_dir + "/go/" + name
if 'isolation' in kwargs and 'rootfs' in kwargs['isolation']:
wdir = "/go/"
diff --git a/test/unit/applications/lang/java.py b/test/unit/applications/lang/java.py
index 01cbfa0b..0ff85187 100644
--- a/test/unit/applications/lang/java.py
+++ b/test/unit/applications/lang/java.py
@@ -9,8 +9,10 @@ from unit.applications.proto import TestApplicationProto
class TestApplicationJava(TestApplicationProto):
- def load(self, script, name='app', **kwargs):
- app_path = self.temp_dir + '/java'
+ application_type = "java"
+
+ def prepare_env(self, script):
+ app_path = option.temp_dir + '/java'
web_inf_path = app_path + '/WEB-INF/'
classes_path = web_inf_path + 'classes/'
script_path = option.test_dir + '/java/' + script + '/'
@@ -50,7 +52,7 @@ class TestApplicationJava(TestApplicationProto):
os.makedirs(classes_path)
classpath = (
- option.current_dir + '/build/tomcat-servlet-api-9.0.13.jar'
+ option.current_dir + '/build/tomcat-servlet-api-9.0.39.jar'
)
ws_jars = glob.glob(
@@ -62,18 +64,28 @@ class TestApplicationJava(TestApplicationProto):
javac = [
'javac',
+ '-target', '8', '-source', '8', '-nowarn',
'-encoding', 'utf-8',
'-d', classes_path,
'-classpath', classpath + ':' + ws_jars[0],
]
javac.extend(src)
+ if option.detailed:
+ print("\n$ " + " ".join(javac))
+
try:
process = subprocess.Popen(javac, stderr=subprocess.STDOUT)
process.communicate()
+ except KeyboardInterrupt:
+ raise
+
except:
- pytest.fail('Cann\'t run javac process.')
+ pytest.fail('Can\'t run javac process.')
+
+ def load(self, script, **kwargs):
+ self.prepare_env(script)
self._load_conf(
{
@@ -81,10 +93,13 @@ class TestApplicationJava(TestApplicationProto):
"applications": {
script: {
"unit_jars": option.current_dir + '/build',
- "type": 'java',
+ "type": self.get_application_type(),
"processes": {"spare": 0},
- "working_directory": script_path,
- "webapp": app_path,
+ "working_directory": option.test_dir
+ + '/java/'
+ + script
+ + '/',
+ "webapp": option.temp_dir + '/java',
}
},
},
diff --git a/test/unit/applications/lang/node.py b/test/unit/applications/lang/node.py
index 877fc461..98fd9ffc 100644
--- a/test/unit/applications/lang/node.py
+++ b/test/unit/applications/lang/node.py
@@ -7,21 +7,24 @@ from unit.applications.proto import TestApplicationProto
class TestApplicationNode(TestApplicationProto):
- def load(self, script, name='app.js', **kwargs):
+ def prepare_env(self, script):
# copy application
shutil.copytree(
- option.test_dir + '/node/' + script, self.temp_dir + '/node'
+ option.test_dir + '/node/' + script, option.temp_dir + '/node'
)
# copy modules
shutil.copytree(
option.current_dir + '/node/node_modules',
- self.temp_dir + '/node/node_modules',
+ option.temp_dir + '/node/node_modules',
)
- public_dir(self.temp_dir + '/node')
+ public_dir(option.temp_dir + '/node')
+
+ def load(self, script, name='app.js', **kwargs):
+ self.prepare_env(script)
self._load_conf(
{
@@ -32,7 +35,7 @@ class TestApplicationNode(TestApplicationProto):
script: {
"type": "external",
"processes": {"spare": 0},
- "working_directory": self.temp_dir + '/node',
+ "working_directory": option.temp_dir + '/node',
"executable": name,
}
},
diff --git a/test/unit/applications/lang/perl.py b/test/unit/applications/lang/perl.py
index a27c7649..9dc24ace 100644
--- a/test/unit/applications/lang/perl.py
+++ b/test/unit/applications/lang/perl.py
@@ -7,17 +7,13 @@ class TestApplicationPerl(TestApplicationProto):
def load(self, script, name='psgi.pl', **kwargs):
script_path = option.test_dir + '/perl/' + script
- appication_type = self.get_appication_type()
-
- if appication_type is None:
- appication_type = self.application_type
self._load_conf(
{
"listeners": {"*:7080": {"pass": "applications/" + script}},
"applications": {
script: {
- "type": appication_type,
+ "type": self.get_application_type(),
"processes": {"spare": 0},
"working_directory": script_path,
"script": script_path + '/' + name,
diff --git a/test/unit/applications/lang/php.py b/test/unit/applications/lang/php.py
index 2d50df2e..3dbb32f5 100644
--- a/test/unit/applications/lang/php.py
+++ b/test/unit/applications/lang/php.py
@@ -1,4 +1,7 @@
from conftest import option
+import os
+import shutil
+
from unit.applications.proto import TestApplicationProto
@@ -7,17 +10,24 @@ class TestApplicationPHP(TestApplicationProto):
def load(self, script, index='index.php', **kwargs):
script_path = option.test_dir + '/php/' + script
- appication_type = self.get_appication_type()
- if appication_type is None:
- appication_type = self.application_type
+ if kwargs.get('isolation') and kwargs['isolation'].get('rootfs'):
+ rootfs = kwargs['isolation']['rootfs']
+
+ if not os.path.exists(rootfs + '/app/php/'):
+ os.makedirs(rootfs + '/app/php/')
+
+ if not os.path.exists(rootfs + '/app/php/' + script):
+ shutil.copytree(script_path, rootfs + '/app/php/' + script)
+
+ script_path = '/app/php/' + script
self._load_conf(
{
"listeners": {"*:7080": {"pass": "applications/" + script}},
"applications": {
script: {
- "type": appication_type,
+ "type": self.get_application_type(),
"processes": {"spare": 0},
"root": script_path,
"working_directory": script_path,
diff --git a/test/unit/applications/lang/python.py b/test/unit/applications/lang/python.py
index 47b95dac..792a86fa 100644
--- a/test/unit/applications/lang/python.py
+++ b/test/unit/applications/lang/python.py
@@ -12,7 +12,6 @@ class TestApplicationPython(TestApplicationProto):
load_module = "wsgi"
def load(self, script, name=None, module=None, **kwargs):
- print()
if name is None:
name = script
@@ -35,25 +34,25 @@ class TestApplicationPython(TestApplicationProto):
script_path = '/app/python/' + name
- appication_type = self.get_appication_type()
+ app = {
+ "type": self.get_application_type(),
+ "processes": kwargs.pop('processes', {"spare": 0}),
+ "path": script_path,
+ "working_directory": script_path,
+ "module": module,
+ }
- if appication_type is None:
- appication_type = self.application_type
+ for attr in ('callable', 'home', 'limits', 'path', 'protocol',
+ 'threads'):
+ if attr in kwargs:
+ app[attr] = kwargs.pop(attr)
self._load_conf(
{
"listeners": {
"*:7080": {"pass": "applications/" + quote(name, '')}
},
- "applications": {
- name: {
- "type": appication_type,
- "processes": {"spare": 0},
- "path": script_path,
- "working_directory": script_path,
- "module": module,
- }
- },
+ "applications": {name: app},
},
**kwargs
)
diff --git a/test/unit/applications/lang/ruby.py b/test/unit/applications/lang/ruby.py
index bc3cefc6..82d66e65 100644
--- a/test/unit/applications/lang/ruby.py
+++ b/test/unit/applications/lang/ruby.py
@@ -7,17 +7,13 @@ class TestApplicationRuby(TestApplicationProto):
def load(self, script, name='config.ru', **kwargs):
script_path = option.test_dir + '/ruby/' + script
- appication_type = self.get_appication_type()
-
- if appication_type is None:
- appication_type = self.application_type
self._load_conf(
{
"listeners": {"*:7080": {"pass": "applications/" + script}},
"applications": {
script: {
- "type": appication_type,
+ "type": self.get_application_type(),
"processes": {"spare": 0},
"working_directory": script_path,
"script": script_path + '/' + name,
diff --git a/test/unit/applications/proto.py b/test/unit/applications/proto.py
index 2f748c21..6e760c70 100644
--- a/test/unit/applications/proto.py
+++ b/test/unit/applications/proto.py
@@ -7,6 +7,8 @@ from unit.control import TestControl
class TestApplicationProto(TestControl):
+ application_type = None
+
def sec_epoch(self):
return time.mktime(time.gmtime())
@@ -14,7 +16,7 @@ class TestApplicationProto(TestControl):
return time.mktime(time.strptime(date, template))
def search_in_log(self, pattern, name='unit.log'):
- with open(self.temp_dir + '/' + name, 'r', errors='ignore') as f:
+ with open(option.temp_dir + '/' + name, 'r', errors='ignore') as f:
return re.search(pattern, f.read())
def wait_for_record(self, pattern, name='unit.log'):
@@ -28,15 +30,12 @@ class TestApplicationProto(TestControl):
return found
- def get_appication_type(self):
+ def get_application_type(self):
current_test = (
os.environ.get('PYTEST_CURRENT_TEST').split(':')[-1].split(' ')[0]
)
- if current_test in option.generated_tests:
- return option.generated_tests[current_test]
-
- return None
+ return option.generated_tests.get(current_test, self.application_type)
def _load_conf(self, conf, **kwargs):
if 'applications' in conf:
diff --git a/test/unit/applications/tls.py b/test/unit/applications/tls.py
index fdf681ae..fb1b112c 100644
--- a/test/unit/applications/tls.py
+++ b/test/unit/applications/tls.py
@@ -8,8 +8,6 @@ from unit.applications.proto import TestApplicationProto
class TestApplicationTLS(TestApplicationProto):
def setup_method(self):
- super().setup_method()
-
self.context = ssl.create_default_context()
self.context.check_hostname = False
self.context.verify_mode = ssl.CERT_NONE
@@ -24,9 +22,9 @@ class TestApplicationTLS(TestApplicationProto):
'-x509',
'-new',
'-subj', '/CN=' + name + '/',
- '-config', self.temp_dir + '/openssl.conf',
- '-out', self.temp_dir + '/' + name + '.crt',
- '-keyout', self.temp_dir + '/' + name + '.key',
+ '-config', option.temp_dir + '/openssl.conf',
+ '-out', option.temp_dir + '/' + name + '.crt',
+ '-keyout', option.temp_dir + '/' + name + '.key',
],
stderr=subprocess.STDOUT,
)
@@ -38,8 +36,8 @@ class TestApplicationTLS(TestApplicationProto):
if key is None:
key = crt
- key_path = self.temp_dir + '/' + key + '.key'
- crt_path = self.temp_dir + '/' + crt + '.crt'
+ key_path = option.temp_dir + '/' + key + '.key'
+ crt_path = option.temp_dir + '/' + crt + '.crt'
with open(key_path, 'rb') as k, open(crt_path, 'rb') as c:
return self.conf(k.read() + c.read(), '/certificates/' + crt)
@@ -66,7 +64,7 @@ class TestApplicationTLS(TestApplicationProto):
return ssl.get_server_certificate(addr, ssl_version=ssl_version)
def openssl_conf(self):
- conf_path = self.temp_dir + '/openssl.conf'
+ conf_path = option.temp_dir + '/openssl.conf'
if os.path.exists(conf_path):
return