Skip to content

Commit dc1c8bc

Browse files
cheenamalhotrapaulmedynski
authored andcommitted
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
1 parent 07de862 commit dc1c8bc

4 files changed

Lines changed: 45 additions & 1 deletion

File tree

eng/pipelines/steps/install-dotnet.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ steps:
5555
- ${{ if ne(parameters.architecture, 'arm64') }}:
5656

5757
# Install the SDK listed in the global.json file.
58+
#
59+
# retryCountOnTaskFailure is set because UseDotNet@2 fails intermittently
60+
# in CI due to transient network/CDN issues when downloading the SDK.
5861
- task: UseDotNet@2
5962
displayName: Install .NET SDK (global.json)
63+
retryCountOnTaskFailure: 3
6064
inputs:
6165
installationPath: ${{ parameters.installDir }}
6266
packageType: sdk
@@ -69,6 +73,7 @@ steps:
6973
- ${{ each version in parameters.runtimes }}:
7074
- task: UseDotNet@2
7175
displayName: Install .NET ${{ version }} Runtime
76+
retryCountOnTaskFailure: 3
7277
inputs:
7378
installationPath: ${{ parameters.installDir }}
7479
packageType: runtime
@@ -81,8 +86,13 @@ steps:
8186
- ${{ else }}:
8287

8388
# Use the install script for ARM64.
89+
#
90+
# retryCountOnTaskFailure provides an outer retry around the script's
91+
# internal retry loop, in case the script download itself or the entire
92+
# step fails due to transient issues.
8493
- task: PowerShell@2
8594
displayName: Install .NET SDK and Runtimes for ARM64
95+
retryCountOnTaskFailure: 3
8696
inputs:
8797
targetType: filePath
8898
pwsh: true

src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using System;
5+
using Microsoft.Data.SqlClient.Tests.Common;
66
using Xunit;
77

88
namespace Microsoft.Data.SqlClient.UnitTests;
@@ -18,6 +18,37 @@ public class LocalAppContextSwitchesTest
1818
[Fact]
1919
public void TestDefaultAppContextSwitchValues()
2020
{
21+
// LocalAppContextSwitches caches each switch value on first access for
22+
// the lifetime of the process. Other tests running in parallel may
23+
// already have triggered caching, or may use LocalAppContextSwitchesHelper
24+
// to mutate the cached fields via reflection. To make this test
25+
// deterministic, acquire the helper (which serializes against every
26+
// other helper user via a process-wide semaphore) and reset each
27+
// cached field to None so the properties re-read from AppContext.
28+
using LocalAppContextSwitchesHelper switchesHelper = new();
29+
30+
switchesHelper.EnableMultiSubnetFailoverByDefault = null;
31+
switchesHelper.IgnoreServerProvidedFailoverPartner = null;
32+
switchesHelper.UseLegacyFailoverAlternationOnLoginSqlErrors = null;
33+
switchesHelper.LegacyRowVersionNullBehavior = null;
34+
switchesHelper.LegacyVarTimeZeroScaleBehaviour = null;
35+
switchesHelper.MakeReadAsyncBlocking = null;
36+
switchesHelper.SuppressInsecureTlsWarning = null;
37+
switchesHelper.TruncateScaledDecimal = null;
38+
switchesHelper.UseCompatibilityAsyncBehaviour = null;
39+
switchesHelper.UseCompatibilityProcessSni = null;
40+
switchesHelper.UseConnectionPoolV2 = null;
41+
switchesHelper.UseMinimumLoginTimeout = null;
42+
#if NET
43+
switchesHelper.GlobalizationInvariantMode = null;
44+
#endif
45+
#if NET && _WINDOWS
46+
switchesHelper.UseManagedNetworking = null;
47+
#endif
48+
#if NETFRAMEWORK
49+
switchesHelper.DisableTnirByDefault = null;
50+
#endif
51+
2152
Assert.False(LocalAppContextSwitches.LegacyRowVersionNullBehavior);
2253
Assert.False(LocalAppContextSwitches.SuppressInsecureTlsWarning);
2354
Assert.False(LocalAppContextSwitches.MakeReadAsyncBlocking);

src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionFailoverTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ public void TransientFault_ShouldConnectToPrimary(uint errorCode)
395395
[InlineData(40613)]
396396
[InlineData(42108)]
397397
[InlineData(42109)]
398+
[Trait("Category", "flaky")]
398399
public void TransientFault_RetryDisabled_ShouldFail(uint errorCode)
399400
{
400401
// Arrange
@@ -498,6 +499,7 @@ public void TransientFault_WithUserProvidedPartner_ShouldConnectToPrimary(uint e
498499
[InlineData(40613)]
499500
[InlineData(42108)]
500501
[InlineData(42109)]
502+
[Trait("Category", "flaky")]
501503
public void TransientFault_WithUserProvidedPartner_RetryDisabled_ShouldFail(uint errorCode)
502504
{
503505
// Arrange

src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionRoutingTestsAzure.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ public void NetworkDelayAtRoutedLocation_RetryDisabled_ShouldSucceed()
158158
}
159159

160160
[Fact]
161+
[Trait("Category", "flaky")]
161162
public void NetworkTimeoutAtRoutedLocation_RetryDisabled_ShouldFail()
162163
{
163164
// Arrange

0 commit comments

Comments
 (0)