Skip to content

Commit

Permalink
luatest: fix ability to run a test several times
Browse files Browse the repository at this point in the history
It is a regression from commit 3b0ccd0 ("luatest: detox test
searching code"), PR #433.

The ability to run a test several times, especially in parallel, is very
useful to reproduce and debug an unstable behavior in the test.

Fixes #437
  • Loading branch information
Totktonada committed Jun 18, 2024
1 parent b8b60b4 commit 240cdea
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions lib/luatest_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,26 @@ def find_tests(test_suite, suite_path):

tests = []
for test_name in glob.glob(os.path.join(suite_path, '*_test.lua')):
# If neither of the include patterns are substrings of
# the given test name, skip the test.
if not any(p in test_name for p in include_patterns):
# Several include patterns may match the given
# test[^1].
#
# The primary usage of this behavior is to run a test
# many times in parallel to verify its stability or
# to debug an unstable behavior.
#
# Execute the test once for each of the matching
# patterns.
#
# [^1]: A pattern matches a test if the pattern is a
# substring of the test name.
repeat = sum(1 for p in include_patterns if p in test_name)
# If neither of the include patterns matches the given
# test, skip the test.
if repeat == 0:
continue

# If at least one of the exclude patterns is a
# substring of the given test name, skip the test.
# If at least one of the exclude patterns matches the
# given test, skip the test.
if any(p in test_name for p in exclude_patterns):
continue

Expand All @@ -211,13 +224,15 @@ def find_tests(test_suite, suite_path):
prefix_len = len(os.path.commonprefix(test_cases))

for test_case in test_cases:
tests.append(LuatestTest(test_name, test_suite.args, test_suite.ini,
params={"test_case": test_case},
conf_name=test_case[prefix_len:]))
test_obj = LuatestTest(test_name, test_suite.args, test_suite.ini,
params={"test_case": test_case},
conf_name=test_case[prefix_len:])
tests.extend([test_obj] * repeat)
else:
# If the test has no 'parallel' tag, run all the
# test cases as one task.
tests.append(LuatestTest(test_name, test_suite.args, test_suite.ini))
test_obj = LuatestTest(test_name, test_suite.args, test_suite.ini)
tests.extend([test_obj] * repeat)

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

Expand Down

0 comments on commit 240cdea

Please sign in to comment.