-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Close contexts when clearing test context cache #36825
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,6 +81,42 @@ void maxCacheSizeZero() { | |
| assertThatIllegalArgumentException().isThrownBy(() -> new DefaultContextCache(0)); | ||
| } | ||
|
|
||
| @Test | ||
| void clearClosesContexts() { | ||
| DefaultContextCache cache = new DefaultContextCache(4); | ||
|
|
||
| cache.put(fooConfig, key -> fooContext); | ||
| cache.put(barConfig, key -> barContext); | ||
| cache.put(bazConfig, key -> bazContext); | ||
| assertCacheContents(cache, "Foo", "Bar", "Baz"); | ||
|
|
||
| cache.clear(); | ||
| assertCacheContents(cache); | ||
|
|
||
| verify(fooContext, times(1)).close(); | ||
| verify(barContext, times(1)).close(); | ||
| verify(bazContext, times(1)).close(); | ||
| verify(abcContext, never()).close(); | ||
| } | ||
|
|
||
| @Test | ||
| void resetClosesContexts() { | ||
| DefaultContextCache cache = new DefaultContextCache(4); | ||
|
|
||
| cache.put(fooConfig, key -> fooContext); | ||
| cache.put(barConfig, key -> barContext); | ||
| cache.get(fooConfig); | ||
| assertThat(cache.getHitCount()).isEqualTo(1); | ||
| assertCacheContents(cache, "Bar", "Foo"); | ||
|
|
||
| cache.reset(); | ||
| assertCacheContents(cache); | ||
| assertThat(cache.getHitCount()).isZero(); | ||
|
|
||
| verify(fooContext, times(1)).close(); | ||
| verify(barContext, times(1)).close(); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a couple of things I'd like addressed on the test side before merging:
This would give us a real regression guard on these new code paths, rather than only checking that the mock contexts were closed. As side note, I think using However, |
||
|
|
||
|
|
||
| @Nested | ||
| @SuppressWarnings("deprecation") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After this new loop, the four subsequent calls to
this.contextMap.clear(),this.hierarchyMap.clear(),this.contextUsageMap.clear(), andthis.unusedContexts.clear()are now redundant: the loop's calls toremove()should already empty all four as an invariant, since every key in the pre-loop snapshot ends up removed either directly or as a descendant.Could you please remove those
clear()calls and ensure the tests cover those invariants (see other comment regarding tests)?