Skip to content

Commit

Permalink
Move distributed transaction test to OleTxTests (#74747)
Browse files Browse the repository at this point in the history
NonMsdtcPromoterTests.PSPENonMsdtcGetPromoterTypeMSDTC was triggering
an MSDTC distributed transaction on Windows, but without the proper
checks/resiliency. Moved to OleTxTests.

Fixes #74170
  • Loading branch information
roji authored Aug 29, 2022
1 parent 1d27c3d commit 012f474
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class NonMsdtcPromoterTests : IDisposable
private static MethodInfo s_setDistributedTransactionIdentifierMethodInfo;
private static MethodInfo s_getPromotedTokenMethodInfo;
private static PropertyInfo s_promoterTypePropertyInfo;
private static FieldInfo s_promoterTypeDtcFieldInfo;

public NonMsdtcPromoterTests()
{
Expand Down Expand Up @@ -51,17 +50,12 @@ private static void VerifySoftDependencies()

// And the PropertyInfo objects for PromoterType
s_promoterTypePropertyInfo = typeof(Transaction).GetTypeInfo().GetProperty("PromoterType", typeof(Guid));

// And the FieldInfo for TransactionInterop.PromoterTypeDtc
s_promoterTypeDtcFieldInfo = typeof(TransactionInterop).GetTypeInfo().GetField("PromoterTypeDtc", BindingFlags.Public | BindingFlags.Static);
}

bool allMethodsAreThere = ((s_enlistPromotableSinglePhaseMethodInfo != null) &&
(s_setDistributedTransactionIdentifierMethodInfo != null) &&
(s_getPromotedTokenMethodInfo != null) &&
(s_promoterTypePropertyInfo != null) &&
(s_promoterTypeDtcFieldInfo != null)
);
(s_promoterTypePropertyInfo != null));
Assert.True(allMethodsAreThere, "At least one of the expected new methods or properties is not implemented by the available System.Transactions.");
}

Expand Down Expand Up @@ -339,14 +333,6 @@ private static byte[] TxPromotedToken(Transaction txToGet)
return (byte[])s_getPromotedTokenMethodInfo.Invoke(txToGet, null);
}

private static Guid PromoterTypeDtc
{
get
{
return (Guid)s_promoterTypeDtcFieldInfo.GetValue(null);
}
}

#endregion

#region NonMSDTCPromoterEnlistment
Expand Down Expand Up @@ -1706,45 +1692,6 @@ private static void TestCase_PromoterType()
TestPassed();
}

private static void TestCase_PromoterTypeMSDTC()
{
string testCaseDescription = "TestCase_PromoterTypeMSDTC";

Trace("**** " + testCaseDescription + " ****");

AutoResetEvent volCompleted = new AutoResetEvent(false);
MyEnlistment vol = null;

try
{
using (TransactionScope ts = new TransactionScope())
{
Assert.Equal(Guid.Empty, TxPromoterType(Transaction.Current));

vol = CreateVolatileEnlistment(volCompleted);

// Force MSDTC promotion.
TransactionInterop.GetDtcTransaction(Transaction.Current);

// TransactionInterop.PromoterTypeDtc
Assert.Equal(PromoterTypeDtc, TxPromoterType(Transaction.Current));

ts.Complete();
}
}
catch (Exception ex)
{
Trace(string.Format("Caught unexpected exception {0}:{1}", ex.GetType().ToString(), ex.ToString()));
return;
}

Assert.True(volCompleted.WaitOne(TimeSpan.FromSeconds(5)));

Assert.True(vol.CommittedOutcome);

TestPassed();
}

private static void TestCase_FailPromotableSinglePhaseNotificationCalls()
{
string testCaseDescription = "TestCase_FailPromotableSinglePhaseNotificationCalls";
Expand Down Expand Up @@ -2133,16 +2080,6 @@ public void PSPENonMsdtcGetPromoterType()
TestCase_PromoterType();
}

/// <summary>
/// PSPE Non-MSDTC Get PromoterType.
/// </summary>
[Fact]
public void PSPENonMsdtcGetPromoterTypeMSDTC()
{
// get_PromoterType
TestCase_PromoterTypeMSDTC();
}

/// <summary>
/// PSPE Non-MSDTC Fail PromotableSinglePhaseNotification Calls.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,15 @@ public void TransmitterPropagationToken()

[Fact]
public void GetWhereabouts()
=> Assert.Throws<PlatformNotSupportedException>(() => TransactionInterop.GetWhereabouts());
=> Assert.Throws<PlatformNotSupportedException>(TransactionInterop.GetWhereabouts);

[Fact]
public void GetExportCookie()
=> Assert.Throws<PlatformNotSupportedException>(() => TransactionInterop.GetExportCookie(
new CommittableTransaction(), new byte[200]));
=> Assert.Throws<PlatformNotSupportedException>(() =>
TransactionInterop.GetExportCookie(new CommittableTransaction(), new byte[200]));

[Fact]
public void GetDtcTransaction()
=> Assert.Throws<PlatformNotSupportedException>(() =>
TransactionInterop.GetDtcTransaction(new CommittableTransaction()));
}
28 changes: 28 additions & 0 deletions src/libraries/System.Transactions.Local/tests/OleTxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,34 @@ public void GetExportCookie()
Assert.Equal(tx.TransactionInformation.DistributedIdentifier, tx2.TransactionInformation.DistributedIdentifier);
});

// Test currently skipped, #74745
private void GetDtcTransaction()
=> Test(() =>
{
using var tx = new CommittableTransaction();

var outcomeReceived = new AutoResetEvent(false);

var enlistment = new TestEnlistment(
Phase1Vote.Prepared, EnlistmentOutcome.Committed, outcomeReceived: outcomeReceived);

Assert.Equal(Guid.Empty, tx.PromoterType);

tx.EnlistVolatile(enlistment, EnlistmentOptions.None);

// Forces promotion to MSDTC, returns an ITransaction for use only with System.EnterpriseServices.
_ = TransactionInterop.GetDtcTransaction(tx);

Assert.Equal(TransactionStatus.Active, tx.TransactionInformation.Status);
Assert.Equal(TransactionInterop.PromoterTypeDtc, tx.PromoterType);

tx.Commit();

Assert.True(outcomeReceived.WaitOne(Timeout));
Assert.Equal(EnlistmentOutcome.Committed, enlistment.Outcome);
Retry(() => Assert.Equal(TransactionStatus.Committed, tx.TransactionInformation.Status));
});

private static void Test(Action action)
{
// Temporarily skip on 32-bit where we have an issue.
Expand Down

0 comments on commit 012f474

Please sign in to comment.