danielgerlag / workflow-core

Lightweight workflow engine for .NET Standard
MIT License
5.36k stars 1.2k forks source link

Saga doesn't skip over steps if error occurs within If #288

Closed rose-pace closed 5 years ago

rose-pace commented 5 years ago

In the following scenario if an error occurs within the If block at step4 I'd expect the workflow to continue on after the CompensateWith step but it actually picks up after the if at step6. If this is how sagas are supposed to work how would I get the behavior I would want where the workflow would pick up after the compensate step?

builder.StartWith<step1>()
  .Saga(saga => saga
    .StartWith<step2>()
    .If(data => someCondition)
      .Do(inner => inner
        .StartWith<step3>()
        .Then<step4>() // error occurs here
        .Then<step5>()
      )
    .Then<step6>() // after compensate workflow picks up here
    .Then<step7>()
  )
  .CompensateWith<MarkError>()
  .Then<FinalStep>() // I'd expect the workflow to pick up here after compensate
danielgerlag commented 5 years ago

Thanks for logging this... are you able to wrap this scenario into a failing integration test?

danielgerlag commented 5 years ago

Would you say this test mirrors your issue? https://github.com/danielgerlag/workflow-core/blob/master/test/WorkflowCore.IntegrationTests/Scenarios/NestedRetrySagaScenario.cs

rose-pace commented 5 years ago

I'm honestly having a difficult time following that test. I don't think it is exactly what I'm talking about since I only have the one compensate step for the entire saga. Do you want me to fork this project and add a test for my situation or just create a small project with a unit test?

danielgerlag commented 5 years ago

if you could even just paste a Test in the format of the one linked here, that would help me get to the bottom of it faster... I will spend some time drilling into it regardless, but that would be a huge help.

rose-pace commented 5 years ago

Here's a gist that recreates the issue: https://gist.github.com/rosspace/4ddc44a86b01e5648ab1b7d2a09173de

danielgerlag commented 5 years ago

Which version are you using?

rose-pace commented 5 years ago

1.6.8

danielgerlag commented 5 years ago

Try upgrading to the latest version and let me know if that helps.

rose-pace commented 5 years ago

Looks like that fixed the issue. I guess this had already been handled. Thanks for your help.