From 69f33cf4384f3a04b11d97360df6d5efbd7d6db4 Mon Sep 17 00:00:00 2001 From: Chi Wawng Date: Mon, 8 Jan 2024 04:02:39 -0800 Subject: [PATCH] Close test.err before deleteing it Unfortuantely, there isn't an easy way to add integration test for this specific edge case on Windows. Fixes #20741. Closes #20752. PiperOrigin-RevId: 596547046 Change-Id: I4f517b161c03793329d5a4e21ec8ac4a5b53abb0 --- .../devtools/build/lib/exec/StandaloneTestStrategy.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java index 3e8ca341c80a2d..0a790408b4f159 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java @@ -808,9 +808,12 @@ private TestAttemptResult runTestAttempt( // Make sure that the test.log exists.Spaw FileSystemUtils.touchFile(fileOutErr.getOutputPath()); } + fileOutErr.close(); // Append any error output to the test.log. This is very rare. + // + // Only write after the error output stream has been closed. Otherwise, Bazel cannot delete + // test.err file on Windows. See https://github.com/bazelbuild/bazel/issues/20741. writeOutFile(fileOutErr.getErrorPath(), fileOutErr.getOutputPath()); - fileOutErr.close(); if (streamed != null) { streamed.close(); }