Skip to content

Commit e65635b

Browse files
authored
Improve DTC test stability. (#3181)
1 parent 9bada0a commit e65635b

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/TransactionTest/DistributedTransactionTest.Windows.cs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,25 +108,21 @@ private void EnlistedTransactionPreservedWhilePooled()
108108
transactionException = ex;
109109
}
110110

111-
if (Utils.IsAzureSqlServer(new SqlConnectionStringBuilder((ConnectionString)).DataSource))
112-
{
113-
// Even if an application swallows the command exception, completing the transaction should indicate that it failed.
114-
Assert.IsType<TransactionInDoubtException>(transactionException);
115-
// See https://learn.microsoft.com/en-us/sql/relational-databases/errors-events/database-engine-events-and-errors-3000-to-3999?view=sql-server-ver16
116-
// Error 3971 corresponds to "The server failed to resume the transaction."
117-
Assert.Equal(3971, ((SqlException)commandException).Number);
118-
}
119-
else
120-
{
121-
Assert.IsType<TransactionAbortedException>(transactionException);
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) };
113+
Assert.Contains(transactionException.GetType(), expectedTransactionExceptions);
122114

123-
#if NETFRAMEWORK
115+
var expectedCommandExceptions = new[] { typeof(SqlException), typeof(InvalidOperationException) };
116+
Assert.Contains(commandException.GetType(), expectedCommandExceptions);
117+
118+
if (commandException is SqlException)
119+
{
124120
// See https://learn.microsoft.com/en-us/sql/relational-databases/errors-events/database-engine-events-and-errors-8000-to-8999?view=sql-server-ver16
125121
// The distributed transaction failed
126-
Assert.Equal(8525, ((SqlException)commandException).Number);
127-
#else
128-
Assert.IsType<InvalidOperationException>(commandException);
129-
#endif
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+
// Error 3971 corresponds to "The server failed to resume the transaction."
124+
var expectedExceptionCodes = new[] { 3971, 8525 };
125+
Assert.Contains(((SqlException)commandException).Number, expectedExceptionCodes);
130126
}
131127

132128
// Verify that nothing made it into the database

0 commit comments

Comments
 (0)