Skip to content
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

Feature/temp dir cleanup #2729

Merged
merged 57 commits into from Nov 29, 2021
Merged

Feature/temp dir cleanup #2729

merged 57 commits into from Nov 29, 2021

Conversation

ghost
Copy link

@ghost ghost commented Sep 26, 2021

Overview

Addressing issue #2159 .

This PR adds a TempDirStrategy annotation for managing TempDirs. The annotation has a single CleanupMode enum field that can have a value of ALWAYS or NEVER. If the field is NEVER, then a test class's TempDirs are not cleaned up after the test completes. The annotation also works on nested classes, and a config parameter for the default cleanup mode has been added. Unit tests, demo and documentation included.

The issue discussion included the idea of an 'on_success' mode, but I have been unable to work out how to achieve this. Happy to discuss ideas on how this might be done.


I hereby agree to the terms of the JUnit Contributor License Agreement.


Definition of Done

@codecov
Copy link

codecov bot commented Sep 26, 2021

Codecov Report

Merging #2729 (85493ee) into main (c997035) will increase coverage by 91.07%.
The diff coverage is 90.69%.

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #2729       +/-   ##
===========================================
+ Coverage        0   91.07%   +91.07%     
- Complexity      0     4476     +4476     
===========================================
  Files           0      385      +385     
  Lines           0    10846    +10846     
  Branches        0      845      +845     
===========================================
+ Hits            0     9878     +9878     
- Misses          0      744      +744     
- Partials        0      224      +224     
Impacted Files Coverage Δ
.../junit/jupiter/engine/extension/TempDirectory.java 72.09% <87.09%> (ø)
...ain/java/org/junit/jupiter/api/io/CleanupMode.java 100.00% <100.00%> (ø)
...ter/engine/config/CachingJupiterConfiguration.java 100.00% <100.00%> (ø)
...ter/engine/config/DefaultJupiterConfiguration.java 100.00% <100.00%> (ø)
...ter/engine/extension/MutableExtensionRegistry.java 100.00% <100.00%> (ø)
...r/engine/discovery/DefaultClassOrdererContext.java 100.00% <0.00%> (ø)
.../platform/engine/support/descriptor/UriSource.java 81.81% <0.00%> (ø)
...r/engine/execution/InvocationInterceptorChain.java 90.38% <0.00%> (ø)
...org/junit/platform/commons/util/Preconditions.java 91.66% <0.00%> (ø)
...overy/DefensiveAllDefaultPossibilitiesBuilder.java 100.00% <0.00%> (ø)
... and 379 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c997035...85493ee. Read the comment docs.

@marcphilipp
Copy link
Member

@hglasgow Sorry for the wait!

The issue discussion included the idea of an 'on_success' mode, but I have been unable to work out how to achieve this. Happy to discuss ideas on how this might be done.

I think we should be able to pass the ExtensionContext to CloseablePath when it's created and check if ExtensionContext.getExecutionException is empty or contains an instance of TestAbortedException.

@ghost
Copy link
Author

ghost commented Nov 19, 2021

All done, ready for review.

@ghost ghost marked this pull request as ready for review November 19, 2021 23:06
Copy link
Member

@marcphilipp marcphilipp left a comment

Choose a reason for hiding this comment

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

Thanks! I found one additional minor thing.

@AfterAll
static void afterAll() {
if (defaultParameterDir != null && defaultParameterDir.exists()) {
defaultParameterDir.delete();
Copy link
Member

Choose a reason for hiding this comment

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

File.delete returns a false if the file wasn't deleted for some reason. Instead, I think we should use Files.deleteIfExists (and Path in the test cases) which only returns false if the file didn't exists and throws an exception if there was a problem deleting it.

Copy link
Author

Choose a reason for hiding this comment

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

Okay, that's done.

Copy link
Author

Choose a reason for hiding this comment

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

Ready for review

Copy link
Member

@marcphilipp marcphilipp left a comment

Choose a reason for hiding this comment

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

Thanks! 👍

@marcphilipp marcphilipp merged commit 3e06d8f into junit-team:main Nov 29, 2021
@marcphilipp marcphilipp linked an issue Nov 29, 2021 that may be closed by this pull request
sbrannen added a commit that referenced this pull request Dec 31, 2021
- Use correct versions in @SInCE tags and @API declarations
- Add missing @SInCE tags and @API declarations
- Add missing Javadoc
- Fix configuration parameter name for default cleanup mode
- Clarify meaning of DEFAULT cleanup mode
- Improve Javadoc
- Polish tests

See #2729
sbrannen added a commit that referenced this pull request Dec 31, 2021
sbrannen added a commit that referenced this pull request Dec 31, 2021
Prior to this commit, a custom default cleanup mode was ignored when
determining the cleanup mode for a parameter annotated with @tempdir.

See #2729
runningcode pushed a commit to runningcode/junit5 that referenced this pull request Feb 15, 2023
This PR adds a cleanup mode (`ALWAYS` (default), `ON_SUCCESS`, or
`NEVER`) parameter to `@TempDir` that allows to configured when the
temp directory should be deleted. The default can be configured by
setting a configuration parameter.

Resolves junit-team#2159.

Co-authored-by: Marc Philipp <mail@marcphilipp.de>
runningcode pushed a commit to runningcode/junit5 that referenced this pull request Feb 15, 2023
- Use correct versions in @SInCE tags and @API declarations
- Add missing @SInCE tags and @API declarations
- Add missing Javadoc
- Fix configuration parameter name for default cleanup mode
- Clarify meaning of DEFAULT cleanup mode
- Improve Javadoc
- Polish tests

See junit-team#2729
runningcode pushed a commit to runningcode/junit5 that referenced this pull request Feb 15, 2023
runningcode pushed a commit to runningcode/junit5 that referenced this pull request Feb 15, 2023
Prior to this commit, a custom default cleanup mode was ignored when
determining the cleanup mode for a parameter annotated with @tempdir.

See junit-team#2729
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support disabling cleanup for @TempDir
2 participants