Skip to content

Commit 4698bbc

Browse files
Upload undeclared outputs of failed/flaky/timed out tests (#2169)
Test failures can require information present in undeclared outputs to diagnose, which if not uploaded means needing to first reproduce the failure locally. e.g. https://buildkite.com/bazel/bazel-bazel-github-presubmit/builds/25623#0194aa2c-7bd9-466b-bd15-d7eec8ef58dc (failure in `test.log` references a file in `test.outputs`) from bazelbuild/bazel#25050 This PR adds uploading of `test.outputs/*` files for tests that fail/flake/timeout. It also; * Simplifies `local_exec_root.as_ref().map(|p| p.as_path()),` to `local_exec_root.as_deref(),` (clippy suggestion) * Lifts the upload decision (dubbed `include_output` in this PR) up a level so it can be used in the new code branch. I'm fairly `test.log` is a mandatory test output, so this change should not affect performance.
1 parent c2b610a commit 4698bbc

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

Diff for: agent/src/artifact/upload.rs

+35-5
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,16 @@ fn watch_bep_json_file(
126126
.map(|str| Path::new(str).to_path_buf());
127127
} else if build_event.is_test_result() {
128128
let test_result = build_event.test_result();
129+
let include_output = ["FAILED", "TIMEOUT", "FLAKY"]
130+
.contains(&test_result.status.as_str());
129131
for output in test_result.test_action_outputs.iter() {
130132
match output.name.as_str() {
131133
"test.log" => {
132-
if ["FAILED", "TIMEOUT", "FLAKY"]
133-
.contains(&test_result.status.as_str())
134-
{
134+
if include_output {
135135
if let Err(error) = upload_test_log(
136136
&mut uploader,
137137
dry,
138-
local_exec_root.as_ref().map(|p| p.as_path()),
138+
local_exec_root.as_deref(),
139139
&output.uri,
140140
mode,
141141
) {
@@ -148,7 +148,7 @@ fn watch_bep_json_file(
148148
if let Err(error) = upload_test_xml(
149149
&mut uploader,
150150
dry,
151-
local_exec_root.as_ref().map(|p| p.as_path()),
151+
local_exec_root.as_deref(),
152152
&output.uri,
153153
test_result.label.as_ref(),
154154
mode,
@@ -157,6 +157,19 @@ fn watch_bep_json_file(
157157
}
158158
}
159159
}
160+
n if n.starts_with("test.outputs/") => {
161+
if include_output {
162+
if let Err(error) = upload_test_output(
163+
&mut uploader,
164+
dry,
165+
local_exec_root.as_deref(),
166+
&output.uri,
167+
mode,
168+
) {
169+
error!("{:?}", error);
170+
}
171+
}
172+
}
160173
_ => {}
161174
}
162175
}
@@ -655,6 +668,23 @@ fn upload_test_xml(
655668
return uploader.upload_test_xml(dry, cwd.as_ref().map(|pb| pb.as_path()), &artifact, label);
656669
}
657670

671+
fn upload_test_output(
672+
uploader: &mut Uploader,
673+
dry: bool,
674+
local_exec_root: Option<&Path>,
675+
test_output: &str,
676+
mode: Mode,
677+
) -> Result<()> {
678+
let (cwd, artifact) = resolve_artifact(test_output, local_exec_root)?;
679+
return uploader.upload_artifact(
680+
dry,
681+
cwd.as_ref().map(|pb| pb.as_path()),
682+
&artifact,
683+
mode,
684+
None,
685+
);
686+
}
687+
658688
#[derive(Debug)]
659689
pub struct TestActionOutput {
660690
pub name: String,

Diff for: agent/tests/artifact/upload.rs

+18
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ fn test_logs_uploaded_to_buildkite() -> Result<()> {
4242
Ok(())
4343
}
4444

45+
#[cfg(not(target_os = "windows"))]
46+
#[test]
47+
fn test_undeclared_output_uploaded_to_buildkite() -> Result<()> {
48+
let mut cmd = Command::cargo_bin("bazelci-agent")?;
49+
cmd.args([
50+
"artifact",
51+
"upload",
52+
"--dry",
53+
"--mode=buildkite",
54+
"--build_event_json_file=tests/data/test_bep_undeclared_output.json",
55+
]);
56+
cmd.assert()
57+
.success()
58+
.stdout(predicates::str::contains("buildkite-agent artifact upload src/test/shell/bazel/tags_propagation_native_test/test_attempts/attempt_1.outputs/test_cc_library_tags_not_propagated_when_incompatible_flag_off/741B943E-B846-4453-A3AF-0D9010431815/output1\n"));
59+
60+
Ok(())
61+
}
62+
4563
fn with_tmpfile<F>(f: F) -> Result<()>
4664
where
4765
F: Fn(File, &Path) -> Result<()>,

Diff for: agent/tests/data/test_bep_undeclared_output.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{"id":{"workspace":{}},"workspaceInfo":{"localExecRoot":"/private/var/tmp/_bazel_buildkite/39eb3a0c7f548273ec33e4a77eb36882/execroot/_main"}}
2+
{"id":{"testResult":{"label":"//src/test/shell/bazel:tags_propagation_native_test","run":1,"shard":1,"attempt":1,"configuration":{"id":"65571a9c3d56c8ba36ef27c072426c3096c8925f94bc60c163904cd36caf68b9"}}},"children":[{"testResult":{"label":"//src/test/shell/bazel:tags_propagation_native_test","run":1,"shard":1,"attempt":2,"configuration":{"id":"65571a9c3d56c8ba36ef27c072426c3096c8925f94bc60c163904cd36caf68b9"}}}],"testResult":{"testActionOutput":[{"name":"test.log","uri":"file:///private/var/tmp/_bazel_buildkite/39eb3a0c7f548273ec33e4a77eb36882/execroot/_main/bazel-out/darwin_arm64-fastbuild/testlogs/src/test/shell/bazel/tags_propagation_native_test/test_attempts/attempt_1.log"},{"name":"test.xml","uri":"file:///private/var/tmp/_bazel_buildkite/39eb3a0c7f548273ec33e4a77eb36882/execroot/_main/bazel-out/darwin_arm64-fastbuild/testlogs/src/test/shell/bazel/tags_propagation_native_test/test_attempts/attempt_1.xml"},{"name":"test.outputs/test_cc_library_tags_not_propagated_when_incompatible_flag_off/741B943E-B846-4453-A3AF-0D9010431815/output1","uri":"file:///private/var/tmp/_bazel_buildkite/39eb3a0c7f548273ec33e4a77eb36882/execroot/_main/bazel-out/darwin_arm64-fastbuild/testlogs/src/test/shell/bazel/tags_propagation_native_test/test_attempts/attempt_1.outputs/test_cc_library_tags_not_propagated_when_incompatible_flag_off/741B943E-B846-4453-A3AF-0D9010431815/output1"},{"name":"test.outputs_manifest__MANIFEST","uri":"file:///private/var/tmp/_bazel_buildkite/39eb3a0c7f548273ec33e4a77eb36882/execroot/_main/bazel-out/darwin_arm64-fastbuild/testlogs/src/test/shell/bazel/tags_propagation_native_test/test_attempts/attempt_1.outputs_manifest/MANIFEST"}],"testAttemptDurationMillis":"38056","status":"FAILED","testAttemptStartMillisEpoch":"1738022034867","executionInfo":{"strategy":"darwin-sandbox","timingBreakdown":{"child":[{"name":"parseTime","time":"0s"},{"name":"fetchTime","time":"0s"},{"name":"queueTime","time":"0s"},{"name":"uploadTime","time":"0s"},{"name":"setupTime","time":"0s"},{"name":"executionWallTime","time":"38.056s"},{"name":"processOutputsTime","time":"0s"},{"name":"networkTime","time":"0s"}],"name":"totalTime","time":"38.056s"}},"testAttemptStart":"2025-01-27T23:53:54.867Z","testAttemptDuration":"38.056s"}}
3+
{"id":{"testSummary":{"label":"//src/test/shell/bazel:tags_propagation_native_test","configuration":{"id":"65571a9c3d56c8ba36ef27c072426c3096c8925f94bc60c163904cd36caf68b9"}}},"testSummary":{"totalRunCount":3,"failed":[{"uri":"file:///private/var/tmp/_bazel_buildkite/39eb3a0c7f548273ec33e4a77eb36882/execroot/_main/bazel-out/darwin_arm64-fastbuild/testlogs/src/test/shell/bazel/tags_propagation_native_test/test_attempts/attempt_1.log"}],"overallStatus":"FAILED","firstStartTimeMillis":"1738022104632","lastStopTimeMillis":"1738022135626","totalRunDurationMillis":"30994","runCount":1,"totalRunDuration":"30.994s","firstStartTime":"2025-01-27T23:55:04.632Z","lastStopTime":"2025-01-27T23:55:35.626Z","attemptCount":3}}
4+
{"id":{"progress":{}},"progress":{},"lastMessage":true}

0 commit comments

Comments
 (0)