-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Fix tests lifecycle instance and methods annotated with AfterAll #26556
Conversation
This comment has been minimized.
This comment has been minimized.
The issue was not completely fixed in the commit quarkusio@b306d8a. The problem was that we were clearing out all the outer instances and hence the current class was not matching with the current test instance. Fix quarkusio#25812
Milestone is already set for some of the items: We haven't automatically updated the milestones for these items.
|
I still have to bisect to be sure, but I fear this has broken test isolation of some sort: |
Confirmed: When I revert this commit in the 2.10 branch then my tests don't fail anymore. |
AFAICS, the problem is that with the default |
A simple fix for that imminent problem is to add quarkus/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java Lines 778 to 780 in 380092c
But it feels weird to leave so many outer instances in the queue when |
Can confirm that |
@ivansenic can you put together a reproducer? Thanks! |
It's quite hard to create a reproducer. When running tests one-by-one, for example in the IDE, it all works.. When running all of them We have tests using different profiles. A list of errors, maybe you find something helpful. Again all of those work when invoked standalone:
|
The following hack works around the problem: import java.lang.reflect.Field;
import java.util.Collection;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusTestExtension;
/**
* Workaround for https://github.com/quarkusio/quarkus/pull/26556#issuecomment-1176798851 until proper fix is available.
*/
// This is not a QuarkusTestAfterAllCallback because the code must not run in a "Quarkus Runtime ClassLoader",
// we need the system CL (regular surefire) or deployment CL (continuous testing) instead.
public class QuarkusTestOuterInstancesWorkaround implements AfterAllCallback {
@Override
public void afterAll(final ExtensionContext context) throws Exception {
// after a toplevel QuarkusTest is done, make sure to clear outerInstances collection
// rationale: it might contain @Nested tests and will thus leak instances (as of 2.10.2.Final)
// note: checking for actual @Nested classes is not strictly required
if (context.getElement()
.filter(e -> e.isAnnotationPresent(QuarkusTest.class))
.isPresent()) {
try {
final Field field = QuarkusTestExtension.class.getDeclaredField("outerInstances");
field.setAccessible(true);
((Collection<?>) field.get(null)).clear();
} catch (final ReflectiveOperationException e) {
throw new IllegalStateException(e);
}
}
}
} (to be registered via Btw, in my case I'm also getting mock issues. I won't have much time to create a reproducer. |
This really makes a lot of sense. Will try to address this issue once I'm back from my sick leave days. |
@Sgitario oh, get well soon! Do you have an idea when that will be? No pressure, I'm just asking in case I find some time over the weekend. I tried to reproduce my problem by extending |
The issue was not completely fixed in the commit b306d8a.
The problem was that we were clearing out all the outer instances and hence the current class was not matching with the current test instance.
Fix #25812