@@ -148,31 +148,44 @@ public void TearDown()
148
148
{
149
149
var testResult = TestContext . CurrentContext . Result ;
150
150
var fail = false ;
151
+ var testOwnTearDownDone = false ;
151
152
string badCleanupMessage = null ;
152
153
try
153
154
{
154
155
try
155
156
{
156
157
OnTearDown ( ) ;
158
+ testOwnTearDownDone = true ;
157
159
}
158
160
finally
159
161
{
160
- var wereClosed = _sessionFactory . CheckSessionsWereClosed ( ) ;
161
- var wasCleaned = CheckDatabaseWasCleaned ( ) ;
162
- var wereConnectionsClosed = CheckConnectionsWereClosed ( ) ;
163
- fail = ! wereClosed || ! wasCleaned || ! wereConnectionsClosed ;
164
-
165
- if ( fail )
162
+ try
166
163
{
167
- badCleanupMessage = "Test didn't clean up after itself. session closed: " + wereClosed + "; database cleaned: " +
168
- wasCleaned
169
- + "; connection closed: " + wereConnectionsClosed ;
170
- if ( testResult != null && testResult . Outcome . Status == TestStatus . Failed )
164
+ var wereClosed = _sessionFactory . CheckSessionsWereClosed ( ) ;
165
+ var wasCleaned = CheckDatabaseWasCleaned ( ) ;
166
+ var wereConnectionsClosed = CheckConnectionsWereClosed ( ) ;
167
+ fail = ! wereClosed || ! wasCleaned || ! wereConnectionsClosed ;
168
+
169
+ if ( fail )
171
170
{
172
- // Avoid hiding a test failure (asserts are usually not hidden, but other exception would be).
173
- badCleanupMessage = GetCombinedFailureMessage ( testResult , badCleanupMessage , null ) ;
171
+ badCleanupMessage = "Test didn't clean up after itself. session closed: " + wereClosed + "; database cleaned: " +
172
+ wasCleaned
173
+ + "; connection closed: " + wereConnectionsClosed ;
174
+ if ( testResult != null && testResult . Outcome . Status == TestStatus . Failed )
175
+ {
176
+ // Avoid hiding a test failure (asserts are usually not hidden, but other exception would be).
177
+ badCleanupMessage = GetCombinedFailureMessage ( testResult , badCleanupMessage , null ) ;
178
+ }
174
179
}
175
180
}
181
+ catch ( Exception ex )
182
+ {
183
+ if ( testOwnTearDownDone )
184
+ throw ;
185
+
186
+ // Do not hide the test own teardown failure.
187
+ log . Error ( "TearDown cleanup failure, while test own teardown has failed. Logging cleanup failure" , ex ) ;
188
+ }
176
189
}
177
190
}
178
191
catch ( Exception ex )
0 commit comments