I’ve been trying to set up some test cases and have run into an issue with nested transactions. I’m doing something similar to this post where I am wrapping all test cases in a transaction.
/**
* @aroundEach
*/
function aroundAll( spec, suite, data ) {
//Always wrap all tests cases in a transaction and roll it back so we don't save any data to the database
transaction {
try {
//Call the test case
arguments.spec.body();
}
catch(any e) {
//Rethrow error so that it will be caught by the test runner and show up in the list
rethrow;
}
finally {
transaction action="rollback";
ormClearSession();
}
}
}
The issue is if there is already a transaction in the code I’m calling with the test case and that inner transaction is committed, then this aroundAll transaction never gets rolled back and the data is saved to the database.
I’ve tried using savepoints in both the inner and outer transactions, but the data is still getting committed.
Is there any way to get around this?