Skip to content

[#487] One SessionFactory per test class #683

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

Merged
merged 14 commits into from
Apr 6, 2021

Conversation

DavideD
Copy link
Member

@DavideD DavideD commented Mar 29, 2021

Fixes #487

Work on this with @blafond.

Now the test will create the factory once per test class. This saves some time with dbs like Db2 or CockroachDB.
The only issues I had is that some times tests get stuck but I couldn't figure out why. Refactoring some tests so that they now
use transaction solved the issues most of time.

If you do this, make sure that you recreate the factory after any test failure. Otherwise, the failure of one test method would have a cascading effect on all the other tests in that class (because its data won't be cleaned up).

@gavinking. do we really need to do this? The cleanDb method is called even when there is a failure. I suppose we could reset the factory if there is a problem deleting the entities but we don't have that many tests in a single class so I don't think it would be a problem. The reason I would prefer not to do it is because the only place I could do something like this is after the deleteEntities method has been called. I might thinkg of a better solution later.

For some reasons, this test doesn't work with Db2: https://github.com/hibernate/hibernate-reactive/compare/main...DavideD:487-sf-per-class?expand=1#diff-659762d6654e6fae801ebfcf7577499a86f6799bd9ce7948922726acc994fbab
Unless I recreate the factory each time.

I've also removed JUnit 5, in the end we don't need it and having both dependencies on the classpath might only causes issues.
I might add it back in the future if they add an extension that's now missing in vertx-junit-5

@DavideD DavideD requested review from blafond and gavinking March 29, 2021 16:05
@gavinking
Copy link
Member

do we really need to do this?

Well I think so, yes. I mean, I don't trust us to always write a cleanDb() method. Indeed, that is a total PITA to have to do.

@DavideD DavideD force-pushed the 487-sf-per-class branch 2 times, most recently from db7e697 to 4778d55 Compare March 29, 2021 17:59
@DavideD
Copy link
Member Author

DavideD commented Mar 29, 2021

Well I think so, yes. I mean, I don't trust us to always write a cleanDb() method. Indeed, that is a total PITA to have to do.

@blafond is having a look to see if we can find the name of the entities and create a default deleteEntities that will work for most cases

@DavideD DavideD force-pushed the 487-sf-per-class branch 2 times, most recently from 221a9a8 to 718b702 Compare March 29, 2021 18:59
@DavideD DavideD marked this pull request as draft March 29, 2021 19:03
@DavideD
Copy link
Member Author

DavideD commented Mar 29, 2021

Something doesn't work as expected on the latest JDKs.
I've tried a quick experiment and noticed that the error message is different. Instead of containing the expected
Detected use of the reactive Session from a different Thread it says Session/EntityManager is closed (
https://github.com/hibernate/hibernate-reactive/pull/683/checks?check_run_id=2221537360#step:7:988)

Note that, because I wanted to see the error message, I've changed the assertion for that specific run. The assertion failing is actually:

testContext.assertTrue( e.getMessage().contains( ERROR_MESSAGE ) );

It would be interesting to know why there is a different error.
I will be on holiday until next week, if somebodys want to have a look at it is more than welcome, otherwise I will get back to it later.

@DavideD DavideD force-pushed the 487-sf-per-class branch 11 times, most recently from 9f42ed8 to eea05b3 Compare March 30, 2021 23:41
@DavideD
Copy link
Member Author

DavideD commented Mar 31, 2021

I think this is ready to be merged now. If anything because it fixes some existing tests

@DavideD DavideD requested a review from blafond March 31, 2021 07:17
@DavideD DavideD force-pushed the 487-sf-per-class branch 3 times, most recently from 920a07d to 7e6e596 Compare April 2, 2021 22:32
@blafond blafond marked this pull request as ready for review April 5, 2021 13:35
@blafond
Copy link
Member

blafond commented Apr 5, 2021

Looks good. Clean implementation and provides test classes option to manage DB entities life cycle.

@DavideD DavideD force-pushed the 487-sf-per-class branch from 7e6e596 to 9fe36dc Compare April 5, 2021 14:08
DavideD added 13 commits April 6, 2021 14:45
In preparation of having a single factory per test class
Unless the entities define it, we cannot rely on the
element order to check the content of a collection.
We will use it to handle a unique session factory
for tests in the same class.
I've also refactored some because they would get stuck on
some databases otherwise.
We don't really need it at the moment and having
both dependencies on the classpath is a recipe for
errors.
Additional test methods for when we need create an async
before calling the method.
@DavideD DavideD force-pushed the 487-sf-per-class branch 2 times, most recently from 50a8a39 to 6b33c5a Compare April 6, 2021 15:11
@DavideD
Copy link
Member Author

DavideD commented Apr 6, 2021

The build is still failing on CI sometimes. I'm having a look

@DavideD DavideD force-pushed the 487-sf-per-class branch from ea7f97c to eec0364 Compare April 6, 2021 16:20
* Make sure test actually runs
* Remove unecessary local variables
* Less strict check on the exception location
@DavideD DavideD force-pushed the 487-sf-per-class branch from eec0364 to 0d3943e Compare April 6, 2021 16:21
@DavideD DavideD merged commit abe07c9 into hibernate:main Apr 6, 2021
@DavideD
Copy link
Member Author

DavideD commented Apr 6, 2021

Merged #683

We can tweak it later when problems occur.

@DavideD DavideD deleted the 487-sf-per-class branch April 7, 2021 10:47
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.

Create one SessionFactory per class in tests
3 participants