Nebo15 / sage

A dependency-free tool to run distributed transactions in Elixir, inspired by Sagas pattern.
MIT License
912 stars 40 forks source link

Ensure retrying doesn't clear effect state #53

Closed aspett closed 4 years ago

aspett commented 4 years ago

There is currently a bug in 0.6.0 where if you have a saga like


Sage.new()
|> Sage.run(:step1, transaction)
|> Sage.run(:step2, transaction, compensation_with_retry(3))
|> Sage.run(...)
|> Sage.execute(...)

Where step2 has a retry compensation, then the executor overrides the current execution state with only an incremented attempt number. This wipes out previous effects so you are unable to reuse step1's result on the retry of step2.

I have added a test to prove this bug - it fails without the fix, and passes with it.

Also fixes https://github.com/Nebo15/sage/issues/52

coveralls commented 4 years ago

Coverage Status

Coverage remained the same at 99.598% when pulling 6e38355dfa3d077c6fd55d24e29ea117a617b49e on aspett:fix-retry-state into e2ed3519c3e44899a0c377b0e07a9746d9c4d6a4 on Nebo15:master.

AndrewDryga commented 4 years ago

Great catch @aspett, thank you ❤️