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

Make Hibernate Reactive tests use @RunOnVertxContext and upgrade the Context validity checks #23905

Merged
merged 8 commits into from
Feb 25, 2022

Conversation

geoand
Copy link
Contributor

@geoand geoand commented Feb 23, 2022

[edited by @Sanne ]
This makes the internal integration tests of Hibernate Reactive use the @RunOnVertxContext annotation and also:

  1. makes the @RunOnVertxContext also work for internal tests
  2. introduces an attribute on @RunOnVertxContext to specify the kind of context
  3. Changes/renames the quarkus-junit5-vertx - necessary to resolve cross-module dependencies
  4. Upgrade the checks that Hibernate Reactive performs to validate it running on the right context: it will now fail by default if it's run on an un-blessed context.

This resolves all remaining concerns I had in regards to context usage for H.R.

N.B. This is a breaking change because the module name of quarkus-junit5-vertx was changed to quarkus-test-vertx (as it now needs to support quarkus-junit5-internal), the dependency on quarkus-junit5 was removed and the API changed packages (from io.quarkus.test.junit.vertx to io.quarkus.test.vertx).

@cescoffier
Copy link
Member

Because you are creating a root context and not a duplicated context :-)

@geoand
Copy link
Contributor Author

geoand commented Feb 23, 2022

I need the magic sauce to get to that duplicated context 😉

@geoand
Copy link
Contributor Author

geoand commented Feb 23, 2022

Nevermind, found it, so let me try

@geoand
Copy link
Contributor Author

geoand commented Feb 23, 2022

Success!

@geoand
Copy link
Contributor Author

geoand commented Feb 23, 2022

@Sanne all this PR needs now if the Hibernate tests to be ported (which is what the last commit started). Do you want to do that?

@Sanne
Copy link
Member

Sanne commented Feb 23, 2022

Many thanks! Nice, there are some similarities with what I was toying with yesterday:

In particular I was preparing to introduce an attribute for the @RunOnVertxContext to control if the context shuld be duplicated, to make it more explicit. WDYT should we add it?

@Sanne
Copy link
Member

Sanne commented Feb 23, 2022

How important is the module rename commit cf06953?

If possible I'd refrain from that, so to not introduce breaking changes.

@@ -28,12 +27,15 @@
@Inject
Mutiny.SessionFactory sessionFactory;

@RunOnVertxContext
Copy link
Member

Choose a reason for hiding this comment

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

That's not enough, what kind of context is it running on?
Event loop context, worker context, duplicated context?

The default should be a duplicated context, but we may need parameters to create the right type of context.

Copy link
Member

@Sanne Sanne Feb 23, 2022

Choose a reason for hiding this comment

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

Right - like I suggested I believe we should have some attributes on the annotation to make things explicit and controllable.

But I think "duplicated" could be a reasonable default.

https://github.com/quarkusio/quarkus/compare/main...Sanne:CheckContext?expand=1#diff-b4dcc8850c70f1ef3ed1c7c55fd3cd5b12db20e8b41f3cf8904e0d6ef3536333L77-R86

But I'm ok fixing that as a follow up myself, if there's agreement on the direction :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since you folks know more about what needs to be done, I'm fine with letting you add more metadata to the annotation :)

Copy link
Member

Choose a reason for hiding this comment

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

Cool, yes thanks a lot to implement the testing tool bits. I was trying yesterday but honestly got lost - not familiar with it at all so I appreciate you doing that part.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's too easy to get lost with all the necessary classloader hacks...

@@ -74,7 +75,7 @@ public Object invoke(Object actualTestInstance, Method actualTestMethod, List<Ob
CompletableFuture<Object> cf = new CompletableFuture<>();
RunTestMethodOnContextHandler handler = new RunTestMethodOnContextHandler(actualTestInstance, actualTestMethod,
actualTestMethodArgs, uniAsserter, cf);
vertx.getOrCreateContext().runOnContext(handler);
VertxContext.getOrCreateDuplicatedContext(vertx).runOnContext(handler);
Copy link
Member

Choose a reason for hiding this comment

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

I think we need to give more flexibility. Yes, the default should be a duplicated context with its root being the event loop context, but we may need some other cases.

That being said, that should always run on a duplicated context.

@geoand
Copy link
Contributor Author

geoand commented Feb 23, 2022

If possible I'd refrain from that, so to not introduce breaking changes.

Not really possible to avoid unfortunately because of the dependency of the existing module on quarkus-junit5.

@geoand
Copy link
Contributor Author

geoand commented Feb 23, 2022

In particular I was preparing to introduce an attribute for the @RunOnVertxContext to control if the context shuld be duplicated, to make it more explicit. WDYT should we add it?

Yeah, I think it makes sense. Feel free to make any changes you like in the PR :)

@Sanne Sanne marked this pull request as ready for review February 24, 2022 14:03
@Sanne
Copy link
Member

Sanne commented Feb 24, 2022

I think this is done now - could @geoand and/or @cescoffier have another look?

@geoand geoand changed the title WIP - Make Hibernate Reactive tests use @RunOnVertxContext Make Hibernate Reactive tests use @RunOnVertxContext Feb 24, 2022
@Sanne Sanne changed the title Make Hibernate Reactive tests use @RunOnVertxContext Make Hibernate Reactive tests use @RunOnVertxContext and upgrade the Context validity checks Feb 24, 2022
@geoand
Copy link
Contributor Author

geoand commented Feb 24, 2022

LGTM

@gsmet
Copy link
Member

gsmet commented Feb 24, 2022

@Sanne does that mean that anyone using HR will have to annotate their tests?

@Sanne
Copy link
Member

Sanne commented Feb 24, 2022 via email

@gsmet
Copy link
Member

gsmet commented Feb 24, 2022

It should only affect users of the "internal" testing extension

Ok, cool, good to know.

@geoand
Copy link
Contributor Author

geoand commented Feb 25, 2022

Force pushed another fix

@Sanne
Copy link
Member

Sanne commented Feb 25, 2022

@geoand for who is it actually a breaking change?

To be clear Hibernate Reactive always had the requirement to run on a vert.x context - it just so happens it was able to bypass this requirement in these specific integration tests because the use the internal testing tools which aren't meant for end users.

The only user-affecting change I see is that @RunOnVertxContext now executes (by default) on a duplicated context; but

  1. I don't expect that to have negative impact on tests - it probably was the original intent
  2. The obscure annotation wasn't adverstised
  3. We give the option to run on the global context instead

Let me know if you think I'm forgetting some aspect :)

@geoand
Copy link
Contributor Author

geoand commented Feb 25, 2022

It breaks anyone using @RunOnVertxContext because:

  • The maven module that contains it changed name
  • The dependencies of the maven module that contained it changed
  • The package of the annotation changed

But as we both said, this is very unlikely to have been used by anybody as we never mentioned it anywhere.

So to summarize, it's breaking, but it's rather unlikely to affect anyone.

@Sanne
Copy link
Member

Sanne commented Feb 25, 2022

@geoand ah, sure. But you clarified that in the description already - I thought you meant there was more breaking stuff on top of it.

I think we're good in that case - perhaps I wouldn't have changed the module names as I said earlier, but you said you had no choice :) If we're doing what we can IMO we'll need to go ahead and ask for forgiveness.

@geoand
Copy link
Contributor Author

geoand commented Feb 25, 2022

Agreed

@geoand geoand merged commit 89b8b84 into quarkusio:main Feb 25, 2022
@quarkus-bot quarkus-bot bot added this to the 2.8 - main milestone Feb 25, 2022
@quarkus-bot quarkus-bot bot removed the triage/waiting-for-ci Ready to merge when CI successfully finishes label Feb 25, 2022
@geoand geoand deleted the qut-vertx branch February 25, 2022 14:35
@gsmet gsmet modified the milestones: 2.8 - main, 2.7.3.Final Feb 28, 2022
edeandrea added a commit to quarkusio/quarkus-super-heroes that referenced this pull request Mar 3, 2022
@edeandrea
Copy link
Contributor

edeandrea commented Mar 3, 2022

But as we both said, this is very unlikely to have been used by anybody as we never mentioned it anywhere.

So to summarize, it's breaking, but it's rather unlikely to affect anyone.

That may not be 100% true, as it has broken the super heroes sample app. It doesn't break people just using the @RunOnVertxContext, but also breaks anyone using the UniAsserter, which would be pretty much anyone writing transactional-based tests with Hibernate Reactive/Panache reactive.

See #23612 (comment)

Just my opinion here (and I'm late to this as I am just returning from PTO - so what's done is done), but introducing breaking changes like this shouldn't be done in minor versions. I also understand that I don't fully understand the context which required the breaking change, so circumstances certainly could have warranted it, but it should be avoided in minor versions unless absolutely necessary.

edeandrea added a commit to quarkusio/quarkus-super-heroes that referenced this pull request Mar 3, 2022
* Bump quarkus.platform.version from 2.7.2.Final to 2.7.3.Final

Bumps `quarkus.platform.version` from 2.7.2.Final to 2.7.3.Final.

Updates `quarkus-bom` from 2.7.2.Final to 2.7.3.Final
- [Release notes](https://github.com/quarkusio/quarkus-platform/releases)
- [Commits](quarkusio/quarkus-platform@2.7.2.Final...2.7.3.Final)

Updates `quarkus-maven-plugin` from 2.7.2.Final to 2.7.3.Final

---
updated-dependencies:
- dependency-name: io.quarkus.platform:quarkus-bom
  dependency-type: direct:production
  update-type: version-update:semver-patch
- dependency-name: io.quarkus.platform:quarkus-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Fix based on quarkusio/quarkus#23905

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Eric Deandrea <eric.deandrea@gmail.com>
@Sanne
Copy link
Member

Sanne commented Mar 3, 2022

hi @edeandrea , could you point me to the test in the super heroes app that was affected?

It would help me to see a concrete example, as think this only affects either internal testing API or code which wasn't running in the right context to begin with. I might be wrong though :)

@edeandrea
Copy link
Contributor

@Sanne https://github.com/quarkusio/quarkus-super-heroes/blob/main/rest-heroes/src/test/java/io/quarkus/sample/superheroes/hero/repository/HeroRepositoryTests.java (after I made changes).

I had to change the artifactId of the dependency in pom.xml as well and then update the java package of the UniAsserter class.

Here's the commit: quarkusio/quarkus-super-heroes@5050d31

@cescoffier
Copy link
Member

so, the problem is the artifactId change. @geoand do you believe we can to a relocation?

@edeandrea
Copy link
Contributor

edeandrea commented Mar 3, 2022

so, the problem is the artifactId change. @geoand do you believe we can to a relocation?

Its not just the artifactId change - also the package relocation from io.quarkus.test.junit.vertx to io.quarkus.test.vertx

@geoand
Copy link
Contributor Author

geoand commented Mar 3, 2022

Yeah, I didn't do the relocation thing because the package also had to change.

@Sanne
Copy link
Member

Sanne commented Mar 3, 2022

I guess I don't fully follow why the package had to change? Could we have a deprecated copy of the annotation in the previous location?

@edeandrea
Copy link
Contributor

UniAsserter isn't an annotation - but it probably could have been deprecated and either extended in a new package (or moved to a new package and extended/deprecated in the old)?

@geoand
Copy link
Contributor Author

geoand commented Mar 3, 2022

The old package didn't make sense after the repurposing of the API to work for both internal and user facing tests

@Sanne
Copy link
Member

Sanne commented Mar 3, 2022

The old package didn't make sense after the repurposing of the API to work for both internal and user facing tests

Ok but that's not a reason that it had to change ? I would suggest introducing a deprecated alternative for both the removed types.

@geoand
Copy link
Contributor Author

geoand commented Mar 4, 2022

There were too many changes that stacked up which is why I didn't see the reason for trying to keep compatibility

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.

None yet

5 participants