Skip to content

Commit dd95913

Browse files
Generate async files
1 parent a8e54cb commit dd95913

File tree

1 file changed

+53
-5
lines changed

1 file changed

+53
-5
lines changed

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

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,10 @@ public async Task EnforceConnectionUsageRulesOnTransactionCompletionAsync()
531531
[Test]
532532
public async Task SupportsTransactionTimeoutAsync()
533533
{
534-
Assume.That(TestDialect.SupportsTransactionScopeTimeouts, Is.True);
534+
Assume.That(TestDialect.SupportsTransactionScopeTimeouts, Is.True, "The tested dialect is not supported for transaction scope timeouts.");
535+
// ODBC always freezes the session during transaction scopes timeouts.
536+
Assume.That(Sfi.ConnectionProvider.Driver, Is.Not.InstanceOf(typeof(OdbcDriver)), "ODBC is not supported for transaction scope timeouts.");
537+
535538
// Test case adapted from https://github.com/kaksmet/NHibBugRepro
536539

537540
// Create some test data.
@@ -552,7 +555,7 @@ public async Task SupportsTransactionTimeoutAsync()
552555
await (t.CommitAsync());
553556
}
554557

555-
// Setup unhandler exception catcher
558+
// Setup unhandled exception catcher.
556559
_unhandledExceptions = new ConcurrentBag<object>();
557560
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
558561
try
@@ -579,18 +582,63 @@ public async Task SupportsTransactionTimeoutAsync()
579582
// Assume that is a transaction timeout. It may cause various failures, of which some are hard to identify.
580583
timeoutsCount++;
581584
}
585+
// If in need of checking some specific failures, the following code may be used instead:
586+
/*
587+
catch (Exception ex)
588+
{
589+
var currentEx = ex;
590+
// Depending on where the transaction aborption has broken NHibernate processing, we may
591+
// get various exceptions, like directly a TransactionAbortedException with an inner
592+
// TimeoutException, or a HibernateException encapsulating a TransactionException with a
593+
// timeout, ...
594+
bool isTransactionException, isTimeout;
595+
do
596+
{
597+
isTransactionException = currentEx is System.Transactions.TransactionException;
598+
isTimeout = isTransactionException && currentEx is TransactionAbortedException;
599+
currentEx = currentEx.InnerException;
600+
}
601+
while (!isTransactionException && currentEx != null);
602+
while (!isTimeout && currentEx != null)
603+
{
604+
isTimeout = currentEx is TimeoutException;
605+
currentEx = currentEx?.InnerException;
606+
}
607+
608+
if (!isTimeout)
609+
{
610+
// We may also get a GenericADOException with an InvalidOperationException stating the
611+
// transaction associated to the connection is no more active but not yet suppressed,
612+
// and that for executing some SQL, we need to suppress it. That is a weak way of
613+
// identifying the case, especially with the many localizations of the message.
614+
currentEx = ex;
615+
do
616+
{
617+
isTimeout = currentEx is InvalidOperationException && currentEx.Message.Contains("SQL");
618+
currentEx = currentEx?.InnerException;
619+
}
620+
while (!isTimeout && currentEx != null);
621+
}
622+
623+
if (isTimeout)
624+
timeoutsCount++;
625+
else
626+
throw;
627+
}
628+
*/
582629
}
583630

584-
// Despite the Thread sleep and the count of entities to load, this test may get the timeout only for slightly
585-
// more than 10% of the attempts.
586-
Assert.That(timeoutsCount, Is.GreaterThan(5), "The test should have generated more timeouts.");
587631
Assert.That(
588632
_unhandledExceptions.Count,
589633
Is.EqualTo(0),
590634
"Unhandled exceptions have occurred: {0}",
591635
string.Join(@"
592636
593637
", _unhandledExceptions));
638+
639+
// Despite the Thread sleep and the count of entities to load, this test may get the timeout only for slightly
640+
// more than 10% of the attempts.
641+
Warn.Unless(timeoutsCount, Is.GreaterThan(5), "The test should have generated more timeouts.");
594642
}
595643
finally
596644
{

0 commit comments

Comments
 (0)