jdaugherty opened a new pull request, #15436:
URL: https://github.com/apache/grails-core/pull/15436

   After reviewing several of the grails-data PRs submitted by @jamesfredley I 
realized that a pattern we implemented in our Grails app would be beneficial 
for everyone: rather than use `@Rollback`, etc we use a clean up process that 
truncates all tables with data.  I've extracted our internal logic into a 
generic spock extension & then enhanced it with the assistance of AI to be a 
little more generic.  Only H2 & Postgres (AI did this one, while the H2 one was 
lifted from our internal implementation) are implemented for now.  
   
   There aren't really many dependencies with this feature (I did make 
grails-testing-support-core a dependency only to be able to reliably resolve 
the ApplicationContext, but it could be argued that the dependency isn't 
needed).  The spock extension requires `@Integration` to use the 
`DefaultApplicationContextResolver` to find the application context.  We could 
relax the `@Integration` requirement if a custom resolver is provided. 
   
   The annotation can be placed at the class level to clear all data after each 
test, or individually on each method - only the methods annotated will truncate 
the database after running. It should be rather performant since it issues 
truncates instead of iterating over every row (FK's etc are disabled during the 
cleanup process too).  There's also some optional debug that can be turned on.
   
   I'm adding this to 7.0.x since it doesn't impact any of the existing code & 
we can then make use of it in the various grails-data tests to be DRY.  Simply 
annotate the test, and the database is always clean now at the start of every 
test - regardless of new transaction testing, etc.  This also means with the 
combination of `@Stepwise` you can now test multi-transaction processes and 
roll back the data reliably. 
   
   Assisted-by: OpenCode <[[email protected]](mailto:[email protected])>
   Assisted-by: Claude <[[email protected]](mailto:[email protected])>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to