Skip to content

Commit 4451a41

Browse files
NH-2176 - crutch for delayed disposal. Only possible fix IMO: cease delaying session disposal when an ambient transaction is ongoing.
1 parent c2a3806 commit 4451a41

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/NHibernate.Test/TestCase.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using NUnit.Framework.Interfaces;
1717
using System.Text;
1818
using static NUnit.Framework.TestContext;
19+
using System.Threading;
1920

2021
namespace NHibernate.Test
2122
{
@@ -221,13 +222,26 @@ private bool CheckSessionsWereClosed()
221222
var allClosed = true;
222223
foreach (var session in _openedSessions)
223224
{
224-
session.GetSessionImplementation().TransactionContext?.WaitOne();
225-
if (session.IsOpen)
225+
var txContext = session.GetSessionImplementation().TransactionContext;
226+
txContext?.WaitOne();
227+
if (!session.IsOpen)
228+
continue;
229+
230+
if (txContext?.ShouldCloseSessionOnDistributedTransactionCompleted ?? false)
226231
{
227-
log.Error($"Test case didn't close session {session.GetSessionImplementation().SessionId}, closing");
228-
allClosed = false;
229-
session.Close();
232+
// Delayed rollback not having lock from prepare phase? Give it a chance to complete.
233+
Thread.Sleep(100);
234+
txContext.WaitOne();
235+
if (!session.IsOpen)
236+
{
237+
Assert.Warn($"Test case had a delayed close of session {session.GetSessionImplementation().SessionId}.");
238+
continue;
239+
}
230240
}
241+
242+
log.Error($"Test case didn't close session {session.GetSessionImplementation().SessionId}, closing");
243+
allClosed = false;
244+
session.Close();
231245
}
232246

233247
return allClosed;

0 commit comments

Comments
 (0)