From 1832feef36e3a6143443ce67102a36d43dd1326d Mon Sep 17 00:00:00 2001 From: Son Luong Ngoc Date: Wed, 6 Jul 2022 18:23:59 +0200 Subject: [PATCH] RemoteExecutionService: fix outputs not being uploaded In 4d900ceea12919ad62012830a95e51f9ec1a48bb we introduced validation in DiskAndRemoteCacheClient.uploadActionResult() where context's step must be UPLOAD_OUTPUTS to trigger the upload. However, this value was never set in RemoteExecutionService before hand thus led to outputs not being uploaded and cause remote cache misses. Fix #15682 --- .../lib/remote/RemoteExecutionService.java | 2 ++ .../bazel/remote/remote_execution_test.sh | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionService.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionService.java index 27132d528c1961..f8c7136388c2b7 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionService.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionService.java @@ -1196,6 +1196,8 @@ public void uploadOutputs(RemoteAction action, SpawnResult spawnResult) SpawnResult.Status.SUCCESS.equals(spawnResult.status()) && spawnResult.exitCode() == 0, "shouldn't upload outputs of failed local action"); + action.getRemoteActionExecutionContext().setStep(Step.UPLOAD_OUTPUTS); + if (remoteOptions.remoteCacheAsync) { Single.using( remoteCache::retain, diff --git a/src/test/shell/bazel/remote/remote_execution_test.sh b/src/test/shell/bazel/remote/remote_execution_test.sh index 854d866a75cefe..adfe984507734f 100755 --- a/src/test/shell/bazel/remote/remote_execution_test.sh +++ b/src/test/shell/bazel/remote/remote_execution_test.sh @@ -1056,6 +1056,33 @@ EOF expect_not_log "remote cache hit" } +function test_remote_cache_upload() { + mkdir -p a + echo 'bar' > a/bar + cat > a/BUILD <<'EOF' +genrule( + name = "foo", + srcs = [":bar"], + outs = ["foo.txt"], + cmd = """ + echo $(location :bar) > "$@" + """, +) +EOF + + CACHEDIR=$(mktemp -d) + + bazel build \ + --disk_cache=$CACHEDIR \ + --remote_cache=grpc://localhost:${worker_port} \ + //a:foo >& $TEST_log || "Failed to build //a:foo" + + remote_ac_files="$(count_remote_ac_files)" + [[ "$remote_ac_files" == 1 ]] || fail "Expected 1 remote action cache entries, not $remote_ac_files" + remote_cas_files="$(count_remote_cas_files)" + [[ "$remote_cas_files" == 3 ]] || fail "Expected 3 remote cas entries, not $remote_cas_files" +} + function test_tag_no_remote_cache_upload() { mkdir -p a cat > a/BUILD <<'EOF'