@@ -48,15 +48,15 @@ public async Task Delegated_transaction_deadlock_in_SinglePhaseCommit()
48
48
private static bool s_EnlistedTransactionPreservedWhilePooledCondition => DataTestUtility . AreConnStringsSetup ( ) && DataTestUtility . IsNotX86Architecture ;
49
49
50
50
[ ConditionalFact ( nameof ( s_EnlistedTransactionPreservedWhilePooledCondition ) , Timeout = 10000 ) ]
51
- public void Test_EnlistedTransactionPreservedWhilePooled ( )
51
+ public async Task Test_EnlistedTransactionPreservedWhilePooled ( )
52
52
{
53
53
#if NET
54
54
TransactionManager . ImplicitDistributedTransactions = true ;
55
55
#endif
56
- RunTestSet ( EnlistedTransactionPreservedWhilePooled ) ;
56
+ await RunTestSet ( EnlistedTransactionPreservedWhilePooled ) ;
57
57
}
58
58
59
- private void EnlistedTransactionPreservedWhilePooled ( )
59
+ private async Task EnlistedTransactionPreservedWhilePooled ( )
60
60
{
61
61
Exception commandException = null ;
62
62
Exception transactionException = null ;
@@ -67,7 +67,7 @@ private void EnlistedTransactionPreservedWhilePooled()
67
67
{
68
68
// Leave first connection open so that the transaction is promoted
69
69
SqlConnection rootConnection = new SqlConnection ( ConnectionString ) ;
70
- rootConnection . Open ( ) ;
70
+ await rootConnection . OpenAsync ( ) ;
71
71
using ( SqlCommand command = rootConnection . CreateCommand ( ) )
72
72
{
73
73
command . CommandText = $ "INSERT INTO { TestTableName } VALUES ({ InputCol1 } , '{ InputCol2 } ')";
@@ -109,25 +109,25 @@ private void EnlistedTransactionPreservedWhilePooled()
109
109
}
110
110
111
111
// Even if an application swallows the command exception, completing the transaction should indicate that it failed.
112
- var expectedTransactionExceptions = new [ ] { typeof ( TransactionAbortedException ) , typeof ( TransactionInDoubtException ) } ;
112
+ Type [ ] expectedTransactionExceptions = new [ ] { typeof ( TransactionAbortedException ) , typeof ( TransactionInDoubtException ) } ;
113
113
Assert . Contains ( transactionException . GetType ( ) , expectedTransactionExceptions ) ;
114
114
115
- var expectedCommandExceptions = new [ ] { typeof ( SqlException ) , typeof ( InvalidOperationException ) } ;
115
+ Type [ ] expectedCommandExceptions = new [ ] { typeof ( SqlException ) , typeof ( InvalidOperationException ) } ;
116
116
Assert . Contains ( commandException . GetType ( ) , expectedCommandExceptions ) ;
117
117
118
- if ( commandException is SqlException )
118
+ if ( commandException is SqlException exception )
119
119
{
120
120
// See https://learn.microsoft.com/en-us/sql/relational-databases/errors-events/database-engine-events-and-errors-8000-to-8999?view=sql-server-ver16
121
121
// The distributed transaction failed
122
122
// See https://learn.microsoft.com/en-us/sql/relational-databases/errors-events/database-engine-events-and-errors-3000-to-3999?view=sql-server-ver16
123
123
// Error 3971 corresponds to "The server failed to resume the transaction."
124
124
var expectedExceptionCodes = new [ ] { 3971 , 8525 } ;
125
- Assert . Contains ( ( ( SqlException ) commandException ) . Number , expectedExceptionCodes ) ;
125
+ Assert . Contains ( exception . Number , expectedExceptionCodes ) ;
126
126
}
127
127
128
128
// Verify that nothing made it into the database
129
129
DataTable result = DataTestUtility . RunQuery ( ConnectionString , $ "select col2 from { TestTableName } where col1 = { InputCol1 } ") ;
130
- Assert . True ( result . Rows . Count == 0 ) ;
130
+ Assert . Equal ( 0 , result . Rows . Count ) ;
131
131
}
132
132
133
133
private void KillProcess ( int serverProcessId )
@@ -152,7 +152,7 @@ private void KillProcess(int serverProcessId)
152
152
private const int InputCol1 = 1 ;
153
153
private const string InputCol2 = "One" ;
154
154
155
- private static void RunTestSet ( Action TestCase )
155
+ private static async Task RunTestSet ( Func < Task > TestCase )
156
156
{
157
157
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder ( DataTestUtility . TCPConnectionString ) ;
158
158
@@ -165,7 +165,7 @@ private static void RunTestSet(Action TestCase)
165
165
DataTestUtility . RunNonQuery ( ConnectionString , $ "create table { TestTableName } (col1 int, col2 text)") ;
166
166
try
167
167
{
168
- TestCase ( ) ;
168
+ await TestCase ( ) ;
169
169
}
170
170
finally
171
171
{
0 commit comments