Skip to content

Commit 3ebb8cd

Browse files
NH-2176 - Forgotten update of ambient transaction. More cleanup of DTC tests.
1 parent d864dbe commit 3ebb8cd

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public void WillNotCrashOnDtcPrepareFailure()
141141
}
142142

143143
[Test]
144-
public void Can_roll_back_transaction()
144+
public void CanRollbackTransaction()
145145
{
146146
var tx = new TransactionScope();
147147
var disposeCalled = false;
@@ -218,7 +218,6 @@ public void TransactionInsertWithRollBackTask()
218218
s.Save(person);
219219
ForceEscalationToDistributedTx.Escalate(true); //will rollback tx
220220
person.CreatedAt = DateTime.Now;
221-
s.Update(person);
222221
}
223222
txscope.Complete();
224223
}
@@ -259,7 +258,6 @@ public void TransactionInsertLoadWithRollBackTask()
259258
{
260259
var person = s.Get<Person>(savedId);
261260
person.CreatedAt = createdAt.AddMonths(-1);
262-
s.Update(person);
263261
}
264262
ForceEscalationToDistributedTx.Escalate(true);
265263

@@ -308,7 +306,6 @@ public void TransactionInsertLoadFlushWithRollBackTask()
308306
{
309307
var person = s.Get<Person>(savedId);
310308
person.CreatedAt = createdAt.AddMonths(-1);
311-
s.Update(person);
312309
s.Flush();
313310
}
314311
ForceEscalationToDistributedTx.Escalate(true);
@@ -343,7 +340,7 @@ public void MultiThreadedTransaction()
343340
{
344341
delegate
345342
{
346-
Can_roll_back_transaction();
343+
CanRollbackTransaction();
347344
_totalCall++;
348345
},
349346
delegate
@@ -375,9 +372,10 @@ public void MultiThreadedTransaction()
375372
public void CanDeleteItemInDtc()
376373
{
377374
object id;
375+
ISession s;
378376
using (var tx = new TransactionScope())
379377
{
380-
using (var s = sessions.OpenSession())
378+
using (s = sessions.OpenSession())
381379
{
382380
id = s.Save(new Person { CreatedAt = DateTime.Today });
383381

@@ -387,15 +385,17 @@ public void CanDeleteItemInDtc()
387385
}
388386
}
389387

390-
using (var s = sessions.OpenSession())
388+
s.GetSessionImplementation().TransactionContext?.WaitOne();
389+
390+
using (s = sessions.OpenSession())
391391
using (s.BeginTransaction())
392392
{
393393
Assert.AreEqual(1, s.Query<Person>().Count(), "Entity not found in database.");
394394
}
395395

396396
using (var tx = new TransactionScope())
397397
{
398-
using (var s = sessions.OpenSession())
398+
using (s = sessions.OpenSession())
399399
{
400400
ForceEscalationToDistributedTx.Escalate();
401401

@@ -405,6 +405,8 @@ public void CanDeleteItemInDtc()
405405
}
406406
}
407407

408+
s.GetSessionImplementation().TransactionContext?.WaitOne();
409+
408410
AssertNoPersons();
409411
}
410412

src/NHibernate/AdoNet/ConnectionManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ private void CloseConnection()
155155
{
156156
Factory.ConnectionProvider.CloseConnection(_connection);
157157
_connection = null;
158+
_connectionAmbientTransaction = null;
158159
}
159160

160161
public DbConnection GetConnection()
@@ -378,6 +379,7 @@ public void EnlistIfRequired()
378379
// Probable case: nested transaction scope. Supporting this could be done by releasing the
379380
// connection instead of enlisting.
380381
_session.Connection.EnlistTransaction(tran);
382+
_connectionAmbientTransaction = tran;
381383
}
382384

383385
private bool RequireConnectionSwapInDtc

0 commit comments

Comments
 (0)