Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/WorkflowCore/Services/ExecutionResultProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ public void HandleStepException(WorkflowInstance workflow, WorkflowDefinition de
{
var exceptionPointer = queue.Dequeue();
var exceptionStep = def.Steps.FindById(exceptionPointer.StepId);
var compensatingStepId = FindScopeCompensationStepId(workflow, def, exceptionPointer);
var errorOption = (exceptionStep.ErrorBehavior ?? (compensatingStepId.HasValue ? WorkflowErrorHandling.Compensate : def.DefaultErrorBehavior));
var shouldCompensate = ShouldCompensate(workflow, def, exceptionPointer);
var errorOption = (exceptionStep.ErrorBehavior ?? (shouldCompensate ? WorkflowErrorHandling.Compensate : def.DefaultErrorBehavior));

foreach (var handler in _errorHandlers.Where(x => x.Type == errorOption))
{
Expand All @@ -120,7 +120,7 @@ public void HandleStepException(WorkflowInstance workflow, WorkflowDefinition de
}
}

private int? FindScopeCompensationStepId(WorkflowInstance workflow, WorkflowDefinition def, ExecutionPointer currentPointer)
private bool ShouldCompensate(WorkflowInstance workflow, WorkflowDefinition def, ExecutionPointer currentPointer)
{
var scope = new Stack<string>(currentPointer.Scope);
scope.Push(currentPointer.Id);
Expand All @@ -130,11 +130,11 @@ public void HandleStepException(WorkflowInstance workflow, WorkflowDefinition de
var pointerId = scope.Pop();
var pointer = workflow.ExecutionPointers.FindById(pointerId);
var step = def.Steps.FindById(pointer.StepId);
if (step.CompensationStepId.HasValue)
return step.CompensationStepId.Value;
if ((step.CompensationStepId.HasValue) || (step.RevertChildrenAfterCompensation))
return true;
}

return null;
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public int this[string propertyName]

public class DataIOWorkflow : IWorkflow<MyDataClass>
{
public string Id => "DataIOWorkflow";
public string Id => "DynamicDataIOWorkflow";
public int Version => 1;
public void Build(IWorkflowBuilder<MyDataClass> builder)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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 FailingSagaScenario : WorkflowTest<FailingSagaScenario.Workflow, object>
{
public class Workflow : IWorkflow<object>
{
public static int Event1Fired;
public static int Event2Fired;
public static int Event3Fired;

public string Id => "NestedRetrySaga2Workflow";
public int Version => 1;
public void Build(IWorkflowBuilder<object> builder)
{
builder
.StartWith(context => ExecutionResult.Next())
.Saga(x => x
.StartWith(context => ExecutionResult.Next())
.If(data => true)
.Do(i => i
.StartWith(context =>
{
Event1Fired++;
throw new Exception();
})
)
.Then(context => Event2Fired++)
)
.OnError(WorkflowErrorHandling.Terminate)
.Then(context => Event3Fired++);
}
}

public FailingSagaScenario()
{
Setup();
Workflow.Event1Fired = 0;
Workflow.Event2Fired = 0;
Workflow.Event3Fired = 0;
}

[Fact]
public void Scenario()
{
var workflowId = StartWorkflow(null);
WaitForWorkflowToComplete(workflowId, TimeSpan.FromSeconds(30));

GetStatus(workflowId).Should().Be(WorkflowStatus.Terminated);
UnhandledStepErrors.Count.Should().Be(1);
Workflow.Event1Fired.Should().Be(1);
Workflow.Event2Fired.Should().Be(0);
Workflow.Event3Fired.Should().Be(0);
}
}
}