Hello,
I’m getting an odd error in a test I’m trying to write for what I imagined would be a simple multi-node test setup. Basically, in production we run a few different nodes and I’m trying to write some test to verify that the module works. Unfortunately, I ran into a problem where the GenServer (App.Cluster.TaskTests) was not running on the slave nodes and so I tried to start it. Here is where I ran into the odd error.
Here is the relevant part of my code (in a test function):
defmodule App.Cluster.TaskTests do
use ExUnit.Case
alias App.Cluster.Tasks
setup_all do
:net_kernel.monitor_nodes(true)
:os.cmd('epmd -daemon')
Node.start(:test@localhost, :shortnames) |> IO.inspect()
children = ['child_1', 'child_2', 'child_3']
for child <- children do
IO.inspect(child)
{:ok, node} = :slave.start_link(:localhost, child) |> IO.inspect()
Node.spawn(node, Supervisor, :init, [[{App.Cluster.Tasks, {}}], strategy: :one_for_one]) |> IO.inspect()
end
on_exit(fn ->
[node() | Node.list()]
|> Enum.each(fn node -> Node.disconnect(node) end)
:net_kernel.monitor_nodes(false)
end)
end
end
And here is the confusing error I get:
17:41:46.361 [error] Process #PID<37495.88.0> on node :child_1@localhost raised an exception
** (UndefinedFunctionError) function Supervisor.init/2 is undefined or private
(elixir) Supervisor.init([{App.Cluster.Tasks, {}}], {:strategy, :one_for_one})
I get this error on each child, which of course causes any calls to the Tasks module to fail. I’m sure I’ve made some boneheaded mistake in setting this up (I’ve never worked with Nodes before), but I thought I would ask here and hope someone more experienced could spot my error.