From 5d67879a5051f7e3d3b4dd96da4f43e7822f7da4 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Thu, 27 Feb 2020 18:41:24 +0000 Subject: Tests: added "-r" option to print unit.log on failures. --- test/unit/main.py | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'test/unit') diff --git a/test/unit/main.py b/test/unit/main.py index 37d01d3b..149cfb2c 100644 --- a/test/unit/main.py +++ b/test/unit/main.py @@ -30,6 +30,7 @@ class TestUnit(unittest.TestCase): detailed = False save_log = False + print_log = False unsafe = False def __init__(self, methodName='runTest'): @@ -183,7 +184,7 @@ class TestUnit(unittest.TestCase): shutil.rmtree(self.testdir) else: - self._print_path_to_log() + self._print_log() def stop(self): if self._started: @@ -281,14 +282,14 @@ class TestUnit(unittest.TestCase): alerts = [al for al in alerts if re.search(skip, al) is None] if alerts: - self._print_path_to_log() + self._print_log(log) self.assertFalse(alerts, 'alert(s)') if not self.skip_sanitizer: sanitizer_errors = re.findall('.+Sanitizer.+', log) if sanitizer_errors: - self._print_path_to_log() + self._print_log(log) self.assertFalse(sanitizer_errors, 'sanitizer error(s)') if found: @@ -360,6 +361,13 @@ class TestUnit(unittest.TestCase): action='store_true', help='Save unit.log after the test execution', ) + parser.add_argument( + '-r', + '--reprint_log', + dest='print_log', + action='store_true', + help='Print unit.log to stdout in case of errors', + ) parser.add_argument( '-u', '--unsafe', @@ -374,6 +382,7 @@ class TestUnit(unittest.TestCase): def _set_args(args): TestUnit.detailed = args.detailed TestUnit.save_log = args.save_log + TestUnit.print_log = args.print_log TestUnit.unsafe = args.unsafe # set stdout to non-blocking @@ -381,5 +390,15 @@ class TestUnit(unittest.TestCase): if TestUnit.detailed: fcntl.fcntl(sys.stdout.fileno(), fcntl.F_SETFL, 0) - def _print_path_to_log(self): - print('Path to unit.log:\n' + self.testdir + '/unit.log') + def _print_log(self, data=None): + path = self.testdir + '/unit.log' + + print('Path to unit.log:\n' + path + '\n') + + if TestUnit.print_log: + if data is None: + with open(path, 'r', encoding='utf-8', errors='ignore') as f: + data = f.read() + + print(data) + -- cgit From f68947bc60c930d460e1bd71bb5f486579009578 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Mon, 2 Mar 2020 13:10:38 +0000 Subject: Tests: truncated huge messages while logging. --- test/unit/http.py | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) (limited to 'test/unit') diff --git a/test/unit/http.py b/test/unit/http.py index c71e8f7e..47fb48f1 100644 --- a/test/unit/http.py +++ b/test/unit/http.py @@ -96,12 +96,7 @@ class TestHTTP(TestUnit): encoding = 'utf-8' if 'encoding' not in kwargs else kwargs['encoding'] - if TestUnit.detailed: - print('>>>') - try: - print(req.decode(encoding, 'ignore')) - except UnicodeEncodeError: - print(req) + self.log_out(req, encoding) resp = '' @@ -113,12 +108,7 @@ class TestHTTP(TestUnit): sock, read_timeout=read_timeout, buff_size=read_buffer_size ).decode(encoding) - if TestUnit.detailed: - print('<<<') - try: - print(resp) - except UnicodeEncodeError: - print(resp.encode()) + self.log_in(resp) if 'raw_resp' not in kwargs: resp = self._resp_to_dict(resp) @@ -138,6 +128,37 @@ class TestHTTP(TestUnit): return (resp, sock) + def log_out(self, log, encoding): + if TestUnit.detailed: + print('>>>') + log = self.log_truncate(log) + try: + print(log.decode(encoding, 'ignore')) + except UnicodeEncodeError: + print(log) + + def log_in(self, log): + if TestUnit.detailed: + print('<<<') + log = self.log_truncate(log) + try: + print(log) + except UnicodeEncodeError: + print(log.encode()) + + def log_truncate(self, log, limit=1024): + len_log = len(log) + if len_log > limit: + log = log[:limit] + appendix = '(...logged %s of %s bytes)' % (limit, len_log) + + if isinstance(log, bytes): + appendix = appendix.encode() + + log = log + appendix + + return log + def delete(self, **kwargs): return self.http('DELETE', **kwargs) -- cgit From 80763b3e64cfeae358c521fa563cc9eaa48f4ea2 Mon Sep 17 00:00:00 2001 From: Tiago Natel de Moura Date: Tue, 3 Mar 2020 18:53:26 +0000 Subject: Tests: chdir() and open() for PHP module. These tests ensure optimizations in the chdir calls don't break SAPI semantics. --- test/unit/applications/lang/php.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/unit') diff --git a/test/unit/applications/lang/php.py b/test/unit/applications/lang/php.py index 6b1677e6..e8c70c62 100644 --- a/test/unit/applications/lang/php.py +++ b/test/unit/applications/lang/php.py @@ -4,7 +4,7 @@ from unit.applications.proto import TestApplicationProto class TestApplicationPHP(TestApplicationProto): application_type = "php" - def load(self, script, name='index.php', **kwargs): + def load(self, script, index='index.php', **kwargs): script_path = self.current_dir + '/php/' + script self._load_conf( @@ -16,7 +16,7 @@ class TestApplicationPHP(TestApplicationProto): "processes": {"spare": 0}, "root": script_path, "working_directory": script_path, - "index": name, + "index": index, } }, }, -- cgit From 3617d4ed03326239587b7299370e64669533c6f5 Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Fri, 6 Mar 2020 20:08:29 +0300 Subject: Tests: simplified unitd process running. There are no reasons to wrap the Unit daemon in a separate Python process. --- test/unit/main.py | 68 +++++++++++++++++++++---------------------------------- 1 file changed, 26 insertions(+), 42 deletions(-) (limited to 'test/unit') diff --git a/test/unit/main.py b/test/unit/main.py index 149cfb2c..322066ba 100644 --- a/test/unit/main.py +++ b/test/unit/main.py @@ -5,6 +5,7 @@ import stat import time import fcntl import shutil +import signal import argparse import platform import tempfile @@ -210,22 +211,19 @@ class TestUnit(unittest.TestCase): print() - self._p = Process(target=subprocess.call, args=[ [ - self.unitd, - '--no-daemon', - '--modules', self.pardir + '/build', - '--state', self.testdir + '/state', - '--pid', self.testdir + '/unit.pid', - '--log', self.testdir + '/unit.log', - '--control', 'unix:' + self.testdir + '/control.unit.sock', - ] ]) - self._p.start() - - if not self.waitforfiles( - self.testdir + '/unit.pid', - self.testdir + '/unit.log', - self.testdir + '/control.unit.sock', - ): + self._p = subprocess.Popen( + [ + self.unitd, + '--no-daemon', + '--modules', self.pardir + '/build', + '--state', self.testdir + '/state', + '--pid', self.testdir + '/unit.pid', + '--log', self.testdir + '/unit.log', + '--control', 'unix:' + self.testdir + '/control.unit.sock', + ] + ) + + if not self.waitforfiles(self.testdir + '/control.unit.sock'): exit("Could not start unit") self._started = True @@ -238,35 +236,21 @@ class TestUnit(unittest.TestCase): self.skip_sanitizer = False def _stop(self): - with open(self.testdir + '/unit.pid', 'r') as f: - pid = f.read().rstrip() - - subprocess.call(['kill', '-s', 'QUIT', pid]) - - for i in range(150): - if not os.path.exists(self.testdir + '/unit.pid'): - break - time.sleep(0.1) - - self._p.join(timeout=5) - - if self._p.is_alive(): - self._p.terminate() - self._p.join(timeout=5) - - if self._p.is_alive(): - self.fail("Could not terminate process " + str(self._p.pid)) - - if os.path.exists(self.testdir + '/unit.pid'): - self.fail("Could not terminate unit") + with self._p as p: + p.send_signal(signal.SIGQUIT) + + try: + retcode = p.wait(15) + if retcode: + self.fail( + "Child process terminated with code " + str(retcode) + ) + except: + self.fail("Could not terminate unit") + p.kill() self._started = False - if self._p.exitcode: - self.fail( - "Child process terminated with code " + str(self._p.exitcode) - ) - def _check_alerts(self, log): found = False -- cgit From 810b8dbb6798bd8ddcbafae7ecd9e5ee535c92f4 Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Fri, 6 Mar 2020 20:08:38 +0300 Subject: Tests: unitd stderr output redirected to unit.log. A part of the debug log was printed to stderr before the log file was opened. Now, this output is redirected to the same log file. --- test/unit/main.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'test/unit') diff --git a/test/unit/main.py b/test/unit/main.py index 322066ba..a7981c1c 100644 --- a/test/unit/main.py +++ b/test/unit/main.py @@ -209,19 +209,19 @@ class TestUnit(unittest.TestCase): os.mkdir(self.testdir + '/state') - print() - - self._p = subprocess.Popen( - [ - self.unitd, - '--no-daemon', - '--modules', self.pardir + '/build', - '--state', self.testdir + '/state', - '--pid', self.testdir + '/unit.pid', - '--log', self.testdir + '/unit.log', - '--control', 'unix:' + self.testdir + '/control.unit.sock', - ] - ) + with open(self.testdir + '/unit.log', 'w') as log: + self._p = subprocess.Popen( + [ + self.unitd, + '--no-daemon', + '--modules', self.pardir + '/build', + '--state', self.testdir + '/state', + '--pid', self.testdir + '/unit.pid', + '--log', self.testdir + '/unit.log', + '--control', 'unix:' + self.testdir + '/control.unit.sock', + ], + stderr=log, + ) if not self.waitforfiles(self.testdir + '/control.unit.sock'): exit("Could not start unit") -- cgit From f36f0f2461a7f0447e92f977ff9c0c71fcb08ffb Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Tue, 10 Mar 2020 18:10:42 +0000 Subject: Tests: redirect tests output to the stdout. --- test/unit/applications/lang/go.py | 5 +++-- test/unit/applications/lang/java.py | 4 ++-- test/unit/applications/tls.py | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) (limited to 'test/unit') diff --git a/test/unit/applications/lang/go.py b/test/unit/applications/lang/go.py index 7212a95c..e0f83c0a 100644 --- a/test/unit/applications/lang/go.py +++ b/test/unit/applications/lang/go.py @@ -1,5 +1,5 @@ import os -from subprocess import Popen +import subprocess from unit.applications.proto import TestApplicationProto @@ -26,7 +26,7 @@ class TestApplicationGo(TestApplicationProto): env['GOPATH'] = self.pardir + '/build/go' try: - process = Popen( + process = subprocess.Popen( [ 'go', 'build', @@ -35,6 +35,7 @@ class TestApplicationGo(TestApplicationProto): self.current_dir + '/go/' + script + '/' + name + '.go', ], env=env, + stderr=subprocess.STDOUT, ) process.communicate() diff --git a/test/unit/applications/lang/java.py b/test/unit/applications/lang/java.py index a370d96b..a8a09ce5 100644 --- a/test/unit/applications/lang/java.py +++ b/test/unit/applications/lang/java.py @@ -1,7 +1,7 @@ import os import glob import shutil -from subprocess import Popen +import subprocess from unit.applications.proto import TestApplicationProto @@ -64,7 +64,7 @@ class TestApplicationJava(TestApplicationProto): javac.extend(src) try: - process = Popen(javac) + process = subprocess.Popen(javac, stderr=subprocess.STDOUT) process.communicate() except: diff --git a/test/unit/applications/tls.py b/test/unit/applications/tls.py index 1290279d..9213974a 100644 --- a/test/unit/applications/tls.py +++ b/test/unit/applications/tls.py @@ -47,7 +47,8 @@ class TestApplicationTLS(TestApplicationProto): '-config', self.testdir + '/openssl.conf', '-out', self.testdir + '/' + name + '.crt', '-keyout', self.testdir + '/' + name + '.key', - ] + ], + stderr=subprocess.STDOUT, ) if load: -- cgit From f092b093f561f0bffeb990c176246c6f6413401d Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Tue, 10 Mar 2020 18:13:47 +0000 Subject: Tests: use blocking to print unit.log files. --- test/unit/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/unit') diff --git a/test/unit/main.py b/test/unit/main.py index a7981c1c..b38d87e2 100644 --- a/test/unit/main.py +++ b/test/unit/main.py @@ -371,7 +371,7 @@ class TestUnit(unittest.TestCase): # set stdout to non-blocking - if TestUnit.detailed: + if TestUnit.detailed or TestUnit.print_log: fcntl.fcntl(sys.stdout.fileno(), fcntl.F_SETFL, 0) def _print_log(self, data=None): -- cgit From 961674af4220ee2e769bb01ce9acd213ecaaa33c Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Thu, 12 Mar 2020 13:44:30 +0000 Subject: Tests: skip "last message send failed" alerts globally. --- test/unit/main.py | 1 + 1 file changed, 1 insertion(+) (limited to 'test/unit') diff --git a/test/unit/main.py b/test/unit/main.py index b38d87e2..a7f5816a 100644 --- a/test/unit/main.py +++ b/test/unit/main.py @@ -230,6 +230,7 @@ class TestUnit(unittest.TestCase): self.skip_alerts = [ r'read signalfd\(4\) failed', + r'last message send failed', r'sendmsg.+failed', r'recvmsg.+failed', ] -- cgit From 5296be0b82784eb90abc86339e6c16841e9a9727 Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Thu, 12 Mar 2020 17:54:29 +0300 Subject: Using disk file to store large request body. This closes #386 on GitHub. --- test/unit/main.py | 1 + 1 file changed, 1 insertion(+) (limited to 'test/unit') diff --git a/test/unit/main.py b/test/unit/main.py index a7f5816a..69234dcc 100644 --- a/test/unit/main.py +++ b/test/unit/main.py @@ -219,6 +219,7 @@ class TestUnit(unittest.TestCase): '--pid', self.testdir + '/unit.pid', '--log', self.testdir + '/unit.log', '--control', 'unix:' + self.testdir + '/control.unit.sock', + '--tmp', self.testdir, ], stderr=log, ) -- cgit