diff --git a/lib/sage/executor.ex b/lib/sage/executor.ex index 07683ed..c52faf8 100644 --- a/lib/sage/executor.ex +++ b/lib/sage/executor.ex @@ -258,7 +258,7 @@ defmodule Sage.Executor do end end - defp execute_compensation({{name, {:run, _transaction, :noop, _tx_opts} = operation}, state}, _opts) do + defp execute_compensation({{name, {_type, _transaction, :noop, _tx_opts} = operation}, state}, _opts) do {name, operation, :ok, nil, state} end diff --git a/test/sage/executor_test.exs b/test/sage/executor_test.exs index 85d645a..3d86ace 100644 --- a/test/sage/executor_test.exs +++ b/test/sage/executor_test.exs @@ -96,6 +96,20 @@ defmodule Sage.ExecutorTest do hook_assertion.() end + test "effects are not compensated for async operations with :noop compensation" do + {hook, hook_assertion} = final_hook_with_assertion(:error, a: :b) + + result = + new() + |> run_async(:step1, transaction_with_error(:t1), :noop) + |> finally(hook) + |> execute(a: :b) + + assert_effects([:t1]) + assert result == {:error, :t1} + hook_assertion.() + end + test "asynchronous transactions process metadata is copied from parent process" do test_pid = self() metadata = [test_pid: test_pid, test_ref: make_ref()] diff --git a/test/sage_test.exs b/test/sage_test.exs index 0ff5e28..f892050 100644 --- a/test/sage_test.exs +++ b/test/sage_test.exs @@ -209,7 +209,7 @@ defmodule SageTest do end end - describe "run_async/4" do + describe "run_async/5" do test "adds compensation via anonymous function to a sage" do tx = transaction(:t1) cmp = compensation() @@ -218,6 +218,13 @@ defmodule SageTest do assert MapSet.member?(names, :step1) end + test "adds noop compensation to a sage" do + tx = transaction(:t1) + %Sage{stages: stages, stage_names: names} = run_async(new(), :step1, tx, :noop, timeout: 5_000) + assert {:step1, {:run_async, tx, :noop, [timeout: 5_000]}} in stages + assert MapSet.member?(names, :step1) + end + test "adds compensation via mfa tuple to a sage" do tx = transaction(:t1) cmp = {__MODULE__, :dummy_compensation_for_mfa, []}