@@ -162,13 +162,15 @@ public void TearDown()
162
162
var wereClosed = _sessionFactory . CheckSessionsWereClosed ( ) ;
163
163
var wasCleaned = CheckDatabaseWasCleaned ( ) ;
164
164
var wereConnectionsClosed = CheckConnectionsWereClosed ( ) ;
165
- fail = ! wereClosed || ! wasCleaned || ! wereConnectionsClosed ;
165
+ var wereTransactionsDisposed = CheckEnlistedTransactionsWereDisposed ( ) ;
166
+ fail = ! wereClosed || ! wasCleaned || ! wereConnectionsClosed || ! wereTransactionsDisposed ;
166
167
167
168
if ( fail )
168
169
{
169
170
badCleanupMessage = "Test didn't clean up after itself. session closed: " + wereClosed + "; database cleaned: " +
170
171
wasCleaned
171
- + "; connection closed: " + wereConnectionsClosed ;
172
+ + "; connection closed: " + wereConnectionsClosed
173
+ + "; transactions disposed:" + wereTransactionsDisposed ; ;
172
174
if ( testResult != null && testResult . Outcome . Status == TestStatus . Failed )
173
175
{
174
176
// Avoid hiding a test failure (asserts are usually not hidden, but other exception would be).
@@ -259,6 +261,31 @@ private bool CheckConnectionsWereClosed()
259
261
return false ;
260
262
}
261
263
264
+ private bool CheckEnlistedTransactionsWereDisposed ( )
265
+ {
266
+ System . Transactions . Transaction current = System . Transactions . Transaction . Current ;
267
+ bool notAborted = ( ( System . Transactions . Transaction . Current ? . TransactionInformation . Status ) ?? System . Transactions . TransactionStatus . Aborted ) != System . Transactions . TransactionStatus . Aborted ;
268
+ if ( ! notAborted ) return true ;
269
+
270
+ do
271
+ {
272
+ notAborted = current . TransactionInformation . Status != System . Transactions . TransactionStatus . Aborted ;
273
+
274
+ try
275
+ {
276
+ current . Dispose ( ) ;
277
+ }
278
+ catch ( Exception ex )
279
+ {
280
+ log . Error ( "Error disposing enlisted transaction" , ex ) ;
281
+ }
282
+
283
+ current = System . Transactions . Transaction . Current ;
284
+ } while ( current != null && notAborted ) ;
285
+
286
+ return false ;
287
+ }
288
+
262
289
/// <summary>
263
290
/// (Re)Create the configuration.
264
291
/// </summary>
0 commit comments