Skip to content

Missing Async test for GH1594 #1608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions src/NHibernate.Test/Async/NHSpecificTest/GH1594/Fixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


using System.Linq;
using System.Threading;
using System.Transactions;
using NHibernate.Engine;
using NUnit.Framework;
using NHibernate.Linq;

namespace NHibernate.Test.NHSpecificTest.GH1594
{
using System.Threading.Tasks;
[TestFixture]
public class FixtureAsync : BugTestCase
{
protected override bool AppliesTo(ISessionFactoryImplementor factory) =>
factory.ConnectionProvider.Driver.SupportsSystemTransactions;

protected override void OnSetUp()
{
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
var e1 = new GH1594.Entity {Name = "Bob"};
session.Save(e1);

var e2 = new GH1594.Entity {Name = "Sally"};
session.Save(e2);

transaction.Commit();
}
}

protected override void OnTearDown()
{
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
// The HQL delete does all the job inside the database without loading the entities, but it does
// not handle delete order for avoiding violating constraints if any. Use
// session.Delete("from System.Object");
// instead if in need of having NHbernate ordering the deletes, but this will cause
// loading the entities in the session.
session.CreateQuery("delete from System.Object").ExecuteUpdate();

transaction.Commit();
}
}

[Test]
public async Task ExecutionContextLocalValuesLeakAsync()
{
using (var session = OpenSession())
{
await (RunInTransactionAsync(session));
var localValuesCountAfterFirstCall = ExecutionContext.Capture().LocalValuesCount();
await (RunInTransactionAsync(session));
var localValuesCountAfterSecondCall = ExecutionContext.Capture().LocalValuesCount();
Assert.AreEqual(localValuesCountAfterFirstCall, localValuesCountAfterSecondCall);
}
}

private async Task RunInTransactionAsync(ISession session, CancellationToken cancellationToken = default(CancellationToken))
{
using (var ts = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
var result = from e in session.Query<GH1594.Entity>()
where e.Name == "Bob"
select e;

await (result.ToListAsync(cancellationToken));
ts.Complete();
}
}
}
}