Skip to content

Conversation

@geoand
Copy link
Contributor

@geoand geoand commented Jun 22, 2020

Without this PR the TestResourceManager gets closed 3 times,
which is causing some issues with new surefire versions

Relates to: #10081

@geoand
Copy link
Contributor Author

geoand commented Jun 22, 2020

@pedroigor @sberyozkin @stuartwdouglas This PR although seems reasonable to me, seems to be failing on the Keycloack tests...

What happens is that it seems that for some reason the Keycloak related QuarkusTestResourceLifecycleManager classes don't get closed properly.
Is there anything I need to know about these classes? Just looking at their source I don't see why they would fail to close.

FWIW, all other QuarkusTestResourceLifecycleManager classes seem to work fine with this PR

@geoand
Copy link
Contributor Author

geoand commented Jun 22, 2020

The easiest way to see the problem is to run mvn clean verify -Dnative -Dtest-keycloak -Ddocker for the keycloack-authorization integration test

@pedroigor
Copy link
Contributor

pedroigor commented Jun 22, 2020

@geoand Looks like a CL issue. When invoking the testResourceManager#close from ExtensionState#close, the class loader is the launcher class loader. If you perform the same call but on the runtime class loader, it works fine.

When using the launcher class loader, you get a NoSuchMethodException when the method KeycloakTestResource.stop is invoked.

That is also why that method runs fine when you get a failure (the stop method is invoked on the runtime class loader) so that a test only works after either the Keycloak server is not yet with any data or only after a failure.

@pedroigor
Copy link
Contributor

@geoand Not sure if this is the best fix, but here is https://github.com/pedroigor/quarkus/tree/testresource-close-classloader. With that change I'm able to run mvn clean verify -Dnative -Dtest-keycloak on keycloak-authorization IT module.

@geoand
Copy link
Contributor Author

geoand commented Jun 22, 2020

Excellent information @pedroigor! I'll take another look tomorrow

Without this PR the TestResourceManager gets closed 3 times,
which is causing some issues with new surefire versions

Relates to: quarkusio#10081
@geoand geoand force-pushed the testsource-close branch from 3a6b5c4 to 25c7a2a Compare June 22, 2020 18:41
@geoand
Copy link
Contributor Author

geoand commented Jun 22, 2020

PR should be good now, but I'll leave it in Draft to make sure that the tests pass on my fork

}

class ExtensionState implements ExtensionContext.Store.CloseableResource {
class ExtensionState {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

By removing the interface, we ensure that JUnit does not attempt to close this, because we are closing it ourselved

Copy link
Collaborator

Choose a reason for hiding this comment

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

How is this being shutdown then? By the shutdown hook?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. When we let Junit 5 shut it down, there are a few problems:

  1. It gets shutdown multiple times (which can make QuarkusTestResourceLifecycleManager fail - I saw this when looking at the Surefire M5 bump PR)
  2. JUnit 5 shuts it down from the wrong ClassLoader. This is what @pedroigor found yesterday when debugging the mysterious failures I was seeing for the Keycloak tests

@geoand geoand requested a review from stuartwdouglas June 23, 2020 05:37
@geoand geoand marked this pull request as ready for review June 23, 2020 05:42
Copy link
Contributor

@gastaldi gastaldi left a comment

Choose a reason for hiding this comment

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

Makes sense to me

@gastaldi gastaldi added this to the 1.6.0 - master milestone Jun 23, 2020
@gastaldi gastaldi merged commit a002dcf into quarkusio:master Jun 23, 2020
@gastaldi gastaldi deleted the testsource-close branch June 23, 2020 18:09
@stuartwdouglas
Copy link
Collaborator

I don't think this is correct, if the surefire fork count is zero then the tests will be run in the main Maven JVM, and Quarkus will not be shut down until Maven exits, which would be problematic for multi module projects. Not sure if there are similar problematic scenarios with Gradle.

The shutdown hook was supposed to be a 'last resort' form of termination, that only is called in abnormal circumstances.

@geoand
Copy link
Contributor Author

geoand commented Jun 24, 2020

Right.

I also thought that it would probably be problematic for the test profile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants