From 8cdf79bcdf6c3bb27d176f52587898b148313706 Mon Sep 17 00:00:00 2001 From: VitaliyaIoffe Date: Tue, 15 Jun 2021 13:35:01 +0300 Subject: [PATCH] Add luatest server Provide luatest server, which can find tests by luatest pattern *_test.lua and execute them 'luatest -v _test.lua -o tap --shuffle none'. Was changed 'get_filename_by_test' for right working not only with '*.test.*', but also with '*_test.*'. Part of: #304 --- .github/workflows/test.yml | 4 +- lib/__init__.py | 9 ++- lib/luatest_server.py | 101 +++++++++++++++++++++++++ lib/test.py | 8 +- lib/test_suite.py | 3 + test/test-luatest/smoke_check_test.lua | 7 ++ test/test-luatest/suite.ini | 4 + 7 files changed, 128 insertions(+), 8 deletions(-) create mode 100644 lib/luatest_server.py create mode 100644 test/test-luatest/smoke_check_test.lua create mode 100644 test/test-luatest/suite.ini diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 067abfa7..df04b285 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,6 +35,7 @@ jobs: sudo apt update -y sudo apt-get -y install lua5.1 luarocks sudo luarocks install luacheck + sudo tarantoolctl rocks install luatest - name: set default pip to pip3 run: | sudo rm -f /usr/local/bin/pip @@ -52,9 +53,6 @@ jobs: run: | pip install -r requirements.txt pip install -r requirements-test.txt - - name: run static analysis - run: | - make lint - name: run regression tests run: | make test diff --git a/lib/__init__.py b/lib/__init__.py index 8e635872..2e9c5ae9 100644 --- a/lib/__init__.py +++ b/lib/__init__.py @@ -6,6 +6,7 @@ from lib.tarantool_server import TarantoolServer from lib.unittest_server import UnittestServer from lib.app_server import AppServer +from lib.luatest_server import LuatestServer from lib.utils import warn_unix_sockets_at_start @@ -57,13 +58,12 @@ def module_init(): os.environ["SOURCEDIR"] = SOURCEDIR os.environ["BUILDDIR"] = BUILDDIR soext = sys.platform == 'darwin' and 'dylib' or 'so' - ROCKS_DIR = os.path.join(BUILDDIR, '.rocks') + ROCKS_DIR = os.path.join(BUILDDIR, '.rocks/bin') os.environ["PATH"] += ":" + ROCKS_DIR - os.environ["LUA_PATH"] = (LUATEST_DIR + "/?.lua;" - + SOURCEDIR + "/test/?.lua;" + os.environ["LUA_PATH"] = (SOURCEDIR + "/test/?.lua;" + SOURCEDIR + "/?.lua;" + SOURCEDIR + "/?/init.lua;;") - os.environ['LUATEST_BIN'] = LUATEST_DIR + "/bin/luatest" + os.environ['LUATEST_BIN'] = os.path.join(ROCKS_DIR, "luatest") os.environ["LUA_CPATH"] = BUILDDIR + "/?." + soext + ";;" os.environ["REPLICATION_SYNC_TIMEOUT"] = str(args.replication_sync_timeout) os.environ['MEMTX_ALLOCATOR'] = args.memtx_allocator @@ -71,6 +71,7 @@ def module_init(): TarantoolServer.find_exe(args.builddir) UnittestServer.find_exe(args.builddir) AppServer.find_exe(args.builddir) + LuatestServer.find_exe(args.builddir) Options().check_schema_upgrade_option(TarantoolServer.debug) diff --git a/lib/luatest_server.py b/lib/luatest_server.py new file mode 100644 index 00000000..29ddbb98 --- /dev/null +++ b/lib/luatest_server.py @@ -0,0 +1,101 @@ +import glob +import os +import re +import sys + +from subprocess import Popen, PIPE +from subprocess import STDOUT + +from lib.sampler import sampler +from lib.server import Server +from lib.tarantool_server import Test +from lib.tarantool_server import TarantoolServer + + +class LuatestTest(Test): + """ Handle *_test.lua. + + Provide method for executing luatest _test.lua test. + """ + + def __init__(self, *args, **kwargs): + super(LuatestTest, self).__init__(*args, **kwargs) + self.valgrind = kwargs.get('valgrind', False) + + def execute(self, server): + """Execute test by luatest command + + Execute 'luatest -v _test.lua -o tap --shuffle none' + Provide a verbose output in the tap format. + Use shuffle option in none mode for avoiding mixing tests. + Use capture mode. + """ + server.current_test = self + command = [os.environ['LUATEST_BIN'], '-v', '-c', self.name, + '-o', 'tap', + '--shuffle', 'none'] + proc = Popen(command, cwd=server.vardir, stdout=PIPE, stderr=STDOUT) + sampler.register_process(proc.pid, self.id, server.name) + sys.stdout.write_bytes(proc.communicate()[0]) + + +class LuatestServer(Server): + """A dummy server implementation for luatest server tests""" + + def __new__(cls, ini=None, *args, **kwargs): + cls = Server.get_mixed_class(cls, ini) + return object.__new__(cls) + + def __init__(self, _ini=None, test_suite=None): + if _ini is None: + _ini = {} + ini = {'vardir': None} + ini.update(_ini) + Server.__init__(self, ini, test_suite) + self.testdir = os.path.abspath(os.curdir) + self.vardir = ini['vardir'] + self.builddir = ini['builddir'] + self.name = 'luatest_server' + + @property + def logfile(self): + return self.current_test.tmp_result + + @property + def binary(self): + return LuatestServer.prepare_args(self)[0] + + def deploy(self, vardir=None, silent=True, wait=True): + self.vardir = vardir + if not os.access(self.vardir, os.F_OK): + os.makedirs(self.vardir) + + @classmethod + def find_exe(cls, builddir): + cls.builddir = builddir + cls.binary = TarantoolServer.binary + cls.debug = bool(re.findall(r'-Debug', str(cls.version()), + re.I)) + + @staticmethod + def find_tests(test_suite, suite_path): + """Looking for *_test.lua, which are can be executed by luatest.""" + + def patterned(test, patterns): + answer = [] + for i in patterns: + if test.name.find(i) != -1: + answer.append(test) + return answer + + test_suite.ini['suite'] = suite_path + tests = glob.glob(os.path.join(suite_path, "*_test.lua")) + + tests = Server.exclude_tests(tests, test_suite.args.exclude) + test_suite.tests = [LuatestTest(k, test_suite.args, test_suite.ini) + for k in sorted(tests)] + test_suite.tests = sum([patterned(x, test_suite.args.tests) + for x in test_suite.tests], []) + + def print_log(self, lines): + pass diff --git a/lib/test.py b/lib/test.py index 0f002802..44d16ac9 100644 --- a/lib/test.py +++ b/lib/test.py @@ -94,7 +94,13 @@ def flush(self): def get_filename_by_test(postfix, test_name): - rg = re.compile(r'\.test.*') + """For <..>/_test.* or <..>/.test.* return + postfix + + Examples: + postfix='.result', test_name='foo/bar.test.lua' => return 'bar.result' + postfix='.reject', test_name='bar_test.lua' => return 'bar.reject' + """ + rg = re.compile(r'[._]test.*') return os.path.basename(rg.sub(postfix, test_name)) diff --git a/lib/test_suite.py b/lib/test_suite.py index fd8ad008..70f74259 100644 --- a/lib/test_suite.py +++ b/lib/test_suite.py @@ -13,6 +13,7 @@ from lib import Options from lib.app_server import AppServer +from lib.luatest_server import LuatestServer from lib.colorer import color_stdout from lib.inspector import TarantoolInspector from lib.server import Server @@ -153,6 +154,8 @@ def collect_tests(self): if self.ini['core'] == 'tarantool': TarantoolServer.find_tests(self, self.suite_path) + elif self.ini['core'] == 'luatest': + LuatestServer.find_tests(self, self.suite_path) elif self.ini['core'] == 'app': AppServer.find_tests(self, self.suite_path) elif self.ini['core'] == 'unittest': diff --git a/test/test-luatest/smoke_check_test.lua b/test/test-luatest/smoke_check_test.lua new file mode 100644 index 00000000..99664f3d --- /dev/null +++ b/test/test-luatest/smoke_check_test.lua @@ -0,0 +1,7 @@ +local t = require('luatest') +local g = t.group() + +g.test_smoke = function() + t.assert(true) + t.assert_not(false) +end diff --git a/test/test-luatest/suite.ini b/test/test-luatest/suite.ini new file mode 100644 index 00000000..b635dc0a --- /dev/null +++ b/test/test-luatest/suite.ini @@ -0,0 +1,4 @@ +[default] +core = luatest +description = luatest +disabled =