-
Notifications
You must be signed in to change notification settings - Fork 198
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
Problem with transaction & rollback behaviour in integration tests #929
Comments
As far as I can see there is no way for you to do what you want for both the controller and service case. The explanation is as follows. In the case where you use If you remove However, removing The only way to do what you are doing and achieve rollback for both the controller test case and the service test case is to manually delete the data you created within the Therefore I am not exactly sure what solution or fix you anticipate us to make since as far as I can see nothing can be done to unify these two distinct approaches to testing. You can of course refactor your |
Hmmm..so it's all about the thread. I got your point but a small confusion. When we create test data with or without Or the data created inside |
Apart from the above, I updated my test suite to use transactional block just for the controller and removing it manually and all test works fine sagrawal31/integration-tests@6e35c4a. Is that what you wanted to say? Also, if I add |
The data is persisted to the database yes, but it has only been written the transaction log. The What this means is that the current transaction sees the data, but other threads that read data via different connections have no visibility on this data. This is quite simply how transactions work (read up on ACID). If you use |
Great! Now clear with the setup. I read about ACID, good to know for future developement. Thanks @graemerocher |
Task List
Stacktrace (if present) providedSteps to Reproduce
git clone [email protected]:sagrawal31/integration-tests.git
grails test-app -integration
Expected Behaviour
All test cases should pass.
Actual Behaviour
Data created in earlier test cases are not rolled back hence two test cases fails.
Environment Information
Example Application
https://github.com/sagrawal31/integration-tests/commits
I'm aware of the recent GORM changes that everything needs to be in a Transaction. And also aware of using
@Rollback
annotations (from Grails & Spring) for writing test methods. Based on these understanding, I've written integration tests for controllers & services. Please see commit by commit in the above link. Here is what is happening:withNewTransaction
then those test data aren't available in the source code while running the test case of a controllerwithNewTransaction
for creating test data in a controller's test case, then only it's available in the running source but then that test data is not automatically rolled back.So basically, data is not rolled back if we don't create test data in
withNewTrasaction
for a controller spec but if create test data inwithNewTransaction
block then controller spec works but service spec starts failing due to previous data is not rolled back.I've tried various solutions like using spring's
@Rollback
or GORM's@Transactional
and@Rollback
but nothing worked. I've tracked individual solutions in different commits but none of them made all the test cases happy.I've already gone through previous related issues multiple times, for example, grails/grails-core#10504, grails/grails-core#9289, grails/grails-core#10556 etc but nothing worked for me for the past 3 days and I had to finally create this issue.
The text was updated successfully, but these errors were encountered: