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/unit/applications/lang/go.py | 10 +- test/unit/applications/lang/java.py | 2 +- test/unit/applications/lang/node.py | 8 +- test/unit/applications/lang/python.py | 1 - test/unit/applications/proto.py | 2 +- test/unit/applications/tls.py | 14 ++- test/unit/control.py | 3 +- test/unit/feature/isolation.py | 20 ++-- test/unit/http.py | 18 ---- test/unit/main.py | 179 ++-------------------------------- 10 files changed, 38 insertions(+), 219 deletions(-) (limited to 'test/unit') diff --git a/test/unit/applications/lang/go.py b/test/unit/applications/lang/go.py index 7715bd6c..518cd017 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,7 +30,7 @@ class TestApplicationGo(TestApplicationProto): 'go', 'build', '-o', - self.temp_dir + '/go/' + name, + option.temp_dir + '/go/' + name, option.test_dir + '/go/' + script + '/' + name + '.go', ] @@ -47,7 +47,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..a034d9a4 100644 --- a/test/unit/applications/lang/java.py +++ b/test/unit/applications/lang/java.py @@ -10,7 +10,7 @@ from unit.applications.proto import TestApplicationProto class TestApplicationJava(TestApplicationProto): def load(self, script, name='app', **kwargs): - app_path = self.temp_dir + '/java' + 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 + '/' diff --git a/test/unit/applications/lang/node.py b/test/unit/applications/lang/node.py index 877fc461..4aa9eb1c 100644 --- a/test/unit/applications/lang/node.py +++ b/test/unit/applications/lang/node.py @@ -11,17 +11,17 @@ class TestApplicationNode(TestApplicationProto): # 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') self._load_conf( { @@ -32,7 +32,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/python.py b/test/unit/applications/lang/python.py index 47b95dac..a4a27bb9 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 diff --git a/test/unit/applications/proto.py b/test/unit/applications/proto.py index 2f748c21..9a0361d5 100644 --- a/test/unit/applications/proto.py +++ b/test/unit/applications/proto.py @@ -14,7 +14,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'): 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 diff --git a/test/unit/control.py b/test/unit/control.py index 6fd350f4..f05aa827 100644 --- a/test/unit/control.py +++ b/test/unit/control.py @@ -1,5 +1,6 @@ import json +from conftest import option from unit.http import TestHTTP @@ -53,7 +54,7 @@ class TestControl(TestHTTP): args = { 'url': url, 'sock_type': 'unix', - 'addr': self.temp_dir + '/control.unit.sock', + 'addr': option.temp_dir + '/control.unit.sock', } if conf is not None: diff --git a/test/unit/feature/isolation.py b/test/unit/feature/isolation.py index c6f6f3c0..235177ab 100644 --- a/test/unit/feature/isolation.py +++ b/test/unit/feature/isolation.py @@ -21,6 +21,16 @@ class TestFeatureIsolation(TestApplicationProto): if 'go' in available['modules']: module = TestApplicationGo() + elif 'python' in available['modules']: + module = TestApplicationPython() + + elif 'php' in available['modules']: + module = TestApplicationPHP() + app = 'phpinfo' + + elif 'ruby' in available['modules']: + module = TestApplicationRuby() + elif 'java' in available['modules']: module = TestApplicationJava() @@ -32,16 +42,6 @@ class TestFeatureIsolation(TestApplicationProto): module = TestApplicationPerl() app = 'body_empty' - elif 'php' in available['modules']: - module = TestApplicationPHP() - app = 'phpinfo' - - elif 'python' in available['modules']: - module = TestApplicationPython() - - elif 'ruby' in available['modules']: - module = TestApplicationRuby() - if not module: return diff --git a/test/unit/http.py b/test/unit/http.py index 7845f9a8..5f073439 100644 --- a/test/unit/http.py +++ b/test/unit/http.py @@ -5,7 +5,6 @@ import os import re import select import socket -import time import pytest from conftest import option @@ -283,23 +282,6 @@ class TestHTTP(TestUnit): def getjson(self, **kwargs): return self.get(json=True, **kwargs) - def waitforsocket(self, port): - ret = False - - for i in range(50): - try: - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - sock.connect(('127.0.0.1', port)) - ret = True - break - except: - sock.close() - time.sleep(0.1) - - sock.close() - - assert ret, 'socket connected' - def form_encode(self, fields): is_multipart = False diff --git a/test/unit/main.py b/test/unit/main.py index d5940995..488b3f4d 100644 --- a/test/unit/main.py +++ b/test/unit/main.py @@ -1,55 +1,19 @@ -import atexit -import os -import re -import shutil -import signal -import stat -import subprocess -import tempfile -import time -from multiprocessing import Process - import pytest -from conftest import _check_alerts -from conftest import _print_log from conftest import option -from conftest import public_dir -from conftest import waitforfiles class TestUnit(): @classmethod def setup_class(cls, complete_check=True): - cls.available = option.available - unit = TestUnit() - - unit._run() - - # read unit.log - - for i in range(50): - with open(unit.temp_dir + '/unit.log', 'r') as f: - log = f.read() - m = re.search('controller started', log) - - if m is None: - time.sleep(0.1) - else: - break - - if m is None: - _print_log(path=unit.temp_dir + '/unit.log') - exit("Unit is writing log too long") - - def check(available, prerequisites): + def check(): missed = [] # check modules - if 'modules' in prerequisites: - available_modules = list(available['modules'].keys()) + if 'modules' in cls.prerequisites: + available_modules = list(option.available['modules'].keys()) - for module in prerequisites['modules']: + for module in cls.prerequisites['modules']: if module in available_modules: continue @@ -60,10 +24,10 @@ class TestUnit(): # check features - if 'features' in prerequisites: - available_features = list(available['features'].keys()) + if 'features' in cls.prerequisites: + available_features = list(option.available['features'].keys()) - for feature in prerequisites['features']: + for feature in cls.prerequisites['features']: if feature in available_features: continue @@ -72,132 +36,7 @@ class TestUnit(): if missed: pytest.skip(', '.join(missed) + ' feature(s) not supported') - def destroy(): - unit.stop() - _check_alerts(log) - shutil.rmtree(unit.temp_dir) - - def complete(): - destroy() - check(cls.available, cls.prerequisites) - if complete_check: - complete() - else: - unit.complete = complete - return unit - - def setup_method(self): - self._run() - - def _run(self): - build_dir = option.current_dir + '/build' - self.unitd = build_dir + '/unitd' - - if not os.path.isfile(self.unitd): - exit("Could not find unit") - - self.temp_dir = tempfile.mkdtemp(prefix='unit-test-') - - public_dir(self.temp_dir) - - if oct(stat.S_IMODE(os.stat(build_dir).st_mode)) != '0o777': - public_dir(build_dir) - - os.mkdir(self.temp_dir + '/state') - - with open(self.temp_dir + '/unit.log', 'w') as log: - self._p = subprocess.Popen( - [ - self.unitd, - '--no-daemon', - '--modules', build_dir, - '--state', self.temp_dir + '/state', - '--pid', self.temp_dir + '/unit.pid', - '--log', self.temp_dir + '/unit.log', - '--control', 'unix:' + self.temp_dir + '/control.unit.sock', - '--tmp', self.temp_dir, - ], - stderr=log, - ) - - atexit.register(self.stop) - - if not waitforfiles(self.temp_dir + '/control.unit.sock'): - _print_log(path=self.temp_dir + '/unit.log') - exit("Could not start unit") - - self._started = True - - def teardown_method(self): - self.stop() - - # check unit.log for alerts - - unit_log = self.temp_dir + '/unit.log' - - with open(unit_log, 'r', encoding='utf-8', errors='ignore') as f: - _check_alerts(f.read()) - - # remove unit.log - - if not option.save_log: - shutil.rmtree(self.temp_dir) + check() else: - _print_log(path=self.temp_dir) - - assert self.stop_errors == [None, None], 'stop errors' - - def stop(self): - if not self._started: - return - - self.stop_errors = [] - - self.stop_errors.append(self._stop()) - - self.stop_errors.append(self.stop_processes()) - - atexit.unregister(self.stop) - - self._started = False - - def _stop(self): - if self._p.poll() is not None: - return - - with self._p as p: - p.send_signal(signal.SIGQUIT) - - try: - retcode = p.wait(15) - if retcode: - return 'Child process terminated with code ' + str(retcode) - except: - p.kill() - return 'Could not terminate unit' - - def run_process(self, target, *args): - if not hasattr(self, '_processes'): - self._processes = [] - - process = Process(target=target, args=args) - process.start() - - self._processes.append(process) - - def stop_processes(self): - if not hasattr(self, '_processes'): - return - - fail = False - for process in self._processes: - if process.is_alive(): - process.terminate() - process.join(timeout=15) - - if process.is_alive(): - fail = True - - if fail: - return 'Fail to stop process' + return check -- cgit From 8956e668cc3b4088a7bdd3d82ca99ac1445c8814 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Tue, 27 Oct 2020 04:09:52 +0000 Subject: Tests: fixed isolation detection. --- test/unit/applications/lang/java.py | 12 +++- test/unit/applications/lang/node.py | 5 +- test/unit/feature/isolation.py | 122 +++++++++++++++++++++++++++++------- 3 files changed, 112 insertions(+), 27 deletions(-) (limited to 'test/unit') diff --git a/test/unit/applications/lang/java.py b/test/unit/applications/lang/java.py index a034d9a4..0aa1a7af 100644 --- a/test/unit/applications/lang/java.py +++ b/test/unit/applications/lang/java.py @@ -9,7 +9,7 @@ from unit.applications.proto import TestApplicationProto class TestApplicationJava(TestApplicationProto): - def load(self, script, name='app', **kwargs): + def prepare_env(self, script): app_path = option.temp_dir + '/java' web_inf_path = app_path + '/WEB-INF/' classes_path = web_inf_path + 'classes/' @@ -75,6 +75,9 @@ class TestApplicationJava(TestApplicationProto): except: pytest.fail('Cann\'t run javac process.') + def load(self, script, **kwargs): + self.prepare_env(script) + self._load_conf( { "listeners": {"*:7080": {"pass": "applications/" + script}}, @@ -83,8 +86,11 @@ class TestApplicationJava(TestApplicationProto): "unit_jars": option.current_dir + '/build', "type": 'java', "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 4aa9eb1c..98fd9ffc 100644 --- a/test/unit/applications/lang/node.py +++ b/test/unit/applications/lang/node.py @@ -7,7 +7,7 @@ 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( @@ -23,6 +23,9 @@ class TestApplicationNode(TestApplicationProto): public_dir(option.temp_dir + '/node') + def load(self, script, name='app.js', **kwargs): + self.prepare_env(script) + self._load_conf( { "listeners": { diff --git a/test/unit/feature/isolation.py b/test/unit/feature/isolation.py index 235177ab..7877c03a 100644 --- a/test/unit/feature/isolation.py +++ b/test/unit/feature/isolation.py @@ -3,11 +3,8 @@ import os from unit.applications.lang.go import TestApplicationGo from unit.applications.lang.java import TestApplicationJava from unit.applications.lang.node import TestApplicationNode -from unit.applications.lang.perl import TestApplicationPerl -from unit.applications.lang.php import TestApplicationPHP -from unit.applications.lang.python import TestApplicationPython -from unit.applications.lang.ruby import TestApplicationRuby from unit.applications.proto import TestApplicationProto +from conftest import option class TestFeatureIsolation(TestApplicationProto): @@ -16,40 +13,119 @@ class TestFeatureIsolation(TestApplicationProto): def check(self, available, temp_dir): test_conf = {"namespaces": {"credential": True}} - module = '' - app = 'empty' + conf = '' if 'go' in available['modules']: - module = TestApplicationGo() + TestApplicationGo().prepare_env('empty', 'app') + + conf = { + "listeners": {"*:7080": {"pass": "applications/empty"}}, + "applications": { + "empty": { + "type": "external", + "processes": {"spare": 0}, + "working_directory": option.test_dir + "/go/empty", + "executable": option.temp_dir + "/go/app", + "isolation": {"namespaces": {"credential": True}}, + }, + }, + } elif 'python' in available['modules']: - module = TestApplicationPython() + conf = { + "listeners": {"*:7080": {"pass": "applications/empty"}}, + "applications": { + "empty": { + "type": "python", + "processes": {"spare": 0}, + "path": option.test_dir + "/python/empty", + "working_directory": option.test_dir + "/python/empty", + "module": "wsgi", + "isolation": {"namespaces": {"credential": True}}, + } + }, + } elif 'php' in available['modules']: - module = TestApplicationPHP() - app = 'phpinfo' + conf = { + "listeners": {"*:7080": {"pass": "applications/phpinfo"}}, + "applications": { + "phpinfo": { + "type": "php", + "processes": {"spare": 0}, + "root": option.test_dir + "/php/phpinfo", + "working_directory": option.test_dir + "/php/phpinfo", + "index": "index.php", + "isolation": {"namespaces": {"credential": True}}, + } + }, + } elif 'ruby' in available['modules']: - module = TestApplicationRuby() + conf = { + "listeners": {"*:7080": {"pass": "applications/empty"}}, + "applications": { + "empty": { + "type": "ruby", + "processes": {"spare": 0}, + "working_directory": option.test_dir + "/ruby/empty", + "script": option.test_dir + "/ruby/empty/config.ru", + "isolation": {"namespaces": {"credential": True}}, + } + }, + } elif 'java' in available['modules']: - module = TestApplicationJava() + TestApplicationJava().prepare_env('empty') + + conf = { + "listeners": {"*:7080": {"pass": "applications/empty"}}, + "applications": { + "empty": { + "unit_jars": option.current_dir + "/build", + "type": "java", + "processes": {"spare": 0}, + "working_directory": option.test_dir + "/java/empty/", + "webapp": option.temp_dir + "/java", + "isolation": {"namespaces": {"credential": True}}, + } + }, + } elif 'node' in available['modules']: - module = TestApplicationNode() - app = 'basic' + TestApplicationNode().prepare_env('basic') + + conf = { + "listeners": {"*:7080": {"pass": "applications/basic"}}, + "applications": { + "basic": { + "type": "external", + "processes": {"spare": 0}, + "working_directory": option.temp_dir + "/node", + "executable": "app.js", + "isolation": {"namespaces": {"credential": True}}, + } + }, + } elif 'perl' in available['modules']: - module = TestApplicationPerl() - app = 'body_empty' - - if not module: + conf = { + "listeners": {"*:7080": {"pass": "applications/body_empty"}}, + "applications": { + "body_empty": { + "type": "perl", + "processes": {"spare": 0}, + "working_directory": option.test_dir + + "/perl/body_empty", + "script": option.test_dir + "/perl/body_empty/psgi.pl", + "isolation": {"namespaces": {"credential": True}}, + } + }, + } + + else: return - module.temp_dir = temp_dir - module.load(app) - - resp = module.conf(test_conf, 'applications/' + app + '/isolation') - if 'success' not in resp: + if 'success' not in self.conf(conf): return userns = self.getns('user') -- cgit From 6a00bab41e2ebffe5f61f6fb9641162624db41d1 Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Wed, 28 Oct 2020 00:01:46 +0300 Subject: Tests: improving get_application_type() and fixing its name. This patch also enables multiversion tests running for Java. --- test/unit/applications/lang/java.py | 4 +++- test/unit/applications/lang/perl.py | 6 +----- test/unit/applications/lang/php.py | 6 +----- test/unit/applications/lang/python.py | 7 +------ test/unit/applications/lang/ruby.py | 6 +----- test/unit/applications/proto.py | 9 ++++----- 6 files changed, 11 insertions(+), 27 deletions(-) (limited to 'test/unit') diff --git a/test/unit/applications/lang/java.py b/test/unit/applications/lang/java.py index 0aa1a7af..fe0dde7a 100644 --- a/test/unit/applications/lang/java.py +++ b/test/unit/applications/lang/java.py @@ -9,6 +9,8 @@ from unit.applications.proto import TestApplicationProto class TestApplicationJava(TestApplicationProto): + application_type = "java" + def prepare_env(self, script): app_path = option.temp_dir + '/java' web_inf_path = app_path + '/WEB-INF/' @@ -84,7 +86,7 @@ class TestApplicationJava(TestApplicationProto): "applications": { script: { "unit_jars": option.current_dir + '/build', - "type": 'java', + "type": self.get_application_type(), "processes": {"spare": 0}, "working_directory": option.test_dir + '/java/' 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..619dfc93 100644 --- a/test/unit/applications/lang/php.py +++ b/test/unit/applications/lang/php.py @@ -7,17 +7,13 @@ 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 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 a4a27bb9..374b0f9c 100644 --- a/test/unit/applications/lang/python.py +++ b/test/unit/applications/lang/python.py @@ -34,11 +34,6 @@ class TestApplicationPython(TestApplicationProto): script_path = '/app/python/' + name - appication_type = self.get_appication_type() - - if appication_type is None: - appication_type = self.application_type - self._load_conf( { "listeners": { @@ -46,7 +41,7 @@ class TestApplicationPython(TestApplicationProto): }, "applications": { name: { - "type": appication_type, + "type": self.get_application_type(), "processes": {"spare": 0}, "path": script_path, "working_directory": script_path, 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 9a0361d5..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()) @@ -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: -- cgit From 0390cb3a61051dd93e206d50591aff5759cf42fc Mon Sep 17 00:00:00 2001 From: Tiago Natel de Moura Date: Thu, 29 Oct 2020 20:30:53 +0000 Subject: Isolation: mounting of procfs by default when using "rootfs". --- test/unit/applications/lang/php.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/unit') diff --git a/test/unit/applications/lang/php.py b/test/unit/applications/lang/php.py index 619dfc93..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 @@ -8,6 +11,17 @@ class TestApplicationPHP(TestApplicationProto): def load(self, script, index='index.php', **kwargs): script_path = option.test_dir + '/php/' + script + 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}}, -- cgit From 4ba9e1d0058bc1710a0078af6e9a1f7e4bee986a Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Mon, 2 Nov 2020 21:05:04 +0300 Subject: Java: upgrading 3rd-party components. --- test/unit/applications/lang/java.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/unit') diff --git a/test/unit/applications/lang/java.py b/test/unit/applications/lang/java.py index fe0dde7a..b57d48bf 100644 --- a/test/unit/applications/lang/java.py +++ b/test/unit/applications/lang/java.py @@ -52,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( -- cgit From 5182d2c398a07f65f2b2334bc04d79130a40808c Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Tue, 3 Nov 2020 01:31:05 +0000 Subject: Tests: force applications to build for JVM 8. This change is made to avoid situations when an application is compiled for a version newer than the Java module used. --- test/unit/applications/lang/java.py | 1 + 1 file changed, 1 insertion(+) (limited to 'test/unit') diff --git a/test/unit/applications/lang/java.py b/test/unit/applications/lang/java.py index b57d48bf..e1bd5e0c 100644 --- a/test/unit/applications/lang/java.py +++ b/test/unit/applications/lang/java.py @@ -64,6 +64,7 @@ class TestApplicationJava(TestApplicationProto): javac = [ 'javac', + '-target', '8', '-source', '8', '-nowarn', '-encoding', 'utf-8', '-d', classes_path, '-classpath', classpath + ':' + ws_jars[0], -- 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/unit/applications/lang/python.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'test/unit') diff --git a/test/unit/applications/lang/python.py b/test/unit/applications/lang/python.py index 374b0f9c..20d4f257 100644 --- a/test/unit/applications/lang/python.py +++ b/test/unit/applications/lang/python.py @@ -34,20 +34,24 @@ class TestApplicationPython(TestApplicationProto): script_path = '/app/python/' + name + app = { + "type": self.get_application_type(), + "processes": kwargs.pop('processes', {"spare": 0}), + "path": script_path, + "working_directory": script_path, + "module": module, + } + + for attr in ('callable', 'home', 'limits', 'path', 'threads'): + if attr in kwargs: + app[attr] = kwargs.pop(attr) + self._load_conf( { "listeners": { "*:7080": {"pass": "applications/" + quote(name, '')} }, - "applications": { - name: { - "type": self.get_application_type(), - "processes": {"spare": 0}, - "path": script_path, - "working_directory": script_path, - "module": module, - } - }, + "applications": {name: app}, }, **kwargs ) -- 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/unit/applications/lang/python.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/unit') diff --git a/test/unit/applications/lang/python.py b/test/unit/applications/lang/python.py index 20d4f257..792a86fa 100644 --- a/test/unit/applications/lang/python.py +++ b/test/unit/applications/lang/python.py @@ -42,7 +42,8 @@ class TestApplicationPython(TestApplicationProto): "module": module, } - for attr in ('callable', 'home', 'limits', 'path', 'threads'): + for attr in ('callable', 'home', 'limits', 'path', 'protocol', + 'threads'): if attr in kwargs: app[attr] = kwargs.pop(attr) -- cgit From 567f0a7b3049f4532524ac35cb232cbeedb868bf Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Mon, 16 Nov 2020 20:37:01 +0300 Subject: Tests: fixing tests interrupt in terminal. KeyboardInterrupt re-raised. --- test/unit/applications/lang/go.py | 6 ++++++ test/unit/applications/lang/java.py | 8 +++++++- test/unit/check/go.py | 3 +++ test/unit/http.py | 10 ++++++++-- 4 files changed, 24 insertions(+), 3 deletions(-) (limited to 'test/unit') diff --git a/test/unit/applications/lang/go.py b/test/unit/applications/lang/go.py index 518cd017..866dec47 100644 --- a/test/unit/applications/lang/go.py +++ b/test/unit/applications/lang/go.py @@ -34,10 +34,16 @@ class TestApplicationGo(TestApplicationProto): 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 diff --git a/test/unit/applications/lang/java.py b/test/unit/applications/lang/java.py index e1bd5e0c..0ff85187 100644 --- a/test/unit/applications/lang/java.py +++ b/test/unit/applications/lang/java.py @@ -71,12 +71,18 @@ class TestApplicationJava(TestApplicationProto): ] 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) diff --git a/test/unit/check/go.py b/test/unit/check/go.py index dd2150eb..35b0c2d5 100644 --- a/test/unit/check/go.py +++ b/test/unit/check/go.py @@ -25,5 +25,8 @@ def check_go(current_dir, temp_dir, test_dir): if process.returncode == 0: return True + except KeyboardInterrupt: + raise + except: return None diff --git a/test/unit/http.py b/test/unit/http.py index 5f073439..8d964978 100644 --- a/test/unit/http.py +++ b/test/unit/http.py @@ -187,6 +187,10 @@ class TestHTTP(TestUnit): try: part = sock.recv(buff_size) + + except KeyboardInterrupt: + raise + except: break @@ -242,7 +246,8 @@ class TestHTTP(TestUnit): try: last_size = int(chunks[-2], 16) - except: + + except ValueError: pytest.fail('Invalid zero size chunk') if last_size != 0 or chunks[-1] != b'': @@ -252,7 +257,8 @@ class TestHTTP(TestUnit): while len(chunks) >= 2: try: size = int(chunks.pop(0), 16) - except: + + except ValueError: pytest.fail('Invalid chunk size %s' % str(size)) if size == 0: -- cgit