diff --git a/test/inngest/function/cases/failure_handler_test.exs b/test/inngest/function/cases/failure_handler_test.exs new file mode 100644 index 0000000..5c06ef8 --- /dev/null +++ b/test/inngest/function/cases/failure_handler_test.exs @@ -0,0 +1,51 @@ +defmodule Inngest.Function.Cases.RetriableTest do + use ExUnit.Case, async: true + + alias Inngest.Test.DevServer + import Inngest.Test.Helper + + @default_sleep 10_000 + @event_name "test/plug.retriable" + + @tag :integration + test "should fail after retrying and failure is handled" do + event_id = send_test_event(@event_name) + Process.sleep(@default_sleep) + + assert {:ok, + %{ + "data" => [ + %{ + "run_id" => _run_id, + "output" => %{ + "error" => "invalid status code: 500", + "message" => stacktrace + }, + "status" => "Failed" + } + ] + }} = DevServer.run_ids(event_id) + + assert stacktrace =~ "YOLO!!!" + + {:ok, %{"data" => events}} = DevServer.list_events() + + assert %{"id" => failed_id} = + events + |> Enum.find(fn evt -> + Map.get(evt, "name") == "inngest/function.failed" && + get_in(evt, ["data", "event", "name"]) == @event_name + end) + + assert {:ok, + %{ + "data" => [ + %{ + "run_id" => _, + "output" => "error handled", + "status" => "Completed" + } + ] + }} = DevServer.run_ids(failed_id) + end +end diff --git a/test/inngest/function/cases/retriable_test.exs b/test/inngest/function/cases/retriable_test.exs deleted file mode 100644 index 3de337b..0000000 --- a/test/inngest/function/cases/retriable_test.exs +++ /dev/null @@ -1,30 +0,0 @@ -defmodule Inngest.Function.Cases.RetriableTest do - use ExUnit.Case, async: true - - alias Inngest.Test.DevServer - import Inngest.Test.Helper - - @default_sleep 10_000 - - @tag :integration - test "should fail after retrying" do - event_id = send_test_event("test/plug.retriable") - Process.sleep(@default_sleep) - - assert {:ok, - %{ - "data" => [ - %{ - "run_id" => _run_id, - "output" => %{ - "error" => "invalid status code: 500", - "message" => stacktrace - }, - "status" => "Failed" - } - ] - }} = DevServer.run_ids(event_id) - - assert stacktrace =~ "YOLO!!!" - end -end diff --git a/test/support/dev_server.ex b/test/support/dev_server.ex index dd55691..db68eea 100644 --- a/test/support/dev_server.ex +++ b/test/support/dev_server.ex @@ -40,6 +40,12 @@ defmodule Inngest.Test.DevServer do |> parse_resp() end + def list_events() do + client() + |> Tesla.get("/v1/events") + |> parse_resp() + end + defp client() do middleware = [ {Tesla.Middleware.BaseUrl, @base_url},