Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/datasmith/harbor_adapter/template/tests/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,16 @@ fi

SETUP_PHASE="base_copy"
# lsv_measure.py times this unpatched copy (with its build) against the patched repo. Overlayfs cannot rename
# image directories, so the repo is moved out and copied back to make both trees renamable.
# image directories, so both trees are copies. No mv of the image tree: on a merged directory with ~10^5 git objects,
# mv stopped on entries already gone (numpy#12445, pandas#40007); rm -rf skips them.
if [ "${FC_LSV_PAIRED:-1}" != "0" ]; then
cd /
rm -rf /workspace/.fc_base
mv /workspace/repo /workspace/.fc_base
cp -a /workspace/.fc_base /workspace/repo
rm -rf /workspace/.fc_base /workspace/.fc_new
cp -a /workspace/repo /workspace/.fc_base
cp -a /workspace/repo /workspace/.fc_new
rm -rf /workspace/repo
mv /workspace/.fc_new /workspace/repo
[ "$(git -C /workspace/repo rev-parse HEAD)" = "$(git -C /workspace/.fc_base rev-parse HEAD)" ]
cd /workspace/repo
fi

Expand Down
27 changes: 27 additions & 0 deletions tests/docker/test_setup_base_copy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import subprocess
from pathlib import Path

SETUP = Path(__file__).resolve().parents[2] / "src/datasmith/harbor_adapter/template/tests/prepare.sh"


def block(root: Path) -> str:
text = SETUP.read_text()
start, end = text.index('SETUP_PHASE="base_copy"'), text.index('SETUP_PHASE="lsv_init"')
return text[start:end].replace("/workspace", str(root))


def test_base_copy_makes_two_equal_trees_without_moving_the_repo(tmp_path):
repo = tmp_path / "repo"
repo.mkdir()
git = lambda *a: subprocess.run(["git", "-C", str(repo), *a], check=True, capture_output=True, text=True).stdout
git("init", "-q")
(repo / "a.py").write_text("x = 1\n")
git("add", "-A")
git("-c", "user.name=t", "-c", "user.email=t@t", "commit", "-q", "-m", "base")
head = git("rev-parse", "HEAD")
subprocess.run(["bash", "-c", "set -euo pipefail\n" + block(tmp_path)], check=True, capture_output=True)
for tree in (repo, tmp_path / ".fc_base"):
assert (tree / "a.py").read_text() == "x = 1\n"
assert subprocess.run(["git", "-C", str(tree), "rev-parse", "HEAD"], capture_output=True, text=True).stdout == head
assert not (tmp_path / ".fc_new").exists()
assert " mv /workspace/repo " not in SETUP.read_text()
33 changes: 33 additions & 0 deletions tests/docker/test_setup_baseline_commit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import re
import subprocess
import time
from pathlib import Path

SETUP = Path(__file__).resolve().parents[2] / "src/datasmith/harbor_adapter/template/tests/prepare.sh"


def baseline_block(sha_file: Path) -> str:
text = SETUP.read_text()
start, end = text.index('SETUP_PHASE="baseline_commit"'), text.index('SETUP_PHASE="base_copy"')
stage = (SETUP.parents[1] / "shared" / "stage_tree.sh").read_text()
block = re.sub(r'\{% filter indent\(2\) %\}\n\{% include "shared/stage_tree.sh" %\}\n\{% endfilter %\}\n', lambda _: stage, text[start:end])
return block.replace("/opt/fc_baseline_sha", str(sha_file))


def test_baseline_commit_starts_no_background_gc(tmp_path):
repo = tmp_path / "repo"
repo.mkdir()
git = lambda *a: subprocess.run(["git", "-C", str(repo), *a], check=True, capture_output=True, text=True).stdout
git("init", "-q")
for i in range(2000):
(repo / f"f{i}.txt").write_text(f"{i}\n")
git("add", "-A")
git("-c", "user.name=t", "-c", "user.email=t@t", "-c", "gc.auto=0", "commit", "-q", "-m", "base")
git("config", "gc.auto", "1")
(repo / "edit.txt").write_text("image edit\n")
subprocess.run(["bash", "-c", "set -euo pipefail\n" + baseline_block(tmp_path / "sha")], cwd=repo, check=True,
capture_output=True)
time.sleep(2)
assert git("log", "-1", "--format=%s").strip() == "fc-baseline"
assert not list((repo / ".git/objects/pack").glob("*.pack"))
assert int(git("count-objects").split()[0]) > 2000
Loading