Skip to content

Commit

Permalink
Download directory output for test actions (#18846)
Browse files Browse the repository at this point in the history
This is a dedicated fix for #17884 for 6.3.0.

Fixes #18845.
  • Loading branch information
coeuvre authored Jul 6, 2023
1 parent 601f909 commit 6fd3bc1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@
import com.google.devtools.build.lib.skyframe.TreeArtifactValue;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.Symlinks;
import com.google.devtools.build.skyframe.MemoizingEvaluator;
import com.google.devtools.build.skyframe.SkyValue;
import java.io.IOException;
import java.util.HashMap;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -117,6 +119,18 @@ public interface PathToMetadataConverter {
}

private void downloadTestOutput(Path path) {
if (path.isDirectory()) {
try {
var entries = path.readdir(Symlinks.FOLLOW);
for (var entry : entries) {
downloadTestOutput(path.getRelative(entry.getName()));
return;
}
} catch (IOException e) {
logger.atWarning().withCause(e).log("Failed to read dir %s.", path);
}
}

// Since the event is fired within action execution, the skyframe doesn't know the outputs of
// test actions yet, so we can't get their metadata through skyframe. However, the fileSystem
// of the path is an ActionFileSystem, we use it to get the metadata for this file.
Expand Down
25 changes: 25 additions & 0 deletions src/test/shell/bazel/remote/build_without_the_bytes_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,31 @@ EOF
expect_log "test.outputs_manifest__MANIFEST"
}

function test_nozip_undeclared_test_outputs() {
mkdir -p a
cat > a/test.sh << 'EOF'
#!/bin/sh
echo foo > "$TEST_UNDECLARED_OUTPUTS_DIR/text.txt"
EOF
chmod +x a/test.sh

cat > a/BUILD <<'EOF'
sh_test(
name = "foo",
srcs = ["test.sh"],
)
EOF

bazel test \
--remote_executor=grpc://localhost:${worker_port} \
--remote_download_toplevel \
--nozip_undeclared_test_outputs \
//a:foo || fail "Failed to test //a:foo"

[[ -e "bazel-testlogs/a/foo/test.outputs/text.txt" ]] || fail "bazel-testlogs/a/foo/test.outputs/text.txt does not exist"
assert_contains "foo" "bazel-testlogs/a/foo/test.outputs/text.txt"
}

function test_multiple_test_attempts() {
# Test that test logs of multiple test attempts can be renamed and reported by
# BEP.
Expand Down

0 comments on commit 6fd3bc1

Please sign in to comment.