|
3 | 3 | import re
|
4 | 4 | import sys
|
5 | 5 |
|
| 6 | +from subprocess import PIPE |
6 | 7 | from subprocess import Popen
|
7 | 8 | from threading import Timer
|
8 | 9 |
|
|
14 | 15 | from lib.tarantool_server import Test
|
15 | 16 | from lib.tarantool_server import TestExecutionError
|
16 | 17 | from lib.tarantool_server import TarantoolServer
|
| 18 | +from lib.utils import bytes_to_str |
17 | 19 | from lib.utils import find_tags
|
18 | 20 |
|
19 | 21 |
|
@@ -53,6 +55,10 @@ def execute(self, server):
|
53 | 55 | for p in Options().args.pattern:
|
54 | 56 | command.extend(['--pattern', p])
|
55 | 57 |
|
| 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 | + |
56 | 62 | # We start luatest from the project source directory, it
|
57 | 63 | # is the usual way to use luatest.
|
58 | 64 | #
|
@@ -138,6 +144,20 @@ def verify_luatest_exe(cls):
|
138 | 144 | # those cases, which are childs of OSError anyway.
|
139 | 145 | raise TestRunInitError('Unable to find luatest executable', e)
|
140 | 146 |
|
| 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 | + |
141 | 161 | @staticmethod
|
142 | 162 | def find_tests(test_suite, suite_path):
|
143 | 163 | """Looking for *_test.lua, which are can be executed by luatest."""
|
@@ -168,16 +188,34 @@ def find_tests(test_suite, suite_path):
|
168 | 188 | if any(p in test_name for p in exclude_patterns):
|
169 | 189 | continue
|
170 | 190 |
|
| 191 | + tags = find_tags(test_name) |
| 192 | + |
171 | 193 | # If --tags <...> CLI option is provided...
|
172 | 194 | if accepted_tags:
|
173 |
| - tags = find_tags(test_name) |
174 | 195 | # ...and the test has neither of the given tags,
|
175 | 196 | # skip the test.
|
176 | 197 | if not any(t in accepted_tags for t in tags):
|
177 | 198 | continue
|
178 | 199 |
|
179 | 200 | # 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)) |
181 | 219 |
|
182 | 220 | tests.sort(key=lambda t: t.name)
|
183 | 221 |
|
|
0 commit comments