From 9d44fa3d55f01e606f84c1f0424f50230e0a2cf3 Mon Sep 17 00:00:00 2001 From: Ryan Gonzalez Date: Thu, 7 Sep 2023 12:45:13 -0500 Subject: [PATCH 1/3] 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 --- system/lib.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/system/lib.py b/system/lib.py index d33e98e86..54a525f41 100644 --- a/system/lib.py +++ b/system/lib.py @@ -296,15 +296,12 @@ def run_cmd(self, command, expected_code=0): 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 From dbc5a68bdcfff869b8a9f57922ca0fe7e3a6d8bc Mon Sep 17 00:00:00 2001 From: Ryan Gonzalez Date: Thu, 7 Sep 2023 12:57:15 -0500 Subject: [PATCH 2/3] Fix the test output regex on Go 1.20 1.20 changes the output format of coverage checks slightly to include a package name on each line, followed by `coverage:`, but the current regex assumes that the line *starts* with `coverage:`. Signed-off-by: Ryan Gonzalez --- system/lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/lib.py b/system/lib.py index 54a525f41..c651ea635 100644 --- a/system/lib.py +++ b/system/lib.py @@ -296,7 +296,7 @@ def run_cmd(self, command, expected_code=0): 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 - match = re.search(r"EXIT: (\d)\n.*\ncoverage: .*", raw_output.decode("utf-8")) + match = re.search(r"EXIT: (\d)\n.*\n.*coverage: .*", raw_output.decode("utf-8")) if match is None: raise Exception("no matches found in output '%s'" % raw_output.decode("utf-8")) From 88f14099cee1c5dee23cca1d44bf2488d5c79c0d Mon Sep 17 00:00:00 2001 From: Ryan Gonzalez Date: Fri, 22 Sep 2023 15:24:34 -0500 Subject: [PATCH 3/3] Add myself to authors Signed-off-by: Ryan Gonzalez --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index cc7b65f08..67d80b6f1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -55,3 +55,4 @@ List of contributors, in chronological order: * Mauro Regli (https://github.com/reglim) * Alexander Zubarev (https://github.com/strike) * Nicolas Dostert (https://github.com/acdn-ndostert) +* Ryan Gonzalez (https://github.com/refi64)