From 6a9a4fe0d46263d4d158803d4a82851e240e0e63 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Fri, 24 Apr 2020 05:08:56 +0100 Subject: Tests: introduced module version specification in prerequisites. --- test/unit/main.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'test/unit') diff --git a/test/unit/main.py b/test/unit/main.py index 4507f71a..074d053e 100644 --- a/test/unit/main.py +++ b/test/unit/main.py @@ -52,9 +52,21 @@ class TestUnit(unittest.TestCase): type = self.application_type for module in self.prerequisites['modules']: if module in self.available['modules']: - for version in self.available['modules'][module]: - self.application_type = type + ' ' + version + prereq_version = self.prerequisites['modules'][module] + available_versions = self.available['modules'][module] + + if prereq_version == 'all': + for version in available_versions: + self.application_type = type + ' ' + version + super().run(result) + elif prereq_version == 'any': + self.application_type = type + ' ' + available_versions[0] super().run(result) + else: + for version in available_versions: + if version.startswith(prereq_version): + self.application_type = type + ' ' + version + super().run(result) @classmethod def main(cls): -- cgit From 0174c971b5ec0d604e4e9becfa41e0bc31179e57 Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Thu, 14 May 2020 13:15:00 +0300 Subject: Configuration: URI encoding in the "pass" option. This is useful to escape "/" in path fragments. For example, in order to reference the application named "foo/bar": { "pass": "applications/foo%2Fbar" } --- test/unit/applications/lang/node.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test/unit') diff --git a/test/unit/applications/lang/node.py b/test/unit/applications/lang/node.py index d818298f..1f5d5027 100644 --- a/test/unit/applications/lang/node.py +++ b/test/unit/applications/lang/node.py @@ -1,5 +1,6 @@ import os import shutil +from urllib.parse import quote from unit.applications.proto import TestApplicationProto @@ -33,7 +34,9 @@ class TestApplicationNode(TestApplicationProto): self._load_conf( { - "listeners": {"*:7080": {"pass": "applications/" + script}}, + "listeners": { + "*:7080": {"pass": "applications/" + quote(script, '')} + }, "applications": { script: { "type": "external", -- cgit From ce4a2bbd05f42d258f9bf7880060a604ac1a866e Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Fri, 15 May 2020 04:20:56 +0100 Subject: Tests: style. --- test/unit/applications/lang/go.py | 1 + test/unit/applications/lang/java.py | 3 ++- test/unit/applications/lang/node.py | 1 + test/unit/applications/proto.py | 1 + test/unit/applications/tls.py | 1 + test/unit/applications/websockets.py | 9 +++++---- test/unit/control.py | 1 + test/unit/feature/isolation.py | 4 ++-- test/unit/http.py | 7 ++++--- test/unit/main.py | 17 ++++++++--------- 10 files changed, 26 insertions(+), 19 deletions(-) (limited to 'test/unit') diff --git a/test/unit/applications/lang/go.py b/test/unit/applications/lang/go.py index e0f83c0a..9070beb6 100644 --- a/test/unit/applications/lang/go.py +++ b/test/unit/applications/lang/go.py @@ -1,5 +1,6 @@ import os import subprocess + from unit.applications.proto import TestApplicationProto diff --git a/test/unit/applications/lang/java.py b/test/unit/applications/lang/java.py index a8a09ce5..c2c6dc51 100644 --- a/test/unit/applications/lang/java.py +++ b/test/unit/applications/lang/java.py @@ -1,7 +1,8 @@ -import os import glob +import os import shutil import subprocess + from unit.applications.proto import TestApplicationProto diff --git a/test/unit/applications/lang/node.py b/test/unit/applications/lang/node.py index 1f5d5027..cf2a99f6 100644 --- a/test/unit/applications/lang/node.py +++ b/test/unit/applications/lang/node.py @@ -1,6 +1,7 @@ import os import shutil from urllib.parse import quote + from unit.applications.proto import TestApplicationProto diff --git a/test/unit/applications/proto.py b/test/unit/applications/proto.py index ae1af354..244cb5be 100644 --- a/test/unit/applications/proto.py +++ b/test/unit/applications/proto.py @@ -1,5 +1,6 @@ import re import time + from unit.control import TestControl diff --git a/test/unit/applications/tls.py b/test/unit/applications/tls.py index 9213974a..e6a846b2 100644 --- a/test/unit/applications/tls.py +++ b/test/unit/applications/tls.py @@ -2,6 +2,7 @@ import os import re import ssl import subprocess + from unit.applications.proto import TestApplicationProto diff --git a/test/unit/applications/websockets.py b/test/unit/applications/websockets.py index fc15e8e4..e0dd2c0d 100644 --- a/test/unit/applications/websockets.py +++ b/test/unit/applications/websockets.py @@ -1,10 +1,11 @@ -import re -import random import base64 -import struct -import select import hashlib import itertools +import random +import re +import select +import struct + from unit.applications.proto import TestApplicationProto GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" diff --git a/test/unit/control.py b/test/unit/control.py index 0b344ed5..029072b5 100644 --- a/test/unit/control.py +++ b/test/unit/control.py @@ -1,4 +1,5 @@ import json + from unit.http import TestHTTP diff --git a/test/unit/feature/isolation.py b/test/unit/feature/isolation.py index 3f474993..4f33d04a 100644 --- a/test/unit/feature/isolation.py +++ b/test/unit/feature/isolation.py @@ -1,6 +1,5 @@ import os -import json -from unit.applications.proto import TestApplicationProto + from unit.applications.lang.go import TestApplicationGo from unit.applications.lang.java import TestApplicationJava from unit.applications.lang.node import TestApplicationNode @@ -8,6 +7,7 @@ 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 class TestFeatureIsolation(TestApplicationProto): diff --git a/test/unit/http.py b/test/unit/http.py index 13384dc8..de3bb2a4 100644 --- a/test/unit/http.py +++ b/test/unit/http.py @@ -1,11 +1,12 @@ import binascii import io +import json import os import re -import time -import json -import socket import select +import socket +import time + from unit.main import TestUnit diff --git a/test/unit/main.py b/test/unit/main.py index 074d053e..42918c9d 100644 --- a/test/unit/main.py +++ b/test/unit/main.py @@ -1,17 +1,17 @@ +import argparse +import atexit +import fcntl import os +import platform import re -import sys -import stat -import time -import fcntl -import atexit import shutil import signal -import argparse -import platform +import stat +import subprocess +import sys import tempfile +import time import unittest -import subprocess from multiprocessing import Process @@ -410,4 +410,3 @@ class TestUnit(unittest.TestCase): data = f.read() print(data) - -- cgit From fa4d4b61200b6f465edbe24ebcdce1a7a8675d39 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Wed, 20 May 2020 23:06:56 +0100 Subject: Tests: print unit.log in case of errors. Thanks to hongzhidao. --- test/unit/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/unit') diff --git a/test/unit/main.py b/test/unit/main.py index 42918c9d..d415f58f 100644 --- a/test/unit/main.py +++ b/test/unit/main.py @@ -102,7 +102,7 @@ class TestUnit(unittest.TestCase): break if m is None: - unit.stop() + unit._print_log() exit("Unit is writing log too long") # discover available modules from unit.log @@ -198,6 +198,7 @@ class TestUnit(unittest.TestCase): atexit.register(self.stop) if not self.waitforfiles(self.testdir + '/control.unit.sock'): + self._print_log() exit("Could not start unit") self.skip_alerts = [ -- cgit From 08b765ae4289f399bb3642d327ccf402efca3537 Mon Sep 17 00:00:00 2001 From: Tiago Natel de Moura Date: Thu, 28 May 2020 14:59:52 +0100 Subject: Tests: Added rootfs tests. --- test/unit/applications/lang/go.py | 75 +++++++++++++++++++++-------------- test/unit/applications/lang/python.py | 19 ++++++++- test/unit/main.py | 3 +- 3 files changed, 66 insertions(+), 31 deletions(-) (limited to 'test/unit') diff --git a/test/unit/applications/lang/go.py b/test/unit/applications/lang/go.py index 9070beb6..83bde4d8 100644 --- a/test/unit/applications/lang/go.py +++ b/test/unit/applications/lang/go.py @@ -19,26 +19,36 @@ class TestApplicationGo(TestApplicationProto): return unit if not complete_check else unit.complete() - def prepare_env(self, script, name): + def prepare_env(self, script, name, static=False): if not os.path.exists(self.testdir + '/go'): os.mkdir(self.testdir + '/go') env = os.environ.copy() env['GOPATH'] = self.pardir + '/build/go' - try: - process = subprocess.Popen( - [ - 'go', - 'build', - '-o', - self.testdir + '/go/' + name, - self.current_dir + '/go/' + script + '/' + name + '.go', - ], - env=env, - stderr=subprocess.STDOUT, - ) + if static: + args = [ + 'go', + 'build', + '-tags', + 'netgo', + '-ldflags', + '-extldflags "-static"', + '-o', + self.testdir + '/go/' + name, + self.current_dir + '/go/' + script + '/' + name + '.go', + ] + else: + args = [ + 'go', + 'build', + '-o', + self.testdir + '/go/' + name, + self.current_dir + '/go/' + script + '/' + name + '.go', + ] + try: + process = subprocess.Popen(args, env=env) process.communicate() except: @@ -47,21 +57,28 @@ class TestApplicationGo(TestApplicationProto): return process def load(self, script, name='app', **kwargs): - self.prepare_env(script, name) - - self._load_conf( - { - "listeners": {"*:7080": {"pass": "applications/" + script}}, - "applications": { - script: { - "type": "external", - "processes": {"spare": 0}, - "working_directory": self.current_dir - + "/go/" - + script, - "executable": self.testdir + "/go/" + name, - } + static_build = False + + wdir = self.current_dir + "/go/" + script + executable = self.testdir + "/go/" + name + + if 'isolation' in kwargs and 'rootfs' in kwargs['isolation']: + wdir = "/go/" + executable = "/go/" + name + static_build = True + + self.prepare_env(script, name, static=static_build) + + conf = { + "listeners": {"*:7080": {"pass": "applications/" + script}}, + "applications": { + script: { + "type": "external", + "processes": {"spare": 0}, + "working_directory": wdir, + "executable": executable, }, }, - **kwargs - ) + } + + self._load_conf(conf, **kwargs) diff --git a/test/unit/applications/lang/python.py b/test/unit/applications/lang/python.py index fdda024a..31a04107 100644 --- a/test/unit/applications/lang/python.py +++ b/test/unit/applications/lang/python.py @@ -1,3 +1,6 @@ +import shutil +import os + from unit.applications.proto import TestApplicationProto @@ -8,7 +11,21 @@ class TestApplicationPython(TestApplicationProto): if name is None: name = script - script_path = self.current_dir + '/python/' + script + if script[0] == '/': + script_path = script + else: + script_path = self.current_dir + '/python/' + script + + if kwargs.get('isolation') and kwargs['isolation'].get('rootfs'): + rootfs = kwargs['isolation']['rootfs'] + + if not os.path.exists(rootfs + '/app/python/'): + os.makedirs(rootfs + '/app/python/') + + if not os.path.exists(rootfs + '/app/python/' + name): + shutil.copytree(script_path, rootfs + '/app/python/' + name) + + script_path = '/app/python/' + name self._load_conf( { diff --git a/test/unit/main.py b/test/unit/main.py index d415f58f..408cf31c 100644 --- a/test/unit/main.py +++ b/test/unit/main.py @@ -58,6 +58,7 @@ class TestUnit(unittest.TestCase): if prereq_version == 'all': for version in available_versions: self.application_type = type + ' ' + version + self.application_version = version super().run(result) elif prereq_version == 'any': self.application_type = type + ' ' + available_versions[0] @@ -165,7 +166,7 @@ class TestUnit(unittest.TestCase): self._run() def _run(self): - build_dir = self.pardir + '/build' + build_dir = os.path.join(self.pardir, 'build') self.unitd = build_dir + '/unitd' if not os.path.isfile(self.unitd): -- cgit