|
| 1 | +//------------------------------------------------------------------------------ |
| 2 | +// <auto-generated> |
| 3 | +// This code was generated by AsyncGenerator. |
| 4 | +// |
| 5 | +// Changes to this file may cause incorrect behavior and will be lost if |
| 6 | +// the code is regenerated. |
| 7 | +// </auto-generated> |
| 8 | +//------------------------------------------------------------------------------ |
| 9 | + |
| 10 | + |
| 11 | +using System.Linq; |
| 12 | +using System.Threading; |
| 13 | +using System.Transactions; |
| 14 | +using NHibernate.Engine; |
| 15 | +using NUnit.Framework; |
| 16 | +using NHibernate.Linq; |
| 17 | + |
| 18 | +namespace NHibernate.Test.NHSpecificTest.GH1594 |
| 19 | +{ |
| 20 | + using System.Threading.Tasks; |
| 21 | + [TestFixture] |
| 22 | + public class FixtureAsync : BugTestCase |
| 23 | + { |
| 24 | + protected override bool AppliesTo(ISessionFactoryImplementor factory) => |
| 25 | + factory.ConnectionProvider.Driver.SupportsSystemTransactions; |
| 26 | + |
| 27 | + protected override void OnSetUp() |
| 28 | + { |
| 29 | + using (var session = OpenSession()) |
| 30 | + using (var transaction = session.BeginTransaction()) |
| 31 | + { |
| 32 | + var e1 = new GH1594.Entity {Name = "Bob"}; |
| 33 | + session.Save(e1); |
| 34 | + |
| 35 | + var e2 = new GH1594.Entity {Name = "Sally"}; |
| 36 | + session.Save(e2); |
| 37 | + |
| 38 | + transaction.Commit(); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + protected override void OnTearDown() |
| 43 | + { |
| 44 | + using (var session = OpenSession()) |
| 45 | + using (var transaction = session.BeginTransaction()) |
| 46 | + { |
| 47 | + // The HQL delete does all the job inside the database without loading the entities, but it does |
| 48 | + // not handle delete order for avoiding violating constraints if any. Use |
| 49 | + // session.Delete("from System.Object"); |
| 50 | + // instead if in need of having NHbernate ordering the deletes, but this will cause |
| 51 | + // loading the entities in the session. |
| 52 | + session.CreateQuery("delete from System.Object").ExecuteUpdate(); |
| 53 | + |
| 54 | + transaction.Commit(); |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + [Test] |
| 59 | + public async Task ExecutionContextLocalValuesLeakAsync() |
| 60 | + { |
| 61 | + using (var session = OpenSession()) |
| 62 | + { |
| 63 | + await (RunInTransactionAsync(session)); |
| 64 | + var localValuesCountAfterFirstCall = ExecutionContext.Capture().LocalValuesCount(); |
| 65 | + await (RunInTransactionAsync(session)); |
| 66 | + var localValuesCountAfterSecondCall = ExecutionContext.Capture().LocalValuesCount(); |
| 67 | + Assert.AreEqual(localValuesCountAfterFirstCall, localValuesCountAfterSecondCall); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + private async Task RunInTransactionAsync(ISession session, CancellationToken cancellationToken = default(CancellationToken)) |
| 72 | + { |
| 73 | + using (var ts = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) |
| 74 | + { |
| 75 | + var result = from e in session.Query<GH1594.Entity>() |
| 76 | + where e.Name == "Bob" |
| 77 | + select e; |
| 78 | + |
| 79 | + await (result.ToListAsync(cancellationToken)); |
| 80 | + ts.Complete(); |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | +} |
0 commit comments