Skip to content

Commit

Permalink
add test for failure handler with retriable error test
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin67 committed Nov 24, 2023
1 parent f7c5e57 commit 960f19a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 30 deletions.
51 changes: 51 additions & 0 deletions test/inngest/function/cases/failure_handler_test.exs
Original file line number Diff line number Diff line change
@@ -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
30 changes: 0 additions & 30 deletions test/inngest/function/cases/retriable_test.exs

This file was deleted.

6 changes: 6 additions & 0 deletions test/support/dev_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit 960f19a

Please sign in to comment.