|
25 | 25 | import os |
26 | 26 | import statistics |
27 | 27 | from pathlib import Path |
| 28 | +from tempfile import TemporaryDirectory |
28 | 29 | from typing import Callable, List, Optional, TypeVar |
29 | 30 |
|
30 | 31 | import scipy |
31 | 32 |
|
32 | 33 | from framework import utils |
33 | 34 | from framework.microvm import Microvm |
34 | 35 | from framework.utils import CommandReturn |
35 | | -from framework.with_filelock import with_filelock |
36 | 36 | from host_tools.cargo_build import get_binary, get_firecracker_binaries |
37 | 37 |
|
38 | 38 | # 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( |
82 | 82 | (alternatively, your comparator can perform any required assertions and not return anything). |
83 | 83 | """ |
84 | 84 |
|
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) |
87 | 88 |
|
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) |
95 | 96 |
|
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 |
98 | 99 |
|
99 | 100 |
|
100 | 101 | def precompiled_binary_ab_test( |
@@ -249,26 +250,22 @@ def check_regression( |
249 | 250 | ) |
250 | 251 |
|
251 | 252 |
|
252 | | -@with_filelock |
253 | 253 | def git_clone(clone_path, commitish): |
254 | 254 | """Clone the repository at `commit`. |
255 | 255 |
|
256 | 256 | :return: the working copy directory. |
257 | 257 | """ |
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}") |
272 | 269 | return clone_path |
273 | 270 |
|
274 | 271 |
|
|
0 commit comments