Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/nodejs/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule NodeJS.Supervisor do
GenServer.call(pid, {module, args, [binary: binary, timeout: timeout, esm: esm]}, timeout)
catch
:exit, {:timeout, _} ->
{:error, "Call timed out."}
{:error, :timeout}

:exit, error ->
{:error, {:node_js_worker_exit, error}}
Expand Down Expand Up @@ -69,7 +69,7 @@ defmodule NodeJS.Supervisor do
run_in_transaction(module, args, opts)
catch
:exit, {:timeout, _} ->
{:error, "Call timed out."}
{:error, :timeout}
end
end

Expand All @@ -78,7 +78,8 @@ defmodule NodeJS.Supervisor do
|> call(args, opts)
|> case do
{:ok, result} -> result
{:error, message} -> raise NodeJS.Error, message: message
{:error, message} when is_binary(message) -> raise NodeJS.Error, message: message
{:error, :timeout} -> raise NodeJS.Error, message: "Call timed out."
end
end

Expand Down
14 changes: 7 additions & 7 deletions test/nodejs_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ defmodule NodeJS.Test do
assert_receive :received_timeout_3, 10
assert_receive :received_timeout_4, 10

assert {:error, "Call timed out."} = Task.await(task1)
assert {:error, "Call timed out."} = Task.await(task2)
assert {:error, "Call timed out."} = Task.await(task3)
assert {:error, "Call timed out."} = Task.await(task4)
assert {:error, :timeout} = Task.await(task1)
assert {:error, :timeout} = Task.await(task2)
assert {:error, :timeout} = Task.await(task3)
assert {:error, :timeout} = Task.await(task4)

# We should still get an answer here, before the timeout
assert {:ok, 1115} = NodeJS.call("slow-async-echo", [1115, 1])
Expand All @@ -176,7 +176,7 @@ defmodule NodeJS.Test do

describe "overriding call timeout" do
test "works, and you can tell because the slow function will time out" do
assert {:error, "Call timed out."} = NodeJS.call("slow-async-echo", [1111], timeout: 0)
assert {:error, :timeout} = NodeJS.call("slow-async-echo", [1111], timeout: 0)
assert_raise NodeJS.Error, fn -> NodeJS.call!("slow-async-echo", [1111], timeout: 0) end
assert {:ok, 1111} = NodeJS.call("slow-async-echo", [1111])
end
Expand All @@ -190,9 +190,9 @@ defmodule NodeJS.Test do

describe "Implementation details shouldn't leak:" do
test "Timeouts do not send stray messages to calling process" do
assert {:error, "Call timed out."} = NodeJS.call("slow-async-echo", [1111], timeout: 0)
assert {:error, :timeout} = NodeJS.call("slow-async-echo", [1111], timeout: 0)

refute_receive {_ref, {:error, "Call timed out."}}, 50
refute_receive {_ref, {:error, :timeout}}, 50
end

test "Crashes do not bring down the calling process" do
Expand Down