Skip to content

Defer XML output file creation to avoid premature file generation #331

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

Merged
merged 1 commit into from
Mar 24, 2025

Conversation

amishra-u
Copy link
Contributor

Issue

The test runner creates an empty XML file when it terminates unexpectedly, such as when the JVM shuts down before the listener has a chance to write any output. The existing premature file creation interferes with Bazel’s fallback mechanism, which generates the XML file from test.log only if the output file is missing.

Solution

Use LazyFileWriter to delay file creation until the first write operation. This ensures that no empty file is created if the JVM shuts down before any content is written. If no output is generated, Bazel's fallback logic can correctly generate the XML file from test.log, as it only activates when the output file does not already exist.

Copy link
Collaborator

@shs96c shs96c left a comment

Choose a reason for hiding this comment

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

This isn't thread-safe, but I don't think it needs to be. LGTM. Thank you for the PR!

@shs96c shs96c merged commit 8436a42 into bazel-contrib:main Mar 24, 2025
7 checks passed
@amishra-u amishra-u deleted the lazy_file_writer branch March 27, 2025 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants