Skip to content

Commit

Permalink
Swallow MSDTC availability exceptions for CI test reliability (#77023)
Browse files Browse the repository at this point in the history
Fixes #76836
  • Loading branch information
roji authored Oct 18, 2022
1 parent e55ece6 commit fdcbc7b
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/libraries/System.Transactions.Local/tests/OleTxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.DotNet.RemoteExecutor;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;

namespace System.Transactions.Tests;
Expand Down Expand Up @@ -542,7 +541,7 @@ public void ImplicitDistributedTransactions_cannot_be_changed_after_being_read_a
{
TransactionManager.ImplicitDistributedTransactions = true;
MinimalOleTxScenario();
Test(MinimalOleTxScenario);
Assert.Throws<InvalidOperationException>(() => TransactionManager.ImplicitDistributedTransactions = false);
TransactionManager.ImplicitDistributedTransactions = true;
Expand Down Expand Up @@ -575,6 +574,11 @@ private static void Test(Action action)
return;
}

if (s_isTestSuiteDisabled)
{
return;
}

TransactionManager.ImplicitDistributedTransactions = true;

// In CI, we sometimes get XACT_E_TMNOTAVAILABLE; when it happens, it's typically on the very first
Expand All @@ -589,14 +593,27 @@ private static void Test(Action action)
action();
return;
}
catch (TransactionException e) when (e.InnerException is TransactionManagerCommunicationException)
catch (Exception e) when (e is TransactionManagerCommunicationException or TransactionException { InnerException: TransactionManagerCommunicationException })
{
if (--nRetries == 0)
if (--nRetries > 0)
{
throw;
Thread.Sleep(1000);

continue;
}

Thread.Sleep(1000);
// We've continuously gotten XACT_E_TMNOTAVAILABLE for the entire retry window - MSDTC is unavailable in some way.
// We don't want this to make our CI flaky, so we swallow the exception and skip all subsequent tests.
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("DOTNET_CI")) ||
!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("HELIX_WORKITEM_ROOT")) ||
!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("AGENT_OS")))
{
s_isTestSuiteDisabled = true;

return;
}

throw;
}
}
}
Expand Down Expand Up @@ -647,4 +664,6 @@ public class OleTxFixture
public OleTxFixture()
=> Test(MinimalOleTxScenario);
}

private static bool s_isTestSuiteDisabled;
}

0 comments on commit fdcbc7b

Please sign in to comment.