-
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
Change default behavior of @WithTestResource
#42852
Conversation
07c1585
to
b5ff28f
Compare
@WithTestResource
This comment has been minimized.
This comment has been minimized.
The failure in Quickstart compilation is expected |
@geoand you mention consecutive tests. Is there an effort to group tests with the same annotation together ? |
Quarkus already does that by implementing the appropriate JUnit API. |
It's done here: Lines 141 to 145 in dcd9928
|
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.
LGTM
test-framework/common/src/main/java/io/quarkus/test/common/WithTestResource.java
Outdated
Show resolved
Hide resolved
test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java
Show resolved
Hide resolved
test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java
Show resolved
Hide resolved
@@ -13,11 +13,20 @@ | |||
/** | |||
* Used to define a test resource, which can affect various aspects of the application lifecycle. | |||
* <p> | |||
* As of Quarkus 3.16, the default behavior of the annotation (meaning that {@code scope} has not been set) | |||
* is that test classes annotated with same {@code WithTestResource} will <strong>not</strong> force a restart | |||
* of Quarkus. |
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.
Maybe I'm blind but while I see the code to order the restricted to class first, I'm not exactly sure how the tests with the same resources are actually grouped?
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.
Are you talking about QuarkusTestProfileAwareClassOrderer
? I haven't changed that
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.
Yes I'm talking about this specific class. I think someone said it was ordering classes depending on resources and I don't see that in the code. I just see some grouping by if they have per-class test resources.
Don't we want to group classes which have similar test resources?
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.
I can look into this in a follow up (or maybe @famod can since he wrote the ordering code).
For the time being, I would like to get this if we agree it's the proper functionality as the change has a very high chance of conflicting with any changes made in test handling code.
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.
I don't see that in the code
At a first glimpse I don't see that either. 🤔 It is has been a while, so I'd need some time to look into it.
Until when do we need that adjustment (if needed after all)?
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.
It is has been a while, so I'd need some time to look into it. Until when do we need that adjustment (if needed after all)?
As this PR is breaking and meant to go into 3.16
, we still have a weeks
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.
Btw, @QuarkusComponentTest isn't covered either but I haven't looked into whether grouping such tests would make sense at all.
Yeah, it probably makes sense to have those executed at the beginning or the end of the run, but that's definitely something for after this PR is in.
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.
Btw, @QuarkusComponentTest isn't covered either but I haven't looked into whether grouping such tests would make sense at all.
Given they are supposed to be faster and lower level, let's execute them first.
But yes, definitely out of the scope for this PR.
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.
FYI, I haven't had the time to take a stab at the QuarkusTestProfileAwareClassOrderer change. I might have some time for that by the end of next week.
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.
🙏🏽
This is a prerequisite of fixing the behavior of `@WithTestResource`
8bcffd7
to
91c009e
Compare
The new default @WithTestResource behavior is for Quarkus to NOT restart when consecutive tests are using the same @WithTestResource annotations.
91c009e
to
12fe9e0
Compare
Status for workflow
|
Status | Name | Step | Failures | Logs | Raw logs | Build scan |
---|---|---|---|---|---|---|
✖ | Quickstarts Compilation - JDK 17 | Compile Quickstarts |
Failures | Logs | Raw logs | 🚧 |
You can consult the Develocity build scans.
Failures
⚙️ Quickstarts Compilation - JDK 17 #
- Failing: optaplanner-quickstart
📦 optaplanner-quickstart
✖ Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:testCompile (default-testCompile) on project optaplanner-quickstart: Compilation failure
/home/runner/work/quarkus/quarkus/quarkus-quickstarts/optaplanner-quickstart/src/test/java/org/acme/optaplanner/TestResources.java:[6,57] cannot find symbol
symbol: method restrictToAnnotatedClass()
location: @interface io.quarkus.test.common.WithTestResource
Flaky tests - Develocity
⚙️ JVM Tests - JDK 21
📦 extensions/resteasy-reactive/rest-client/deployment
✖ io.quarkus.rest.client.reactive.stork.StorkResponseTimeLoadBalancerTest.shouldUseFasterService
- History
expected: "hello, Alice" but was: "hello, I'm a slow server"
-org.opentest4j.AssertionFailedError
org.opentest4j.AssertionFailedError:
expected: "hello, Alice"
but was: "hello, I'm a slow server"
at io.quarkus.rest.client.reactive.stork.StorkResponseTimeLoadBalancerTest.shouldUseFasterService(StorkResponseTimeLoadBalancerTest.java:58)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at io.quarkus.test.QuarkusUnitTest.runExtensionMethod(QuarkusUnitTest.java:499)
at io.quarkus.test.QuarkusUnitTest.interceptTestMethod(QuarkusUnitTest.java:413)
Assuming this is the right track, what would be your doc describing the isolation and how to isolate / not isolate and why? For mere humans :D With this "doc as spec", we will move the user experience up a notch. Thoughts? |
That's a good question... I am pretty sure it would need a few iterations to be made clear for all people |
The way I envision it: Global: applies to all tests and thus doesn't make a difference when it comes to restarting Quarkus |
*/ | ||
RESTRICTED_TO_CLASS, | ||
/** | ||
* Means that Quarkus will not restart when running consecutive tests that use the same resource |
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.
The same resource or the same set of resources? If the former how do you group to restart the resources less often?
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.
Users can't really influence the order of test execution, but if Quarkus does its job correctly, restarting will be minimized
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.
How? (for my benefit).
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.
We might need to update it a little, but the idea is that we can tell JUnit the order with which tests can be executed
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.
Also my question was
@WithTestResource(value={Resource1.class, Resource2.class, Resource3.class})
will it run in the same batch as @WithTestResource(value={Resource3.class})
what about @WithTestResource(value={Resource3.class, Resource4.class})
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.
Even if those are executed one after the other, they still force a restart because they don't match
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.
ok, thanks. So i'ts not the same resource that matches, it's the exact resource set (or list of resoruces) that matches.
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.
Correct!
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.
Let's merge this as it's going to be very prone to conflicts and let's iterate during the 3.16 development cycle.
Thanks! |
Watching with sadness, as I see the non-trivial conflicts mounting up with #34681. 🫣 Serves me right for going slow. 😆 |
@holly-cummins do you need help with that one? FWIW, the code should be simpler to follow now, but a conflict is a conflict no doubt :( |
Yeah, that's a very good idea! |
#42471 (comment) is a good indication things are much better now :) |
FWIW, this breaking change is not mentioned in https://github.com/quarkusio/quarkus/wiki/Migration-Guide-3.16 |
Hopefully no one was using the old one :) |
The new default
@WithTestResource
behavior isfor Quarkus to NOT restart when consecutive tests
are using the same
@WithTestResource
annotations.Despite the first first commit being a refactor and not a behavior change,
it is where the heavy lifting is done (while hopefully making the code clearer to read).
The second commit which brings the change just takes the structure put in place
by the previous one and changes the default.
P.S. For now, I only have the refactoring code in this PR, which I want to test against CI as it should not include any behavior change