-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 #192 from danielgerlag/issue-191
Order of compensation steps
- Loading branch information
Showing
5 changed files
with
95 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Workflow Core 1.6.8 | ||
|
||
* Fixed the order in which multiple compensating steps execute within a saga transaction. [Issue 191](https://github.com/danielgerlag/workflow-core/issues/191) |
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
83 changes: 83 additions & 0 deletions
83
test/WorkflowCore.IntegrationTests/Scenarios/MultistepCompensationScenario.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,83 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using WorkflowCore.Interface; | ||
using WorkflowCore.Models; | ||
using Xunit; | ||
using FluentAssertions; | ||
using System.Linq; | ||
using WorkflowCore.Testing; | ||
|
||
namespace WorkflowCore.IntegrationTests.Scenarios | ||
{ | ||
public class MultistepCompensationScenario : WorkflowTest<MultistepCompensationScenario.Workflow, Object> | ||
{ | ||
public class Workflow : IWorkflow | ||
{ | ||
public static int Compensation1Fired = -1; | ||
public static int Compensation2Fired = -1; | ||
public static int Compensation3Fired = -1; | ||
public static int Compensation4Fired = -1; | ||
public static int CompensationCounter = 0; | ||
|
||
public string Id => "CompensatingWorkflow"; | ||
public int Version => 1; | ||
public void Build(IWorkflowBuilder<object> builder) | ||
{ | ||
builder | ||
.StartWith(context => ExecutionResult.Next()) | ||
.Saga(x => x | ||
.StartWith(context => ExecutionResult.Next()) | ||
.CompensateWith(context => | ||
{ | ||
CompensationCounter++; | ||
Compensation1Fired = CompensationCounter; | ||
}) | ||
.Then(context => ExecutionResult.Next()) | ||
.CompensateWith(context => | ||
{ | ||
CompensationCounter++; | ||
Compensation2Fired = CompensationCounter; | ||
}) | ||
.Then(context => ExecutionResult.Next()) | ||
.CompensateWith(context => | ||
{ | ||
CompensationCounter++; | ||
Compensation3Fired = CompensationCounter; | ||
}) | ||
.Then(context => throw new Exception()) | ||
.CompensateWith(context => | ||
{ | ||
CompensationCounter++; | ||
Compensation4Fired = CompensationCounter; | ||
}) | ||
); | ||
} | ||
} | ||
|
||
public MultistepCompensationScenario() | ||
{ | ||
Setup(); | ||
Workflow.Compensation1Fired = -1; | ||
Workflow.Compensation2Fired = -1; | ||
Workflow.Compensation3Fired = -1; | ||
Workflow.Compensation4Fired = -1; | ||
Workflow.CompensationCounter = 0; | ||
} | ||
|
||
[Fact] | ||
public void MultiCompensationStepOrder() | ||
{ | ||
var workflowId = StartWorkflow(null); | ||
WaitForWorkflowToComplete(workflowId, TimeSpan.FromSeconds(30)); | ||
|
||
GetStatus(workflowId).Should().Be(WorkflowStatus.Complete); | ||
UnhandledStepErrors.Count.Should().Be(1); | ||
|
||
Workflow.Compensation1Fired.Should().Be(4); | ||
Workflow.Compensation2Fired.Should().Be(3); | ||
Workflow.Compensation3Fired.Should().Be(2); | ||
Workflow.Compensation4Fired.Should().Be(1); | ||
} | ||
} | ||
} |