Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
bording committed Sep 14, 2023
1 parent 0f126ed commit 23acbe4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading;
using System.Threading.Tasks;
using System.Transactions;
using NServiceBus.AcceptanceTests.Tx;
using Transport;

public class FakeTransport : TransportDefinition
Expand All @@ -23,12 +24,10 @@ public override Task<TransportInfrastructure> Initialize(HostSettings hostSettin

try
{
using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew, TransactionScopeAsyncFlowOption.Enabled))
{
FakePromotableResourceManager.ForceDtc();
using var scope = new TransactionScope(TransactionScopeOption.RequiresNew, TransactionScopeAsyncFlowOption.Enabled);

DtcIsAvailable = true;
}
FakePromotableResourceManager.ForceDtc();
DtcIsAvailable = true;
}
catch (Exception ex)
{
Expand Down Expand Up @@ -80,17 +79,7 @@ public void RaiseExceptionOnTransportDispose(Exception exception)
public Action<(QueueAddress[] receivingAddresses, string[] sendingAddresses, bool setupInfrastructure)> OnTransportInitialize { get; set; } = _ => { };

public bool DtcIsAvailable { get; set; }
public Exception DtcCheckException { get; private set; }

class FakePromotableResourceManager : IEnlistmentNotification
{
public static readonly Guid Id = Guid.NewGuid();
public void Prepare(PreparingEnlistment preparingEnlistment) => preparingEnlistment.Prepared();
public void Commit(Enlistment enlistment) => enlistment.Done();
public void Rollback(Enlistment enlistment) => enlistment.Done();
public void InDoubt(Enlistment enlistment) => enlistment.Done();

public static void ForceDtc() => Transaction.Current.EnlistDurable(Id, new FakePromotableResourceManager(), EnlistmentOptions.None);
}
public Exception DtcCheckException { get; private set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class When_transport_supports_transaction_scope_on_windows : NServiceBusAcceptanceTest
{
[Test]
public async Task Should_enable_dtc()
public async Task Should_support_dtc()
{
if (!OperatingSystem.IsWindows())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

<ItemGroup>
<RemoveSourceFileFromPackage Include="Core\**\*.cs" />
<RemoveSourceFileFromPackage Remove="Core\Transactions\When_transport_supports_transaction_scope_on_windows.cs" />
<RemoveSourceFileFromPackage Include="AssemblyInfo.cs" />
</ItemGroup>

Expand Down
55 changes: 17 additions & 38 deletions src/NServiceBus.AcceptanceTests/Tx/FakePromotableResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,24 @@

public class FakePromotableResourceManager : IPromotableSinglePhaseNotification, IEnlistmentNotification
{
public void Prepare(PreparingEnlistment preparingEnlistment)
{
preparingEnlistment.Prepared();
}

public void Commit(Enlistment enlistment)
{
enlistment.Done();
}

public void Rollback(Enlistment enlistment)
{
enlistment.Done();
}

public void InDoubt(Enlistment enlistment)
{
enlistment.Done();
}

public void Initialize()
{
}

public void SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment)
{
singlePhaseEnlistment.Committed();
}

public void Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
{
singlePhaseEnlistment.Done();
}

public byte[] Promote()
{
return TransactionInterop.GetTransmitterPropagationToken(new CommittableTransaction());
}
public void Prepare(PreparingEnlistment preparingEnlistment) => preparingEnlistment.Prepared();

public void Commit(Enlistment enlistment) => enlistment.Done();

public void Rollback(Enlistment enlistment) => enlistment.Done();

public void InDoubt(Enlistment enlistment) => enlistment.Done();

public void Initialize() { }

public void SinglePhaseCommit(SinglePhaseEnlistment singlePhaseEnlistment) => singlePhaseEnlistment.Committed();

public void Rollback(SinglePhaseEnlistment singlePhaseEnlistment) => singlePhaseEnlistment.Done();

public byte[] Promote() => TransactionInterop.GetTransmitterPropagationToken(new CommittableTransaction());

public static Guid ResourceManagerId = Guid.Parse("6f057e24-a0d8-4c95-b091-b8dc9a916fa4");

public static void ForceDtc() => Transaction.Current.EnlistDurable(ResourceManagerId, new FakePromotableResourceManager(), EnlistmentOptions.None);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public void Basic_assumptions_promotable_should_fail_if_durable_already_exists()
{
if (OperatingSystem.IsWindows())
{
// This test only work on Windows
TransactionManager.ImplicitDistributedTransactions = true;

using (var tx = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
Transaction.Current.EnlistDurable(FakePromotableResourceManager.ResourceManagerId, new FakePromotableResourceManager(), EnlistmentOptions.None);
Expand Down
1 change: 0 additions & 1 deletion src/NServiceBus.TransportTests/NServiceBusTransportTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ protected async Task StartPump(OnMessage onMessage, OnError onError, TransportTr

transport.TransportTransactionMode = transactionMode;


transportInfrastructure = await configurer.Configure(transport, hostSettings, new QueueAddress(InputQueueName), ErrorQueueName, cancellationToken);

receiver = transportInfrastructure.Receivers.Single().Value;
Expand Down

0 comments on commit 23acbe4

Please sign in to comment.