Skip to content

Commit dd00063

Browse files
Totktonadaylobankov
authored andcommitted
luatest: allow to run test cases in parallel
In order to use the feature, add the following comment to a beginning of the test file: ```lua -- tags: parallel ```
1 parent 3b0ccd0 commit dd00063

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

lib/luatest_server.py

+40-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import re
44
import sys
55

6+
from subprocess import PIPE
67
from subprocess import Popen
78
from threading import Timer
89

@@ -14,6 +15,7 @@
1415
from lib.tarantool_server import Test
1516
from lib.tarantool_server import TestExecutionError
1617
from lib.tarantool_server import TarantoolServer
18+
from lib.utils import bytes_to_str
1719
from lib.utils import find_tags
1820

1921

@@ -53,6 +55,10 @@ def execute(self, server):
5355
for p in Options().args.pattern:
5456
command.extend(['--pattern', p])
5557

58+
# Run a specific test case. See find_tests() for details.
59+
if 'test_case' in self.run_params:
60+
command.extend(['--run-test-case', self.run_params['test_case']])
61+
5662
# We start luatest from the project source directory, it
5763
# is the usual way to use luatest.
5864
#
@@ -138,6 +144,20 @@ def verify_luatest_exe(cls):
138144
# those cases, which are childs of OSError anyway.
139145
raise TestRunInitError('Unable to find luatest executable', e)
140146

147+
@classmethod
148+
def test_cases(cls, test_name):
149+
p = Popen([cls.luatest, test_name, '--list-test-cases'], stdout=PIPE)
150+
output = bytes_to_str(p.stdout.read()).rstrip()
151+
p.wait()
152+
153+
# Exclude the first line if it is a tarantool version
154+
# report.
155+
res = output.split('\n')
156+
if len(res) > 0 and res[0].startswith('Tarantool version is'):
157+
return res[1:]
158+
159+
return res
160+
141161
@staticmethod
142162
def find_tests(test_suite, suite_path):
143163
"""Looking for *_test.lua, which are can be executed by luatest."""
@@ -168,16 +188,34 @@ def find_tests(test_suite, suite_path):
168188
if any(p in test_name for p in exclude_patterns):
169189
continue
170190

191+
tags = find_tags(test_name)
192+
171193
# If --tags <...> CLI option is provided...
172194
if accepted_tags:
173-
tags = find_tags(test_name)
174195
# ...and the test has neither of the given tags,
175196
# skip the test.
176197
if not any(t in accepted_tags for t in tags):
177198
continue
178199

179200
# Add the test to the execution list otherwise.
180-
tests.append(LuatestTest(test_name, test_suite.args, test_suite.ini))
201+
if 'parallel' in tags:
202+
# If the test has the 'parallel' tag, split the
203+
# test to test cases to run in separate tasks in
204+
# parallel.
205+
test_cases = LuatestServer.test_cases(test_name)
206+
207+
# Display shorter test case names on the screen:
208+
# strip the common prefix.
209+
prefix_len = len(os.path.commonprefix(test_cases))
210+
211+
for test_case in test_cases:
212+
tests.append(LuatestTest(test_name, test_suite.args, test_suite.ini,
213+
params={"test_case": test_case},
214+
conf_name=test_case[prefix_len:]))
215+
else:
216+
# If the test has no 'parallel' tag, run all the
217+
# test cases as one task.
218+
tests.append(LuatestTest(test_name, test_suite.args, test_suite.ini))
181219

182220
tests.sort(key=lambda t: t.name)
183221

0 commit comments

Comments
 (0)