-
Notifications
You must be signed in to change notification settings - Fork 61
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
Testing with two JPA datasources fails - possibly rolls back incorrect order #95
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Any news on this? |
Hi @ysb33r sorry for the delay in giving you a response. Do you have a sample application that I can use to reproduce the issue? |
We are running into this same issue!
|
Hi, do we have any update on this? This issue also doesn't seem to be fixed in the latest (2.*) version. |
If anyone has a sample that reproduces the issue, we can reopen it. |
@alvarosanchez here is a reproducible test case: |
I'm actually experiencing this same issue but using a single GORM datasource. First test fails every time w/ "Transaction synchronization is not active" then the rest pass, even if the test doesn't actually do anything requiring GORM/transactions. |
I have the same issue with two JDBC datasources. I got test failures unless @MicronautTest(transactional=false). |
We already had:
@MicronautTest(transactional=false)
and apply manual transaction management for multiple data sources that have been configured.I am coming back to this issue as I think that #28 is a very inconvenient workaround. It don't think it should be necessary to do all the extra work just because an application has more than one datasource.
To re-state the problem: When an application has more than one JPA datasource, the following exception is thrown at cleanup of the first test in the suite.
Let's dig into this assuming we have two datasources
default
andabc
listed in this order inapplication.yml
. (I explicitly chose the alphabetical reverse order as in this investigation I had no clue whether it was significant).In my original case, the test class is annotated with
MicronautTest
and some tests only interacted with thedefault
datasource, some withabc
and some with both. This all turned out as non-relevant. A silly Spock setup such as 👇 produces the problemtest1
will fail,test2
will pass.. It cannot be bypassed by usage of something like@FailsWith
or@PendingFeature
, because the issue is not with the test, it is with the cleanup.The end the logged outcome is always the same irrespective of a test failure(i.e. an assertion failure the logs) or whether test passes. In the case where the first test fails the same exception is still emitted (https://github.com/micronaut-projects/micronaut-data/blob/293560e4cdc0c56274c79c91a250925227f79784/data-tx/src/main/java/io/micronaut/transaction/support/TransactionSynchronizationManager.java#L319), but is masked by the test assertion.
The first thing was tor validate in which order the datasource are found and loaded for
default
andabc
as the log shows.☝️ Ordering has been consistent, and I don't think contributes to any issue.
Next thing is the actual running of the test - the two transactions are created by the test, followed by roll back in the test cleanup.
Notice that it creates
162795775
and then656883468
, but when it rolls back it attempts162795775
first. I imagined that being wrong and if looking at the code heremicronaut-test/test-core/src/main/java/io/micronaut/test/extensions/AbstractMicronautExtension.java
Line 92 in 860a914
This has seemed pretty consistent after sifting through hours of logs of running tests in various combinations: When the rollback order is reversed, the first test passes; so does the rest.
I am pleading some lack of understanding the bigger picture, but what I see in front of me in my test context, is that the rollback should be in reverse order.
The text was updated successfully, but these errors were encountered: