Skip to content

Commit 9c1a1d2

Browse files
committed
feat: store test results for A/B runs
Currently when A/B is run, only results for B test are available in the `test_results` dir because this dir is shared for both runs and the last one overwrites the data. Now we move results into separate dirs after tests are done.
1 parent 997fe17 commit 9c1a1d2

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

tests/framework/ab_test.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
of both invocations is the same, the test passes (with us being alerted to this situtation via a special pipeline that
2222
does not block PRs). If not, it fails, preventing PRs from introducing new vulnerable dependencies.
2323
"""
24+
import os
2425
import statistics
2526
from pathlib import Path
2627
from tempfile import TemporaryDirectory
@@ -103,7 +104,7 @@ def git_ab_test(
103104

104105

105106
def binary_ab_test(
106-
test_runner: Callable[[Path, bool], T],
107+
test_runner: Callable[[str, Path, bool], T],
107108
comparator: Callable[[T, T], U] = default_comparator,
108109
*,
109110
a_directory: Path = DEFAULT_A_DIRECTORY,
@@ -113,8 +114,14 @@ def binary_ab_test(
113114
Similar to `git_ab_test`, but instead of locally checking out different revisions, it operates on
114115
directories containing firecracker/jailer binaries
115116
"""
116-
result_a = test_runner(a_directory, True)
117-
result_b = test_runner(b_directory, False)
117+
result_a = test_runner("A", a_directory, True)
118+
result_b = test_runner("B", b_directory, False)
119+
120+
# put results back into the place, where buildkite will
121+
# expect them to be
122+
os.mkdir("test_results")
123+
os.rename("A", "test_results/A")
124+
os.rename("B", "test_results/B")
118125

119126
return result_a, result_b, comparator(result_a, result_b)
120127

@@ -160,7 +167,7 @@ def git_ab_test_host_command(
160167

161168

162169
def set_did_not_grow_comparator(
163-
set_generator: Callable[[CommandReturn], set]
170+
set_generator: Callable[[CommandReturn], set],
164171
) -> Callable[[CommandReturn, CommandReturn], bool]:
165172
"""Factory function for comparators to use with git_ab_test_command that converts the command output to sets
166173
(using the given callable) and then checks that the "B" set is a subset of the "A" set

tools/ab_test.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def uninteresting_dimensions(processed_emf):
180180
return uninteresting
181181

182182

183-
def collect_data(binary_dir: Path, pytest_opts: str):
183+
def collect_data(tag: str, binary_dir: Path, pytest_opts: str):
184184
"""Executes the specified test using the provided firecracker binaries"""
185185
binary_dir = binary_dir.resolve()
186186

@@ -195,8 +195,13 @@ def collect_data(binary_dir: Path, pytest_opts: str):
195195
check=True,
196196
shell=True,
197197
)
198+
199+
# move results into a tag directory
200+
os.mkdir(tag)
201+
os.rename("test_results", f"{tag}")
202+
198203
return load_data_series(
199-
Path("test_results/test-report.json"), binary_dir, reemit=True
204+
Path(f"{tag}/test-report.json"), binary_dir, reemit=True
200205
)
201206

202207

@@ -346,7 +351,7 @@ def ab_performance_test(
346351
"""Does an A/B-test of the specified test with the given firecracker/jailer binaries"""
347352

348353
return binary_ab_test(
349-
lambda bin_dir, _: collect_data(bin_dir, pytest_opts),
354+
lambda tag, bin_dir, _: collect_data(tag, bin_dir, pytest_opts),
350355
lambda ah, be: analyze_data(
351356
ah,
352357
be,

0 commit comments

Comments
 (0)