Ignore NoSuchFileException in @TempDir cleanup#3667
Merged
marcphilipp merged 2 commits intojunit-team:mainfrom Apr 16, 2024
Merged
Ignore NoSuchFileException in @TempDir cleanup#3667marcphilipp merged 2 commits intojunit-team:mainfrom
NoSuchFileException in @TempDir cleanup#3667marcphilipp merged 2 commits intojunit-team:mainfrom
Conversation
NoSuchFileException in TempDirectory cleanup
NoSuchFileException in TempDirectory cleanupNoSuchFileException in @TempDir cleanup
While walking the temp directory, the file walker may fail to visit a file that has been removed by another thread or process. In this case, JUnit should ignore the NoSuchFileException, because there's nothing to clean-up.
Add NoSuchFileException suppression to release notes.
a90e282 to
ed397b4
Compare
marcphilipp
approved these changes
Apr 16, 2024
Member
Given that such a test would likely be flaky I don't think adding it would be justified. I'd be okay with making an exception in this case. |
NoSuchFileException in @TempDir cleanupNoSuchFileException in TempDir cleanup
Member
|
@gilday Thank you for your contribution! 👍 |
NoSuchFileException in TempDir cleanupNoSuchFileException in @TempDir cleanup
8 tasks
marcphilipp
pushed a commit
that referenced
this pull request
Jun 17, 2024
While walking the temp directory, the file walker may fail to visit a file that has been removed by another thread or process. In this case, JUnit should ignore the NoSuchFileException, because there's nothing to clean up. (cherry picked from commit 6dbc84e)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
In
TempDirectory's cleanup logic, while walking the temp directory, the file walker may fail to visit a file that has been removed by another thread or process. In this case, JUnit should ignore theNoSuchFileException, because there's nothing to clean up.I have observed such failures when using JGit to manage repositories in temporary directories. JGit uses lock files that it cleans up in background threads. JGit and JUnit will race to delete the lock file, and the JUnit
TempDirectorycleanup fails when JGit wins that race.I considered what an automated test for this new behavior would look like. I could add a clear-box test that uses high-level concurrency objects to make sure that the test can delete a file between the time that the
SimpleFileVisitorlists the temp directory and the time that theSimpleFileVisitorattempts to delete the file, but this would require adding new seams toTempDirectorythat are inconsistent with the existing tests for that type. Would you accept this change without adding new test coverage?I hereby agree to the terms of the JUnit Contributor License Agreement.
Definition of Done
@APIannotations