Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4401 from Particular/hotfix-6.0.5
Reuse of incoming message as saga timeout message causes duplicate handler invocations
- Loading branch information
Showing
7 changed files
with
167 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...erviceBus.AcceptanceTests/Sagas/When_handling_message_with_handler_and_timeout_handler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
namespace NServiceBus.AcceptanceTests.Sagas | ||
{ | ||
using System; | ||
using System.Threading.Tasks; | ||
using AcceptanceTesting; | ||
using EndpointTemplates; | ||
using Features; | ||
using NUnit.Framework; | ||
|
||
public class When_handling_message_with_handler_and_timeout_handler : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public async Task Should_not_invoke_timeout_handler() | ||
{ | ||
var context = await Scenario.Define<Context>() | ||
.WithEndpoint<TimeoutSagaEndpoint>(g => g.When(session => session.SendLocal(new StartSagaMessage | ||
{ | ||
SomeId = Guid.NewGuid() | ||
}))) | ||
.Done(c => c.HandlerInvoked || c.TimeoutHandlerInvoked) | ||
.Run(); | ||
|
||
Assert.True(context.HandlerInvoked, "Regular handler should be invoked"); | ||
Assert.False(context.TimeoutHandlerInvoked, "Timeout handler should not be invoked"); | ||
} | ||
|
||
public class Context : ScenarioContext | ||
{ | ||
public bool TimeoutHandlerInvoked { get; set; } | ||
public bool HandlerInvoked { get; set; } | ||
} | ||
|
||
public class TimeoutSagaEndpoint : EndpointConfigurationBuilder | ||
{ | ||
public TimeoutSagaEndpoint() | ||
{ | ||
EndpointSetup<DefaultServer>(config => config.EnableFeature<TimeoutManager>()); | ||
} | ||
|
||
public class HandlerAndTimeoutSaga : Saga<HandlerAndTimeoutSagaData>, IAmStartedByMessages<StartSagaMessage>, | ||
IHandleTimeouts<StartSagaMessage> | ||
{ | ||
public Context TestContext { get; set; } | ||
|
||
public Task Handle(StartSagaMessage message, IMessageHandlerContext context) | ||
{ | ||
TestContext.HandlerInvoked = true; | ||
return Task.FromResult(0); | ||
} | ||
|
||
public Task Timeout(StartSagaMessage message, IMessageHandlerContext context) | ||
{ | ||
TestContext.TimeoutHandlerInvoked = true; | ||
return Task.FromResult(0); | ||
} | ||
|
||
protected override void ConfigureHowToFindSaga(SagaPropertyMapper<HandlerAndTimeoutSagaData> mapper) | ||
{ | ||
mapper.ConfigureMapping<StartSagaMessage>(m => m.SomeId) | ||
.ToSaga(s => s.SomeId); | ||
} | ||
} | ||
|
||
public class HandlerAndTimeoutSagaData : IContainSagaData | ||
{ | ||
public virtual Guid SomeId { get; set; } | ||
public virtual Guid Id { get; set; } | ||
public virtual string Originator { get; set; } | ||
public virtual string OriginalMessageId { get; set; } | ||
} | ||
} | ||
|
||
public class StartSagaMessage : IMessage | ||
{ | ||
public Guid SomeId { get; set; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters