Skip to content
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

chore: reduce time spent in Quarkus tests #1076

Merged
merged 2 commits into from
Jan 8, 2025

Conversation

gsmet
Copy link
Contributor

@gsmet gsmet commented Dec 23, 2024

This is a follow up of Marek asking for help here: https://quarkusio.zulipchat.com/#narrow/channel/187030-users/topic/.40QuarkusTest.20best.20practices.20.28multiple.20tests.2C.20slowness.29

From the first commit comment (the second one is just going a step further):

Some background: Quarkus is restarted whenever a test resource is
restricted to the class or different from the ones from other tests and
also when the test profile is different.

There is a clever orderer in Quarkus that tries to order things cleverly
to minimize the number of restarts but... ITs and Failsafe are not
honoring the JUnit test orderer so you lose this benefit and you end up
with Quarkus being restarted a lot more often than strictly necessary.

So the first fix here is to consider the Quarkus tests as Surefire
tests, not failsafe tests.
If more practical for you, they can be isolated in a specific Surefire
execution but we should keep them executed with Surefire.

Second issue is that @WithKubernetesTestServer is restricted to a given
test clean, meaning every time you have this annotation, the server will
have to be restarted.
I will start discussions to see if we should change that but in the
meantime I added an annotation that has a less aggressive behavior.

Unfortunately, you are also affected by a Quarkus bug, for which I will
push a fix soon and that we will hopefully backport to the next 3.17.

Combined with quarkusio/quarkus#45253 , I was able to reduce the time spent in service module testing from 4mn30 to 1m45 and it should scale a lot better if you don't multiply the combination of resources + test profiles.

There's one VERY important caveat though: the Kubernetes mock is shared with all the tests so you need to have this limitation in mind. Marek told me that was acceptable so here we are.

gsmet added a commit to gsmet/sbomer that referenced this pull request Dec 23, 2024
While I agree you should stay compatible with the minor request by the
Operator SDK extension, I don't think it's a good idea to stay on the
micro as you are missing all the fixes we are pushing since at the
moment the version used here is 3.17.0.

So my advice is: update to the latest micro of the minor branch
requested for the Operator SDK.

This is important for project-ncl#1076 as otherwise, you will have to wait a lot
longer to get the fix. Also it's good practice in general.
gsmet added a commit to gsmet/sbomer that referenced this pull request Dec 23, 2024
While I agree you should stay compatible with the minor request by the
Operator SDK extension, I don't think it's a good idea to stay on the
micro as you are missing all the fixes we are pushing since at the
moment the version used here is 3.17.0.

So my advice is: update to the latest micro of the minor branch
requested for the Operator SDK.

This is important for project-ncl#1076 as otherwise, you will have to wait a lot
longer to get the fix. Also it's good practice in general.
gsmet added a commit to gsmet/sbomer that referenced this pull request Dec 23, 2024
While I agree you should stay compatible with the minor requested by the
Operator SDK extension, I don't think it's a good idea to stay on the
micro as you are missing all the fixes we are pushing since at the
moment the version used here is 3.17.0.

So my advice is: update to the latest micro of the minor branch
requested for the Operator SDK.

This is important for project-ncl#1076 as otherwise, you will have to wait a lot
longer to get the fix. Also it's good practice in general.
@gsmet
Copy link
Contributor Author

gsmet commented Dec 23, 2024

FWIW I also created fabric8io/kubernetes-client#6750 . I worked around the issue but it would be nice to have a proper fix.

@gsmet gsmet changed the title Reduce time spent in Quarkus tests chore: reduce time spent in Quarkus tests Dec 24, 2024
gsmet added a commit to gsmet/sbomer that referenced this pull request Dec 24, 2024
While I agree you should stay compatible with the minor requested by the
Operator SDK extension, I don't think it's a good idea to stay on the
micro as you are missing all the fixes we are pushing since at the
moment the version used here is 3.17.0.

So my advice is: update to the latest micro of the minor branch
requested for the Operator SDK.

This is important for project-ncl#1076 as otherwise, you will have to wait a lot
longer to get the fix. Also it's good practice in general.
Some background: Quarkus is restarted whenever a test resource is
restricted to the class or different from the ones from other tests and
also when the test profile is different.

There is a clever orderer in Quarkus that tries to order things cleverly
to minimize the number of restarts but... ITs and Failsafe are not
honoring the JUnit test orderer so you lose this benefit and you end up
with Quarkus being restarted a lot more often than strictly necessary.

So the first fix here is to consider the Quarkus tests as Surefire
tests, not failsafe tests.
If more practical for you, they can be isolated in a specific Surefire
execution but we should keep them executed with Surefire.

Second issue is that @WithKubernetesTestServer is restricted to a given
test clean, meaning every time you have this annotation, the server will
have to be restarted.
I will start discussions to see if we should change that but in the
meantime I added an annotation that has a less aggressive behavior.

Unfortunately, you are also affected by a Quarkus bug, for which I will
push a fix soon and that we will hopefully backport to the next 3.17.
That means that the tests are not isolated from this POV but Marek was
saying this would be OK.
@gsmet gsmet force-pushed the improve-unit-testing branch from 27b405f to c54a484 Compare December 24, 2024 07:50
assertNull(mockServer.getLastRequest());
// there is no proper way to reset the last request at the beginning of the method
// so let's just compare it's the same as before and no requests have been executed.
assertSame(lastRequestPriorToExecution, mockServer.getLastRequest());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created fabric8io/kubernetes-client#6750 for that.

goldmann pushed a commit that referenced this pull request Jan 8, 2025
While I agree you should stay compatible with the minor requested by the
Operator SDK extension, I don't think it's a good idea to stay on the
micro as you are missing all the fixes we are pushing since at the
moment the version used here is 3.17.0.

So my advice is: update to the latest micro of the minor branch
requested for the Operator SDK.

This is important for #1076 as otherwise, you will have to wait a lot
longer to get the fix. Also it's good practice in general.
@gsmet
Copy link
Contributor Author

gsmet commented Jan 8, 2025

FYI, I'm currently releasing Quarkus 3.17.6 that will come with the Quarkus fix that should improve things for you even more with this patch. I'll include the upgrade in this PR if not merged by then.

@goldmann
Copy link
Contributor

goldmann commented Jan 8, 2025

Thanks for heads-up! I actually plan to merge this one now. I can do the Quarkus upgrade myself once it becomes available, or, if you are so kind, you could create a new PR. Hope this works for you.

@gsmet Thanks for the support!

@gsmet
Copy link
Contributor Author

gsmet commented Jan 8, 2025

Works for me, I'll create a PR once 3.17.6 has been released.

@goldmann goldmann merged commit 317ce69 into project-ncl:main Jan 8, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants