Skip to content

Commit 1363f10

Browse files
Regenerate async
1 parent 6d68e59 commit 1363f10

File tree

5 files changed

+241
-5
lines changed

5 files changed

+241
-5
lines changed

src/NHibernate.Test/Async/Hql/AggregateFunctionsWithSubSelectTest.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
namespace NHibernate.Test.Hql
1717
{
1818
using System.Threading.Tasks;
19-
using System.Threading;
2019
[TestFixture]
2120
public class AggregateFunctionsWithSubSelectTestAsync : TestCaseMappingByCode
2221
{
@@ -88,7 +87,7 @@ protected override bool AppliesTo(Dialect.Dialect dialect)
8887
[TestCase("MIN", 2)]
8988
[TestCase("MAX", 2)]
9089
[TestCase("AVG", 2d)]
91-
public async Task TestAggregateFunctionAsync(string functionName, object result, CancellationToken cancellationToken = default(CancellationToken))
90+
public async Task TestAggregateFunctionAsync(string functionName, object result)
9291
{
9392
var query = "SELECT " +
9493
" d.Id, " +
@@ -107,14 +106,14 @@ protected override bool AppliesTo(Dialect.Dialect dialect)
107106
using (var session = OpenSession())
108107
using (var transaction = session.BeginTransaction())
109108
{
110-
var results = await (session.CreateQuery(query).ListAsync(cancellationToken));
109+
var results = await (session.CreateQuery(query).ListAsync());
111110

112111
Assert.That(results, Has.Count.EqualTo(1));
113112
var tuple = results[0] as object[];
114113
Assert.That(tuple, Is.Not.Null);
115114
Assert.That(tuple, Has.Length.EqualTo(2));
116115
Assert.That(tuple[1], Is.EqualTo(result));
117-
await (transaction.CommitAsync(cancellationToken));
116+
await (transaction.CommitAsync());
118117
}
119118
}
120119
}

src/NHibernate.Test/Async/NHSpecificTest/NH750/Fixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public async Task DeviceOfDriveAsync()
108108
await (t.CommitAsync());
109109
}
110110

111-
await (VerifyResultAsync(2,2, msg: "modified collection"));
111+
await (VerifyResultAsync(2, 2, msg: "modified collection"));
112112

113113
async Task VerifyResultAsync(int expectedInCollection, int expectedInDb, string msg)
114114
{

src/NHibernate.Test/Async/SystemTransactions/DistributedSystemTransactionFixture.cs

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,117 @@ public async Task EnforceConnectionUsageRulesOnTransactionCompletionAsync()
687687
Assert.That(interceptor.AfterException, Is.TypeOf<HibernateException>());
688688
}
689689

690+
[Theory]
691+
public async Task CanUseDependentTransactionAsync(bool explicitFlush)
692+
{
693+
if (!TestDialect.SupportsDependentTransaction)
694+
Assert.Ignore("Dialect does not support dependent transactions");
695+
IgnoreIfUnsupported(explicitFlush);
696+
697+
try
698+
{
699+
using (var committable = new CommittableTransaction())
700+
{
701+
System.Transactions.Transaction.Current = committable;
702+
using (var clone = committable.DependentClone(DependentCloneOption.RollbackIfNotComplete))
703+
{
704+
System.Transactions.Transaction.Current = clone;
705+
706+
using (var s = OpenSession())
707+
{
708+
if (!AutoJoinTransaction)
709+
s.JoinTransaction();
710+
await (s.SaveAsync(new Person()));
711+
712+
if (explicitFlush)
713+
await (s.FlushAsync());
714+
clone.Complete();
715+
}
716+
}
717+
718+
System.Transactions.Transaction.Current = committable;
719+
committable.Commit();
720+
}
721+
}
722+
finally
723+
{
724+
System.Transactions.Transaction.Current = null;
725+
}
726+
}
727+
728+
[Theory]
729+
public async Task CanUseSessionWithManyDependentTransactionAsync(bool explicitFlush)
730+
{
731+
if (!TestDialect.SupportsDependentTransaction)
732+
Assert.Ignore("Dialect does not support dependent transactions");
733+
IgnoreIfUnsupported(explicitFlush);
734+
735+
try
736+
{
737+
using (var s = Sfi.WithOptions().ConnectionReleaseMode(ConnectionReleaseMode.OnClose).OpenSession())
738+
{
739+
using (var committable = new CommittableTransaction())
740+
{
741+
System.Transactions.Transaction.Current = committable;
742+
using (var clone = committable.DependentClone(DependentCloneOption.RollbackIfNotComplete))
743+
{
744+
System.Transactions.Transaction.Current = clone;
745+
if (!AutoJoinTransaction)
746+
s.JoinTransaction();
747+
// Acquire the connection
748+
var count = await (s.Query<Person>().CountAsync());
749+
Assert.That(count, Is.EqualTo(0), "Unexpected initial entity count.");
750+
clone.Complete();
751+
}
752+
753+
using (var clone = committable.DependentClone(DependentCloneOption.RollbackIfNotComplete))
754+
{
755+
System.Transactions.Transaction.Current = clone;
756+
if (!AutoJoinTransaction)
757+
s.JoinTransaction();
758+
await (s.SaveAsync(new Person()));
759+
760+
if (explicitFlush)
761+
await (s.FlushAsync());
762+
763+
clone.Complete();
764+
}
765+
766+
using (var clone = committable.DependentClone(DependentCloneOption.RollbackIfNotComplete))
767+
{
768+
System.Transactions.Transaction.Current = clone;
769+
if (!AutoJoinTransaction)
770+
s.JoinTransaction();
771+
var count = await (s.Query<Person>().CountAsync());
772+
Assert.That(count, Is.EqualTo(1), "Unexpected entity count after committed insert.");
773+
clone.Complete();
774+
}
775+
776+
System.Transactions.Transaction.Current = committable;
777+
committable.Commit();
778+
}
779+
}
780+
}
781+
finally
782+
{
783+
System.Transactions.Transaction.Current = null;
784+
}
785+
786+
await (DodgeTransactionCompletionDelayIfRequiredAsync());
787+
788+
using (var s = OpenSession())
789+
{
790+
using (var tx = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
791+
{
792+
if (!AutoJoinTransaction)
793+
s.JoinTransaction();
794+
var count = await (s.Query<Person>().CountAsync());
795+
Assert.That(count, Is.EqualTo(1), "Unexpected entity count after global commit.");
796+
tx.Complete();
797+
}
798+
}
799+
}
800+
690801
private Task DodgeTransactionCompletionDelayIfRequiredAsync(CancellationToken cancellationToken = default(CancellationToken))
691802
{
692803
if (Sfi.ConnectionProvider.Driver.HasDelayedDistributedTransactionCompletion)

src/NHibernate.Test/Async/SystemTransactions/SystemTransactionFixture.cs

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,126 @@ public async Task EnforceConnectionUsageRulesOnTransactionCompletionAsync()
523523
// Currently always forbidden, whatever UseConnectionOnSystemTransactionEvents.
524524
Assert.That(interceptor.AfterException, Is.TypeOf<HibernateException>());
525525
}
526+
527+
[Theory]
528+
public async Task CanUseDependentTransactionAsync(bool explicitFlush)
529+
{
530+
if (!TestDialect.SupportsDependentTransaction)
531+
Assert.Ignore("Dialect does not support dependent transactions");
532+
IgnoreIfUnsupported(explicitFlush);
533+
534+
try
535+
{
536+
using (var committable = new CommittableTransaction())
537+
{
538+
System.Transactions.Transaction.Current = committable;
539+
using (var clone = committable.DependentClone(DependentCloneOption.RollbackIfNotComplete))
540+
{
541+
System.Transactions.Transaction.Current = clone;
542+
543+
using (var s = OpenSession())
544+
{
545+
if (!AutoJoinTransaction)
546+
s.JoinTransaction();
547+
await (s.SaveAsync(new Person()));
548+
549+
if (explicitFlush)
550+
await (s.FlushAsync());
551+
clone.Complete();
552+
}
553+
}
554+
555+
System.Transactions.Transaction.Current = committable;
556+
committable.Commit();
557+
}
558+
}
559+
finally
560+
{
561+
System.Transactions.Transaction.Current = null;
562+
}
563+
}
564+
565+
[Theory]
566+
public async Task CanUseSessionWithManyDependentTransactionAsync(bool explicitFlush)
567+
{
568+
if (!TestDialect.SupportsDependentTransaction)
569+
Assert.Ignore("Dialect does not support dependent transactions");
570+
IgnoreIfUnsupported(explicitFlush);
571+
// ODBC with SQL-Server always causes system transactions to go distributed, which causes their transaction completion to run
572+
// asynchronously. But ODBC enlistment also check the previous transaction in a way that do not guard against it
573+
// being concurrently disposed of. See https://github.com/nhibernate/nhibernate-core/pull/1505 for more details.
574+
if (Sfi.ConnectionProvider.Driver is OdbcDriver)
575+
Assert.Ignore("ODBC sometimes fails on second scope by checking the previous transaction status, which may yield an object disposed exception");
576+
// SAP HANA & SQL Anywhere .Net providers always cause system transactions to be distributed, causing them to
577+
// complete on concurrent threads. This creates race conditions when chaining scopes, the subsequent scope usage
578+
// finding the connection still enlisted in the previous transaction, its complete being still not finished
579+
// on its own thread.
580+
if (Sfi.ConnectionProvider.Driver is HanaDriverBase || Sfi.ConnectionProvider.Driver is SapSQLAnywhere17Driver)
581+
Assert.Ignore("SAP HANA and SQL Anywhere scope handling causes concurrency issues preventing chaining scope usages.");
582+
583+
try
584+
{
585+
using (var s = WithOptions().ConnectionReleaseMode(ConnectionReleaseMode.OnClose).OpenSession())
586+
{
587+
using (var committable = new CommittableTransaction())
588+
{
589+
System.Transactions.Transaction.Current = committable;
590+
using (var clone = committable.DependentClone(DependentCloneOption.RollbackIfNotComplete))
591+
{
592+
System.Transactions.Transaction.Current = clone;
593+
if (!AutoJoinTransaction)
594+
s.JoinTransaction();
595+
// Acquire the connection
596+
var count = await (s.Query<Person>().CountAsync());
597+
Assert.That(count, Is.EqualTo(0), "Unexpected initial entity count.");
598+
clone.Complete();
599+
}
600+
601+
using (var clone = committable.DependentClone(DependentCloneOption.RollbackIfNotComplete))
602+
{
603+
System.Transactions.Transaction.Current = clone;
604+
if (!AutoJoinTransaction)
605+
s.JoinTransaction();
606+
await (s.SaveAsync(new Person()));
607+
608+
if (explicitFlush)
609+
await (s.FlushAsync());
610+
611+
clone.Complete();
612+
}
613+
614+
using (var clone = committable.DependentClone(DependentCloneOption.RollbackIfNotComplete))
615+
{
616+
System.Transactions.Transaction.Current = clone;
617+
if (!AutoJoinTransaction)
618+
s.JoinTransaction();
619+
var count = await (s.Query<Person>().CountAsync());
620+
Assert.That(count, Is.EqualTo(1), "Unexpected entity count after committed insert.");
621+
clone.Complete();
622+
}
623+
624+
System.Transactions.Transaction.Current = committable;
625+
committable.Commit();
626+
}
627+
}
628+
}
629+
finally
630+
{
631+
System.Transactions.Transaction.Current = null;
632+
}
633+
634+
using (var s = OpenSession())
635+
{
636+
using (var tx = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
637+
{
638+
if (!AutoJoinTransaction)
639+
s.JoinTransaction();
640+
var count = await (s.Query<Person>().CountAsync());
641+
Assert.That(count, Is.EqualTo(1), "Unexpected entity count after global commit.");
642+
tx.Complete();
643+
}
644+
}
645+
}
526646
}
527647

528648
[TestFixture]

src/NHibernate/Async/Multi/QueryBatchItemBase.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ public async Task ProcessResultsAsync(CancellationToken cancellationToken)
144144

145145
if (queryInfo.IsCacheable)
146146
{
147+
if (queryInfo.IsResultFromCache)
148+
{
149+
var queryCacheBuilder = new QueryCacheResultBuilder(queryInfo.Loader);
150+
queryInfo.Result = queryCacheBuilder.GetResultList(queryInfo.Result);
151+
}
152+
147153
// This transformation must not be applied to ResultToCache.
148154
queryInfo.Result =
149155
queryInfo.Loader.TransformCacheableResults(

0 commit comments

Comments
 (0)