Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote: Fix "file not found" error when remote cache is changed from enabled to disabled. #14252

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
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
69 changes: 49 additions & 20 deletions src/test/shell/bazel/remote/remote_execution_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3204,23 +3204,23 @@ EOF
expect_not_log "WARNING: Writing to Remote Cache:"
}

function test_download_toplevel_when_turn_remote_cache_off() {
# Test that BwtB does cause build failure if remote cache is disabled in a following build.
function test_download_toplevel_when_turn_remote_cache_off_without_metadata() {
# Test that BwtB doesn't cause build failure if remote cache is disabled in a following build.
# See https://github.com/bazelbuild/bazel/issues/13882.

mkdir -p a
cat > a/BUILD <<EOF
mkdir a
cat > a/BUILD <<'EOF'
genrule(
name = "producer",
outs = ["a.txt", "b.txt"],
cmd = "touch \$(OUTS)",
cmd = "touch $(OUTS)",
)

genrule(
name = "consumer",
outs = ["out.txt"],
srcs = [":b.txt", "in.txt"],
cmd = "cat \$(SRCS) > \$@",
cmd = "cat $(SRCS) > $@",
)
EOF
echo 'foo' > a/in.txt
Expand All @@ -3232,44 +3232,73 @@ EOF
--verbose_failures \
//a:consumer >& $TEST_log || fail "Failed to populate the cache"

bazel clean || fail "Failed to clean"
bazel clean >& $TEST_log || fail "Failed to clean"

# download top level outputs without remote metadata
# download top level outputs
bazel build \
--remote_cache=grpc://localhost:${worker_port} \
--remote_download_toplevel \
--verbose_failures \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supernit: --verbose_failures is unlikely needed/we could add that to the blazerc for the whole test if that aids debugging failures.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

//a:consumer >& $TEST_log || fail "Failed to download outputs without remote metadata"
(! [[ -f bazel-bin/a/a.txt ]] && ! [[ -f bazel-bin/a/b.txt ]]) \
|| fail "Expected outputs of producer are not downloaded without remote metadata"
//a:consumer >& $TEST_log || fail "Failed to download outputs"
[[ -f bazel-bin/a/a.txt ]] || [[ -f bazel-bin/a/b.txt ]] \
&& fail "Expected outputs of producer are not downloaded"

# build without remote cache without remote metadata
# build without remote cache
echo 'bar' > a/in.txt
bazel build \
--remote_download_toplevel \
--verbose_failures \
//a:consumer >& $TEST_log || fail "Failed to build without remote cache without remote metadata"
//a:consumer >& $TEST_log || fail "Failed to build without remote cache"
}

bazel clean || fail "Failed to clean"
function test_download_toplevel_when_turn_remote_cache_off_with_metadata() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 2 test cases differ by 1 option only -- why not put the test case as a separate helper function and call that twice with different parameters (Bash tests parameterization). Example here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

# Test that BwtB doesn't cause build failure if remote cache is disabled (but with
# --experimental_action_cache_store_output_metadata) in a following build.
# See https://github.com/bazelbuild/bazel/issues/13882.

mkdir a
cat > a/BUILD <<'EOF'
genrule(
name = "producer",
outs = ["a.txt", "b.txt"],
cmd = "touch $(OUTS)",
)

genrule(
name = "consumer",
outs = ["out.txt"],
srcs = [":b.txt", "in.txt"],
cmd = "cat $(SRCS) > $@",
)
EOF
echo 'foo' > a/in.txt

# download top level outputs with remote metadata
# populate the cache
bazel build \
--remote_cache=grpc://localhost:${worker_port} \
--remote_download_toplevel \
--verbose_failures \
//a:consumer >& $TEST_log || fail "Failed to populate the cache"

bazel clean >& $TEST_log || fail "Failed to clean"

# download top level outputs
bazel build \
--remote_cache=grpc://localhost:${worker_port} \
--remote_download_toplevel \
--experimental_action_cache_store_output_metadata \
--verbose_failures \
//a:consumer >& $TEST_log || fail "Failed to download outputs with remote metadata"
(! [[ -f bazel-bin/a/a.txt ]] && ! [[ -f bazel-bin/a/b.txt ]]) \
|| fail "Expected outputs of producer are not downloaded with remote metadata"
//a:consumer >& $TEST_log || fail "Failed to download outputs"
[[ -f bazel-bin/a/a.txt ]] || [[ -f bazel-bin/a/b.txt ]] \
&& fail "Expected outputs of producer are not downloaded"

# build without remote cache with remote metadata
# build without remote cache
echo 'bar' > a/in.txt
bazel build \
--remote_download_toplevel \
--experimental_action_cache_store_output_metadata \
--verbose_failures \
//a:consumer >& $TEST_log || fail "Failed to build without remote cache with remote metadata"
//a:consumer >& $TEST_log || fail "Failed to build without remote cache"
}

run_suite "Remote execution and remote cache tests"