@@ -130,6 +130,7 @@ private void runMfSetup(TestSuite testSuite) {
130130 if (testSuite .getAutoRollbackMFs ()) {
131131 setupContext = Core .createSystemContext ();
132132 setupContext .startTransaction ();
133+ LOG .trace ("Start transaction for setup" );
133134 Core .microflowCall (testSuite .getModule () + ".Setup" ).execute (setupContext );
134135 } else {
135136 Core .microflowCall (testSuite .getModule () + ".Setup" ).execute (Core .createSystemContext ());
@@ -148,10 +149,13 @@ private void runMfTearDown(TestSuite testSuite) {
148149 LOG .info ("Running TearDown microflow.." );
149150 if (tearDownContext == null ) {
150151 tearDownContext = Core .createSystemContext ();
152+
153+ if (testSuite .getAutoRollbackMFs ()) {
154+ tearDownContext .startTransaction ();
155+ LOG .trace ("Start transaction for teardown" );
156+ }
151157 }
152- if (testSuite .getAutoRollbackMFs ()) {
153- tearDownContext .startTransaction ();
154- }
158+
155159 Core .microflowCall (testSuite .getModule () + ".TearDown" ).execute (tearDownContext );
156160 } catch (Exception e ) {
157161 LOG .error ("Severe: exception in unittest TearDown microflow '" + testSuite .getModule () + ".TearDown': "
@@ -160,8 +164,9 @@ private void runMfTearDown(TestSuite testSuite) {
160164 }
161165 }
162166
163- // Either we had a teardown a teardown or
167+ // Rollback teardown and/or setup transaction
164168 if (testSuite .getAutoRollbackMFs () && tearDownContext != null ) {
169+ LOG .trace ("Rollback transaction for setup and/or teardown" );
165170 tearDownContext .rollbackTransaction ();
166171 }
167172
@@ -335,7 +340,9 @@ private boolean runMicroflowTest(String mf, UnitTest test, TestSuite testSuite)
335340 mfContext = setupContext .clone ();
336341 else
337342 mfContext = Core .createSystemContext ();
343+
338344 mfContext .startTransaction ();
345+ LOG .trace ("Start transaction for unit test" );
339346 } else {
340347 mfContext = Core .createSystemContext ();
341348 }
@@ -358,8 +365,6 @@ private boolean runMicroflowTest(String mf, UnitTest test, TestSuite testSuite)
358365
359366 return res ;
360367 } catch (Exception e ) {
361- if (testSuite .getAutoRollbackMFs ())
362- mfContext .startTransaction ();
363368 start = System .currentTimeMillis () - start ;
364369 test .setResult (UnitTestResult ._2_Failed );
365370 Throwable cause = ExceptionUtils .getRootCause (e );
@@ -370,8 +375,10 @@ private boolean runMicroflowTest(String mf, UnitTest test, TestSuite testSuite)
370375 return false ;
371376
372377 } finally {
373- if (testSuite .getAutoRollbackMFs ())
378+ if (testSuite .getAutoRollbackMFs () && mfContext .isInTransaction ()) {
379+ LOG .trace ("Rollback transaction for unit test" );
374380 mfContext .rollbackTransaction ();
381+ }
375382 test .setLastStep (lastStep );
376383 test .setReadableTime ((start > 10000 ? Math .round (start / 1000 ) + " seconds" : start + " milliseconds" ));
377384 commitSilent (test );
0 commit comments