From 27a0d1d3c8c269e6e1be64e4e1bc1aaa47d57b11 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra <13396919+cheenamalhotra@users.noreply.github.com> Date: Thu, 28 May 2026 23:26:50 -0700 Subject: [PATCH 1/2] Tests | Address transient errors in CI pipelines (#4314) * Retry installing dotnet in CI + address flaky tests * One more flaky test * FIx TestDefaultAppContextSwitchValues to be deterministic --- eng/pipelines/steps/install-dotnet.yml | 10 ++++++ .../SqlClient/LocalAppContextSwitchesTest.cs | 33 ++++++++++++++++++- .../ConnectionFailoverTests.cs | 2 ++ .../ConnectionRoutingTestsAzure.cs | 1 + 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/eng/pipelines/steps/install-dotnet.yml b/eng/pipelines/steps/install-dotnet.yml index e6a50ee03f..5774984663 100644 --- a/eng/pipelines/steps/install-dotnet.yml +++ b/eng/pipelines/steps/install-dotnet.yml @@ -55,8 +55,12 @@ steps: - ${{ if ne(parameters.architecture, 'arm64') }}: # Install the SDK listed in the global.json file. + # + # retryCountOnTaskFailure is set because UseDotNet@2 fails intermittently + # in CI due to transient network/CDN issues when downloading the SDK. - task: UseDotNet@2 displayName: Install .NET SDK (global.json) + retryCountOnTaskFailure: 3 inputs: installationPath: ${{ parameters.installDir }} packageType: sdk @@ -69,6 +73,7 @@ steps: - ${{ each version in parameters.runtimes }}: - task: UseDotNet@2 displayName: Install .NET ${{ version }} Runtime + retryCountOnTaskFailure: 3 inputs: installationPath: ${{ parameters.installDir }} packageType: runtime @@ -81,8 +86,13 @@ steps: - ${{ else }}: # Use the install script for ARM64. + # + # retryCountOnTaskFailure provides an outer retry around the script's + # internal retry loop, in case the script download itself or the entire + # step fails due to transient issues. - task: PowerShell@2 displayName: Install .NET SDK and Runtimes for ARM64 + retryCountOnTaskFailure: 3 inputs: targetType: filePath pwsh: true diff --git a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs index a5db02faa0..98a8958107 100644 --- a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; +using Microsoft.Data.SqlClient.Tests.Common; using Xunit; namespace Microsoft.Data.SqlClient.UnitTests; @@ -18,6 +18,37 @@ public class LocalAppContextSwitchesTest [Fact] public void TestDefaultAppContextSwitchValues() { + // LocalAppContextSwitches caches each switch value on first access for + // the lifetime of the process. Other tests running in parallel may + // already have triggered caching, or may use LocalAppContextSwitchesHelper + // to mutate the cached fields via reflection. To make this test + // deterministic, acquire the helper (which serializes against every + // other helper user via a process-wide semaphore) and reset each + // cached field to None so the properties re-read from AppContext. + using LocalAppContextSwitchesHelper switchesHelper = new(); + + switchesHelper.EnableMultiSubnetFailoverByDefault = null; + switchesHelper.IgnoreServerProvidedFailoverPartner = null; + switchesHelper.UseLegacyFailoverAlternationOnLoginSqlErrors = null; + switchesHelper.LegacyRowVersionNullBehavior = null; + switchesHelper.LegacyVarTimeZeroScaleBehaviour = null; + switchesHelper.MakeReadAsyncBlocking = null; + switchesHelper.SuppressInsecureTlsWarning = null; + switchesHelper.TruncateScaledDecimal = null; + switchesHelper.UseCompatibilityAsyncBehaviour = null; + switchesHelper.UseCompatibilityProcessSni = null; + switchesHelper.UseConnectionPoolV2 = null; + switchesHelper.UseMinimumLoginTimeout = null; + #if NET + switchesHelper.GlobalizationInvariantMode = null; + #endif + #if NET && _WINDOWS + switchesHelper.UseManagedNetworking = null; + #endif + #if NETFRAMEWORK + switchesHelper.DisableTnirByDefault = null; + #endif + Assert.False(LocalAppContextSwitches.LegacyRowVersionNullBehavior); Assert.False(LocalAppContextSwitches.SuppressInsecureTlsWarning); Assert.False(LocalAppContextSwitches.MakeReadAsyncBlocking); diff --git a/src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionFailoverTests.cs b/src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionFailoverTests.cs index 4d95c22cb3..a8734f9b8a 100644 --- a/src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionFailoverTests.cs +++ b/src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionFailoverTests.cs @@ -380,6 +380,7 @@ public void TransientFault_ShouldConnectToPrimary(uint errorCode) [InlineData(40613)] [InlineData(42108)] [InlineData(42109)] + [Trait("Category", "flaky")] public void TransientFault_RetryDisabled_ShouldFail(uint errorCode) { // Arrange @@ -475,6 +476,7 @@ public void TransientFault_WithUserProvidedPartner_ShouldConnectToPrimary(uint e [InlineData(40613)] [InlineData(42108)] [InlineData(42109)] + [Trait("Category", "flaky")] public void TransientFault_WithUserProvidedPartner_RetryDisabled_ShouldFail(uint errorCode) { // Arrange diff --git a/src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionRoutingTestsAzure.cs b/src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionRoutingTestsAzure.cs index dd945e37f3..31dfc366fc 100644 --- a/src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionRoutingTestsAzure.cs +++ b/src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionRoutingTestsAzure.cs @@ -159,6 +159,7 @@ public void NetworkDelayAtRoutedLocation_RetryDisabled_ShouldSucceed() } [Fact] + [Trait("Category", "flaky")] public void NetworkTimeoutAtRoutedLocation_RetryDisabled_ShouldFail() { // Arrange From 3fff6ca15f8fbaf93ae9537012c4980dcb00c87c Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Fri, 29 May 2026 11:10:12 -0700 Subject: [PATCH 2/2] Address compilation error --- .../Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs index 98a8958107..2435eb2f4a 100644 --- a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs @@ -29,7 +29,6 @@ public void TestDefaultAppContextSwitchValues() switchesHelper.EnableMultiSubnetFailoverByDefault = null; switchesHelper.IgnoreServerProvidedFailoverPartner = null; - switchesHelper.UseLegacyFailoverAlternationOnLoginSqlErrors = null; switchesHelper.LegacyRowVersionNullBehavior = null; switchesHelper.LegacyVarTimeZeroScaleBehaviour = null; switchesHelper.MakeReadAsyncBlocking = null;