-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
TestWatcher
can no longer access data in ExtensionContext.Store
#3944
Comments
TestWatcher
can no longer access data in ExtensionContext.Store
Hi @joerg1985, Thanks for raising the issue. I have confirmed that the following all-in-one test class prints package example;
import example.TestWatcherTests.DemoTestWatcher;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.BeforeTestExecutionCallback;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
import org.junit.jupiter.api.extension.ExtensionContext.Store;
import org.junit.jupiter.api.extension.TestWatcher;
@ExtendWith(DemoTestWatcher.class)
class TestWatcherTests {
@Test
void test() {
}
static class DemoTestWatcher implements BeforeTestExecutionCallback, TestWatcher {
private static final Namespace NAMESPACE = Namespace.create(DemoTestWatcher.class);
@Override
public void beforeTestExecution(ExtensionContext context) throws Exception {
getStore(context).put("value", "enigma");
}
@Override
public void testSuccessful(ExtensionContext context) {
System.err.println("Value: " + getStore(context).get("value"));
}
private static Store getStore(ExtensionContext context) {
return context.getStore(NAMESPACE);
}
}
} We will discuss this within the team. |
As for why this happens,
|
One option to fix the regression would be to remove the Line 142 in 5f9eeb7
Line 159 in 5f9eeb7
That would effectively change the semantics of "closed" to "read-only". However, we'd still need to keep the In summary, I think we should either change the semantics of "closed" to "read-only" or revert #3614. Though, now that I think about it, the title of #3614 is " |
@leonard84, would changing the semantics of "closed" to "read-only" meet your needs (and original intent) as well? |
Team decision: Make it read-only by removing |
Since #3614 was introduced in 5.11, I've moved this to the |
Reopening to backport to the |
Changes made in conjunction with #3614 resulted in an exception being thrown if a NamespacedHierarchicalStore was queried after it had been closed. Consequently, TestWatcher callbacks were no longer able to access data in the Store. To fix that regression, this commit revises NamespacedHierarchicalStore so that it no longer throws an exception after it has been closed if the store is queried via one of the get(...) or getOrComputeIfAbsent(...) methods; however, if a getOrComputeIfAbsent(...) invocation results in the computation of a new value, an exception will still be thrown. In other words, when a NamespacedHierarchicalStore is closed, it now effectively switches to ready-only mode. See: #3614 Fixes: #3944 (cherry picked from commit 3e2cc6c)
Backported to |
@sbrannen thank you for taking care and fixing this issue! |
You're welcome, and thanks for bringing it to our attention. |
After upgrading from
5.10.2
to5.11.0
aorg.junit.jupiter.api.extension.TestWatcher
can no longer access store data. Instead, it now fails withorg.junit.jupiter.api.extension.ExtensionContextException: A NamespacedHierarchicalStore cannot be modified or queried after it has been closed
.In my mind the intention of the store is to allow extensions to attach data to the context, so this data should be accessible at least until all extensions related to the context are processed.
Steps to reproduce
Context
The text was updated successfully, but these errors were encountered: