-
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
Annotation classloading issue in custom JUnit extension when run in continuous testing #24257
Comments
/cc @stuartwdouglas |
@famod this appears to be fixed in main (but fails in 2.7.5.Final). I suppose #24440 fixed it. |
@aloubyansky well, I checked it with my real project while trying out #24440 and it wasn't fixed. I'll try again with current main. Maybe it's now fixed for the reproducer but not my real project (I hope not). |
Please do and see if you can adjust the reproducer for main. Thanks! |
I can confirm that it's fixed for the reproducer, but not for my real project. I'm somehow suspecting |
It's not |
Interesting: In my project where it fails (it doesn't fail everywhere!) there are two different deployment classloaders involved! Will try to dig deeper tomorrow, but in case you have an idea @aloubyansky please let me know! 🙂 |
One more detail: Right before the test failure there is a In that |
Managed to reproduce it, it was just a matter of adding a non-Quarkus test: q_ct-callback-ann_multi-2.zip |
I suppose the deployment classloaders mismatch is caused by the creation of a new deployment classloader during discovery of unit test classes: quarkus/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/JunitTestRunner.java Lines 667 to 671 in 619288d
|
I think I have a fix for this, stay tuned! |
@stuartwdouglas @aloubyansky I'm under the impression that unit tests must be run separately, with a separate |
|
@famod just tried your last reproducer from #24257 (comment). It fails with 2.7.5.Final but passes with 2.8.0.Final and the main branch. |
@aloubyansky hum, still fails for me with 2.8.0.Final and main (on two different machines):
|
Right. Not sure what happened. Just tried on another laptop and it fails. Sorry. |
No worries, thanks for checking! |
I wonder if this is also related to #27821? |
@holly-cummins thanks for the pointer! At first glance #27821 seems to be about testing in general, not just continuous testing, right? |
Describe the bug
A Junit extension, e.g. a
org.junit.jupiter.api.extension.BeforeEachCallback
, that is registered viasrc/test/resources/META-INF/services/org.junit.jupiter.api.extension.Extension
, cannot find a custom annotation that is present on a test method.context.getRequiredTestMethod().getAnnotationsByType(SomeAnnotation.class)
(context
beingorg.junit.jupiter.api.extension.ExtensionContext
) returns an empty array.OTOH,
context.getRequiredTestMethod().getAnnotations()
does contain the annotation. So it's there, but the type is loaded in two different classloaders:Via surefire (where everything is ok):
(CL1 is
SomeAnnotation.class.getClassLoader()
and CL2 isannotation.annotationType().getClassLoader()
)But in CT:
ℹ️ There is no issue when the extension is registered via
@ExtendWith(...)
!Expected behavior
Annotation is found in CT just like when run via surefire.
Actual behavior
Annotation is not found by type because two different classloaders are involved.
How to Reproduce?
q_ct-callback-ann_multi.zip
mvn clean install
✔️mvn quarkus:test -f dist
❌Note that this reproducer needs two modules because of #24229 and in reality,
core
produces atest-jar
but I wanted to take that out of the equation.Edit: Udpated reproducer is here: #24257 (comment)
Output of
uname -a
orver
No response
Output of
java -version
17.0.2, vendor: BellSoft
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.7.3.Final and 2.7.4.Final
Build tool (ie. output of
mvnw --version
orgradlew --version
)Apache Maven 3.8.4
Additional information
Reminds me a lot of #10623, but that was long before CT was invented.
The text was updated successfully, but these errors were encountered: