Skip to content

Commit 532ee83

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 532ee83

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/NHibernate.Test/NHSpecificTest/DtcFailures/DtcFailuresFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ public void CanUseSessionOutsideOfScopeAfterScope([Values(false, true)] bool exp
502502
Assert.DoesNotThrow(() => count = s.Query<Person>().Count(), "Failed using the session after scope.");
503503
if (count != 1)
504504
// We are not testing that here, so just issue a warning. Do not use DodgeTransactionCompletionDelayIfRequired
505-
// before previous assert. We want to ascertain the session is usable in any cases.
505+
// before previous assert. We want to ascertain the session is usable in any cases.
506506
Assert.Warn("Unexpected entity count: {0} instead of {1}. The transaction seems to have a delayed commit.", count, 1);
507507
}
508508
}

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+
log.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)