Skip to content

Commit ff759fb

Browse files
add tests for skipped remote update with auto-cache
1 parent a81f4d4 commit ff759fb

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

tests/test_project_caching.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from conftest import (
1010
GIT,
1111
add_commit,
12+
chdir,
1213
cmd,
1314
create_branch,
1415
create_repo,
@@ -314,6 +315,100 @@ def test_update_auto_cache(tmpdir):
314315
assert bar_head_newer in rev_list(auto_cache_dir / "bar" / bar_hash)
315316

316317

318+
def test_update_auto_cache_skipped_remote_update(tmpdir):
319+
foo_remote = Path(tmpdir / 'remotes' / 'foo')
320+
bar_remote = Path(tmpdir / 'remotes' / 'bar')
321+
auto_cache_dir = Path(tmpdir / 'auto_cache_dir')
322+
323+
def create_foo_bar_commits():
324+
add_commit(foo_remote, 'new commit')
325+
add_commit(bar_remote, 'new commit')
326+
foo_head = rev_parse(foo_remote, 'HEAD')
327+
bar_head = rev_parse(bar_remote, 'HEAD')
328+
return foo_head, bar_head
329+
330+
def setup_workspace_and_west_update(workspace, foo_head, bar_head):
331+
setup_cache_workspace(
332+
workspace,
333+
foo_remote=foo_remote,
334+
foo_head=foo_head,
335+
bar_remote=bar_remote,
336+
bar_head=bar_head,
337+
)
338+
with chdir(workspace):
339+
stdout = cmd(['-v', 'update', '--auto-cache', auto_cache_dir])
340+
return stdout
341+
342+
create_repo(foo_remote)
343+
create_repo(bar_remote)
344+
foo_commit1, bar_commit1 = create_foo_bar_commits()
345+
foo_commit2, bar_commit2 = create_foo_bar_commits()
346+
347+
# run initial west update to setup auto-cache and get cache directories
348+
setup_workspace_and_west_update(
349+
tmpdir / 'workspace1',
350+
foo_head=foo_commit1,
351+
bar_head=bar_commit1,
352+
)
353+
354+
# read the auto-cache hashes from foo and bar
355+
(bar_hash,) = [p for p in (auto_cache_dir / 'bar').iterdir() if p.is_dir()]
356+
auto_cache_dir_bar = auto_cache_dir / 'bar' / bar_hash
357+
(foo_hash,) = [p for p in (auto_cache_dir / 'foo').iterdir() if p.is_dir()]
358+
auto_cache_dir_foo = auto_cache_dir / 'foo' / foo_hash
359+
360+
# Imitate that foo remote is temporarily offline by moving it temporarily.
361+
# Since foo and bar revisions are used which are already contained in the auto-cache,
362+
# west update should work with according messages as there is no need to update remotes.
363+
foo_moved = Path(tmpdir / 'remotes' / 'foo.moved')
364+
shutil.move(foo_remote, foo_moved)
365+
stdout = setup_workspace_and_west_update(
366+
tmpdir / 'workspace2',
367+
foo_head=foo_commit2,
368+
bar_head=bar_commit2,
369+
)
370+
shutil.move(foo_moved, foo_remote)
371+
msgs = [
372+
f"foo: auto-cache remote update is skipped as it already contains commit {foo_commit2}",
373+
f"foo: cloning from {auto_cache_dir_foo}",
374+
f"bar: auto-cache remote update is skipped as it already contains commit {bar_commit2}",
375+
f"bar: cloning from {auto_cache_dir_bar}",
376+
]
377+
for msg in msgs:
378+
assert msg in stdout
379+
380+
# If a new commit is used, the auto-cache should be updated with remote
381+
foo_commit3, bar_commit3 = create_foo_bar_commits()
382+
stdout = setup_workspace_and_west_update(
383+
tmpdir / 'workspace3',
384+
foo_head=foo_commit3,
385+
bar_head=bar_commit3,
386+
)
387+
msgs = [
388+
f"foo: update auto-cache ({auto_cache_dir_foo}) with remote",
389+
f"foo: cloning from {auto_cache_dir_foo}",
390+
f"bar: update auto-cache ({auto_cache_dir_bar}) with remote",
391+
f"bar: cloning from {auto_cache_dir_bar}",
392+
]
393+
for msg in msgs:
394+
assert msg in stdout
395+
396+
# If a branch is used as revision, the auto-cache must be updated.
397+
stdout = setup_workspace_and_west_update(
398+
tmpdir / 'workspace4',
399+
foo_head='master',
400+
bar_head='master',
401+
)
402+
msgs = [
403+
f"foo: update auto-cache ({auto_cache_dir_foo}) with remote",
404+
f"foo: cloning from {auto_cache_dir_foo}",
405+
f"bar: update auto-cache ({auto_cache_dir_bar}) with remote",
406+
f"bar: cloning from {auto_cache_dir_bar}",
407+
]
408+
for msg in msgs:
409+
assert msg in stdout
410+
411+
317412
def test_update_caches_priorities(tmpdir):
318413
# Test that the correct cache is used if multiple caches are specified
319414
# e.g. if 'west update --name-cache X --path-cache Y --auto-cache Z'

0 commit comments

Comments
 (0)