Skip to content

Commit d8b634a

Browse files
rojigithub-actions
authored and
github-actions
committed
Move distributed transaction test to OleTxTests
NonMsdtcPromoterTests.PSPENonMsdtcGetPromoterTypeMSDTC was triggering an MSDTC distributed transaction on Windows, but without the proper checks/resiliency. Moved to OleTxTests. Fixes #74170
1 parent fe99c44 commit d8b634a

File tree

3 files changed

+37
-67
lines changed

3 files changed

+37
-67
lines changed

src/libraries/System.Transactions.Local/tests/NonMsdtcPromoterTests.cs

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public class NonMsdtcPromoterTests : IDisposable
2121
private static MethodInfo s_setDistributedTransactionIdentifierMethodInfo;
2222
private static MethodInfo s_getPromotedTokenMethodInfo;
2323
private static PropertyInfo s_promoterTypePropertyInfo;
24-
private static FieldInfo s_promoterTypeDtcFieldInfo;
2524

2625
public NonMsdtcPromoterTests()
2726
{
@@ -51,17 +50,12 @@ private static void VerifySoftDependencies()
5150

5251
// And the PropertyInfo objects for PromoterType
5352
s_promoterTypePropertyInfo = typeof(Transaction).GetTypeInfo().GetProperty("PromoterType", typeof(Guid));
54-
55-
// And the FieldInfo for TransactionInterop.PromoterTypeDtc
56-
s_promoterTypeDtcFieldInfo = typeof(TransactionInterop).GetTypeInfo().GetField("PromoterTypeDtc", BindingFlags.Public | BindingFlags.Static);
5753
}
5854

5955
bool allMethodsAreThere = ((s_enlistPromotableSinglePhaseMethodInfo != null) &&
6056
(s_setDistributedTransactionIdentifierMethodInfo != null) &&
6157
(s_getPromotedTokenMethodInfo != null) &&
62-
(s_promoterTypePropertyInfo != null) &&
63-
(s_promoterTypeDtcFieldInfo != null)
64-
);
58+
(s_promoterTypePropertyInfo != null));
6559
Assert.True(allMethodsAreThere, "At least one of the expected new methods or properties is not implemented by the available System.Transactions.");
6660
}
6761

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

342-
private static Guid PromoterTypeDtc
343-
{
344-
get
345-
{
346-
return (Guid)s_promoterTypeDtcFieldInfo.GetValue(null);
347-
}
348-
}
349-
350336
#endregion
351337

352338
#region NonMSDTCPromoterEnlistment
@@ -1706,45 +1692,6 @@ private static void TestCase_PromoterType()
17061692
TestPassed();
17071693
}
17081694

1709-
private static void TestCase_PromoterTypeMSDTC()
1710-
{
1711-
string testCaseDescription = "TestCase_PromoterTypeMSDTC";
1712-
1713-
Trace("**** " + testCaseDescription + " ****");
1714-
1715-
AutoResetEvent volCompleted = new AutoResetEvent(false);
1716-
MyEnlistment vol = null;
1717-
1718-
try
1719-
{
1720-
using (TransactionScope ts = new TransactionScope())
1721-
{
1722-
Assert.Equal(Guid.Empty, TxPromoterType(Transaction.Current));
1723-
1724-
vol = CreateVolatileEnlistment(volCompleted);
1725-
1726-
// Force MSDTC promotion.
1727-
TransactionInterop.GetDtcTransaction(Transaction.Current);
1728-
1729-
// TransactionInterop.PromoterTypeDtc
1730-
Assert.Equal(PromoterTypeDtc, TxPromoterType(Transaction.Current));
1731-
1732-
ts.Complete();
1733-
}
1734-
}
1735-
catch (Exception ex)
1736-
{
1737-
Trace(string.Format("Caught unexpected exception {0}:{1}", ex.GetType().ToString(), ex.ToString()));
1738-
return;
1739-
}
1740-
1741-
Assert.True(volCompleted.WaitOne(TimeSpan.FromSeconds(5)));
1742-
1743-
Assert.True(vol.CommittedOutcome);
1744-
1745-
TestPassed();
1746-
}
1747-
17481695
private static void TestCase_FailPromotableSinglePhaseNotificationCalls()
17491696
{
17501697
string testCaseDescription = "TestCase_FailPromotableSinglePhaseNotificationCalls";
@@ -2133,16 +2080,6 @@ public void PSPENonMsdtcGetPromoterType()
21332080
TestCase_PromoterType();
21342081
}
21352082

2136-
/// <summary>
2137-
/// PSPE Non-MSDTC Get PromoterType.
2138-
/// </summary>
2139-
[Fact]
2140-
public void PSPENonMsdtcGetPromoterTypeMSDTC()
2141-
{
2142-
// get_PromoterType
2143-
TestCase_PromoterTypeMSDTC();
2144-
}
2145-
21462083
/// <summary>
21472084
/// PSPE Non-MSDTC Fail PromotableSinglePhaseNotification Calls.
21482085
/// </summary>

src/libraries/System.Transactions.Local/tests/OleTxNonWindowsUnsupportedTests.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,15 @@ public void TransmitterPropagationToken()
5555

5656
[Fact]
5757
public void GetWhereabouts()
58-
=> Assert.Throws<PlatformNotSupportedException>(() => TransactionInterop.GetWhereabouts());
58+
=> Assert.Throws<PlatformNotSupportedException>(TransactionInterop.GetWhereabouts);
5959

6060
[Fact]
6161
public void GetExportCookie()
62-
=> Assert.Throws<PlatformNotSupportedException>(() => TransactionInterop.GetExportCookie(
63-
new CommittableTransaction(), new byte[200]));
62+
=> Assert.Throws<PlatformNotSupportedException>(() =>
63+
TransactionInterop.GetExportCookie(new CommittableTransaction(), new byte[200]));
64+
65+
[Fact]
66+
public void GetDtcTransaction()
67+
=> Assert.Throws<PlatformNotSupportedException>(() =>
68+
TransactionInterop.GetDtcTransaction(new CommittableTransaction()));
6469
}

src/libraries/System.Transactions.Local/tests/OleTxTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,34 @@ public void GetExportCookie()
433433
Assert.Equal(tx.TransactionInformation.DistributedIdentifier, tx2.TransactionInformation.DistributedIdentifier);
434434
});
435435

436+
// Test currently skipped, #74745
437+
private void GetDtcTransaction()
438+
=> Test(() =>
439+
{
440+
using var tx = new CommittableTransaction();
441+
442+
var outcomeReceived = new AutoResetEvent(false);
443+
444+
var enlistment = new TestEnlistment(
445+
Phase1Vote.Prepared, EnlistmentOutcome.Committed, outcomeReceived: outcomeReceived);
446+
447+
Assert.Equal(Guid.Empty, tx.PromoterType);
448+
449+
tx.EnlistVolatile(enlistment, EnlistmentOptions.None);
450+
451+
// Forces promotion to MSDTC, returns an ITransaction for use only with System.EnterpriseServices.
452+
_ = TransactionInterop.GetDtcTransaction(tx);
453+
454+
Assert.Equal(TransactionStatus.Active, tx.TransactionInformation.Status);
455+
Assert.Equal(TransactionInterop.PromoterTypeDtc, tx.PromoterType);
456+
457+
tx.Commit();
458+
459+
Assert.True(outcomeReceived.WaitOne(Timeout));
460+
Assert.Equal(EnlistmentOutcome.Committed, enlistment.Outcome);
461+
Retry(() => Assert.Equal(TransactionStatus.Committed, tx.TransactionInformation.Status));
462+
});
463+
436464
private static void Test(Action action)
437465
{
438466
// Temporarily skip on 32-bit where we have an issue.

0 commit comments

Comments
 (0)