-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for `step.invoke` --------- Co-authored-by: Darwin D Wu <[email protected]>
- Loading branch information
Showing
12 changed files
with
227 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
defmodule Inngest.Function.Cases.InvokeTest do | ||
use ExUnit.Case, async: true | ||
|
||
alias Inngest.Test.DevServer | ||
import Inngest.Test.Helper | ||
|
||
@default_sleep 5_000 | ||
|
||
@tag :integration | ||
test "should run successfully" do | ||
event_id = send_test_event("test/invoke.caller") | ||
Process.sleep(@default_sleep) | ||
|
||
assert {:ok, | ||
%{ | ||
"data" => [ | ||
%{ | ||
"output" => %{"data" => "INVOKED!"}, | ||
"run_id" => _, | ||
"status" => "Completed" | ||
} | ||
] | ||
}} = DevServer.run_ids(event_id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
defmodule Inngest.Function.Cases.InvokeTimeoutTest do | ||
use ExUnit.Case, async: true | ||
|
||
alias Inngest.Test.DevServer | ||
import Inngest.Test.Helper | ||
|
||
@default_sleep 5_000 | ||
|
||
@tag :integration | ||
test "should fail with timeout error" do | ||
event_id = send_test_event("test/invoke.timeout.caller") | ||
Process.sleep(@default_sleep) | ||
|
||
assert { | ||
:ok, | ||
%{ | ||
"data" => [ | ||
%{ | ||
"output" => %{ | ||
"name" => error, | ||
"message" => message, | ||
"stack" => _ | ||
}, | ||
"run_id" => _, | ||
"status" => "Failed" | ||
} | ||
] | ||
} | ||
} = DevServer.run_ids(event_id) | ||
|
||
assert error == "Elixir.Inngest.NonRetriableError" | ||
|
||
assert message == | ||
"InngestInvokeTimeoutError: Timed out waiting for invoked function to complete" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
defmodule Inngest.Test.Case.InvokeCallerFn do | ||
@moduledoc false | ||
|
||
use Inngest.Function | ||
|
||
@func %FnOpts{id: "invoke-caller", name: "Invoke Caller"} | ||
@trigger %Trigger{event: "test/invoke.caller"} | ||
|
||
@impl true | ||
def exec(ctx, %{step: step} = _args) do | ||
_ = step.run(ctx, "step-1", fn -> %{hello: "world"} end) | ||
|
||
res = | ||
step.invoke(ctx, "caller", %{ | ||
function: Inngest.Test.Case.InvokedFn, | ||
data: %{yolo: true}, | ||
timeout: "10s" | ||
}) | ||
|
||
{:ok, res} | ||
end | ||
end | ||
|
||
defmodule Inngest.Test.Case.InvokedFn do | ||
@moduledoc false | ||
|
||
use Inngest.Function | ||
|
||
@func %FnOpts{id: "invoke-target", name: "Invoked"} | ||
@trigger %Trigger{event: "test/invoked"} | ||
|
||
@impl true | ||
def exec(ctx, %{step: step} = _args) do | ||
_ = step.run(ctx, "invoked", fn -> "YO!" end) | ||
|
||
{:ok, "INVOKED!"} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
defmodule Inngest.Test.Case.InvokeTimeoutCallerFn do | ||
@moduledoc false | ||
|
||
use Inngest.Function | ||
|
||
@func %FnOpts{id: "invoke-timeout-caller", name: "Invoke Timeout Caller"} | ||
@trigger %Trigger{event: "test/invoke.timeout.caller"} | ||
|
||
@impl true | ||
def exec(ctx, %{step: step} = _args) do | ||
_ = step.run(ctx, "step-1", fn -> %{hello: "world"} end) | ||
|
||
_ = | ||
step.invoke(ctx, "caller", %{ | ||
function: Inngest.Test.Case.InvokedLongFn, | ||
data: %{yolo: true}, | ||
timeout: "1s" | ||
}) | ||
|
||
{:ok, "TIMED OUT"} | ||
end | ||
end | ||
|
||
defmodule Inngest.Test.Case.InvokedLongFn do | ||
@moduledoc false | ||
|
||
use Inngest.Function | ||
|
||
@func %FnOpts{id: "invoke-long-target", name: "Invoked Long"} | ||
@trigger %Trigger{event: "test/invoked.long"} | ||
|
||
@impl true | ||
def exec(ctx, %{step: step} = _args) do | ||
_ = step.sleep(ctx, "sleep", "5s") | ||
_ = step.run(ctx, "invoked", fn -> "YO!" end) | ||
|
||
{:ok, "INVOKED!"} | ||
end | ||
end |