Skip to content

Commit 45cca69

Browse files
committed
test: do pre-PR A/B-test checkout into temporary directory
Otherwise, they clash with the directories used for the pre-compiled binaries. Since each pipeline only uses git_ab_test in precisely one test, loosing the re-use is not a big deal. Signed-off-by: Patrick Roy <[email protected]>
1 parent 8381766 commit 45cca69

File tree

1 file changed

+24
-27
lines changed

1 file changed

+24
-27
lines changed

tests/framework/ab_test.py

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
import os
2626
import statistics
2727
from pathlib import Path
28+
from tempfile import TemporaryDirectory
2829
from typing import Callable, List, Optional, TypeVar
2930

3031
import scipy
3132

3233
from framework import utils
3334
from framework.microvm import Microvm
3435
from framework.utils import CommandReturn
35-
from framework.with_filelock import with_filelock
3636
from host_tools.cargo_build import get_binary, get_firecracker_binaries
3737

3838
# Locally, this will always compare against main, even if we try to merge into, say, a feature branch.
@@ -82,19 +82,20 @@ def git_ab_test(
8282
(alternatively, your comparator can perform any required assertions and not return anything).
8383
"""
8484

85-
dir_a = git_clone(Path("../build") / a_revision, a_revision)
86-
result_a = test_runner(dir_a, True)
85+
with TemporaryDirectory() as tmp_dir:
86+
dir_a = git_clone(Path(tmp_dir) / a_revision, a_revision)
87+
result_a = test_runner(dir_a, True)
8788

88-
if b_revision:
89-
dir_b = git_clone(Path("../build") / b_revision, b_revision)
90-
else:
91-
# By default, pytest execution happens inside the `tests` subdirectory. Pass the repository root, as
92-
# documented.
93-
dir_b = Path.cwd().parent
94-
result_b = test_runner(dir_b, False)
89+
if b_revision:
90+
dir_b = git_clone(Path(tmp_dir) / b_revision, b_revision)
91+
else:
92+
# By default, pytest execution happens inside the `tests` subdirectory. Pass the repository root, as
93+
# documented.
94+
dir_b = Path.cwd().parent
95+
result_b = test_runner(dir_b, False)
9596

96-
comparison = comparator(result_a, result_b)
97-
return result_a, result_b, comparison
97+
comparison = comparator(result_a, result_b)
98+
return result_a, result_b, comparison
9899

99100

100101
def precompiled_binary_ab_test(
@@ -249,26 +250,22 @@ def check_regression(
249250
)
250251

251252

252-
@with_filelock
253253
def git_clone(clone_path, commitish):
254254
"""Clone the repository at `commit`.
255255
256256
:return: the working copy directory.
257257
"""
258-
if not clone_path.exists():
259-
ret, _, _ = utils.run_cmd(f"git cat-file -t {commitish}")
260-
if ret != 0:
261-
# git didn't recognize this object; qualify it if it is a branch
262-
commitish = f"origin/{commitish}"
263-
# make a temp branch for that commit so we can directly check it out
264-
branch_name = f"tmp-{commitish}"
265-
utils.check_output(f"git branch {branch_name} {commitish}")
266-
_, git_root, _ = utils.run_cmd("git rev-parse --show-toplevel")
267-
# split off the '\n' at the end of the stdout
268-
utils.check_output(
269-
f"git clone -b {branch_name} {git_root.strip()} {clone_path}"
270-
)
271-
utils.check_output(f"git branch -D {branch_name}")
258+
ret, _, _ = utils.run_cmd(f"git cat-file -t {commitish}")
259+
if ret != 0:
260+
# git didn't recognize this object; qualify it if it is a branch
261+
commitish = f"origin/{commitish}"
262+
# make a temp branch for that commit so we can directly check it out
263+
branch_name = f"tmp-{commitish}"
264+
utils.check_output(f"git branch {branch_name} {commitish}")
265+
_, git_root, _ = utils.run_cmd("git rev-parse --show-toplevel")
266+
# split off the '\n' at the end of the stdout
267+
utils.check_output(f"git clone -b {branch_name} {git_root.strip()} {clone_path}")
268+
utils.check_output(f"git branch -D {branch_name}")
272269
return clone_path
273270

274271

0 commit comments

Comments
 (0)