Skip to content

Commit

Permalink
Use deterministic workdir ids
Browse files Browse the repository at this point in the history
  • Loading branch information
mernst committed Oct 31, 2023
1 parent c104908 commit fe5b009
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/python/merge_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def merge_analyzer( # pylint: disable=too-many-locals
Merges two branches and returns the result.
Args:
args (Tuple[str,pd.Series,Path]): A tuple containing the repo slug,
the merge data, and the cache path.
the merge data (which is side-effected), and the cache path.
Returns:
dict: A dictionary containing the merge result.
"""
Expand All @@ -58,8 +58,12 @@ def merge_analyzer( # pylint: disable=too-many-locals
return merge_data

cache_data = {}
repo_left = Repository(repo_slug, cache_directory=cache_directory)
repo_right = Repository(repo_slug, cache_directory=cache_directory)
repo_left = Repository(
repo_slug, cache_directory=cache_directory, workdir_id=merge_data["left"]
)
repo_right = Repository(
repo_slug, cache_directory=cache_directory, workdir_id=merge_data["right"]
)
left_success, _ = repo_left.checkout(merge_data["left"])
right_success, _ = repo_right.checkout(merge_data["right"])

Expand Down
6 changes: 5 additions & 1 deletion src/python/merge_differ.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ def get_merge_fingerprint(
return None, None
left = merge_data["left"]
right = merge_data["right"]
repo = Repository(repo_slug, cache_directory=cache_directory)
repo = Repository(
repo_slug,
cache_directory=cache_directory,
workdir_id="merge-" + left + "-" + right,
)
(
merge_status,
merge_fingerprint,
Expand Down
10 changes: 8 additions & 2 deletions src/python/merge_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def merge_tester(args: Tuple[str, pd.Series, Path]) -> pd.Series:
merge_data["parents pass"] = False
for branch in ["left", "right"]:
commit_sha = merge_data[branch]
repo = Repository(repo_slug, cache_directory=cache_directory)
repo = Repository(
repo_slug, cache_directory=cache_directory, workdir_id=commit_sha
)
test_result, test_coverage, tree_fingerprint = repo.checkout_and_test(
commit_sha, TIMEOUT_TESTING_PARENT, N_TESTS
)
Expand All @@ -77,7 +79,11 @@ def merge_tester(args: Tuple[str, pd.Series, Path]) -> pd.Series:
merge_data["parents pass"] = True

for merge_tool in MERGE_TOOL:
repo = Repository(repo_slug, cache_directory=cache_directory)
repo = Repository(
repo_slug,
cache_directory=cache_directory,
workdir_id="merge-" + merge_data["left"] + "-" + merge_data["right"],
)
(
result,
merge_fingerprint,
Expand Down
2 changes: 1 addition & 1 deletion src/python/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def __init__(
self,
repo_slug: str,
cache_directory: Path = Path(""),
workdir_id=uuid.uuid4().hex, # uuid4 is a random UID
) -> None:
"""Initializes the repository.
Args:
Expand All @@ -121,7 +122,6 @@ def __init__(
"""
self.repo_slug = repo_slug
self.path = REPOS_PATH / repo_slug.split("/")[1]
workdir_id = uuid.uuid4().hex
self.workdir = WORKDIR_DIRECTORY / workdir_id
self.workdir.mkdir(parents=True, exist_ok=True)
self.repo_path = self.workdir / self.path.name
Expand Down
4 changes: 3 additions & 1 deletion src/python/test_repo_heads.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ def head_passes_tests(args: Tuple[pd.Series, Path]) -> TEST_STATE:
repo_slug = repo_info["repository"]
print("test_repo_heads:", repo_slug, ": head_passes_tests : started")

repo = Repository(repo_slug, cache_directory=cache)
repo = Repository(
repo_slug, cache_directory=cache, workdir_id="head-" + repo_info["head hash"]
)
test_state, _, _ = repo.checkout_and_test(
repo_info["head hash"], timeout=TIMEOUT_TESTING, n_tests=3
)
Expand Down

0 comments on commit fe5b009

Please sign in to comment.