mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-05 05:20:34 +00:00
Improve test output regex for better perf
The current regex runs in exponential time, which massively impacts the
runtime of the test suite, taking several seconds (~4s on my system)
just to perform a single match. By replacing the mix of re.findall + the
initial capture group with re.search + some string slicing, the time
spent matching the regex becomes nearly instant, e.g.:
$ make system-test TESTS='Config*'
goes from taking ~10s to ~1.5s.
Signed-off-by: Ryan Gonzalez <ryan.gonzalez@collabora.com>
This commit is contained in:
+4
-7
@@ -296,15 +296,12 @@ class BaseTest(object):
|
||||
if is_aptly_command:
|
||||
# remove the last two rows as go tests always print PASS/FAIL and coverage in those
|
||||
# two lines. This would otherwise fail the tests as they would not match gold
|
||||
matches = re.findall(r"((.|\n)*)EXIT: (\d)\n.*\ncoverage: .*", raw_output.decode("utf-8"))
|
||||
if not matches:
|
||||
match = re.search(r"EXIT: (\d)\n.*\ncoverage: .*", raw_output.decode("utf-8"))
|
||||
if match is None:
|
||||
raise Exception("no matches found in output '%s'" % raw_output.decode("utf-8"))
|
||||
|
||||
output, _, returncode = matches[0]
|
||||
|
||||
output = output.encode()
|
||||
returncodes.append(int(returncode))
|
||||
|
||||
output = match.string[:match.start()].encode()
|
||||
returncodes.append(int(match.group(1)))
|
||||
else:
|
||||
output = raw_output
|
||||
|
||||
|
||||
Reference in New Issue
Block a user