FarmbotExt: Dont supervise anything in :test

pull/1182/head
Rick Carlino 2020-03-26 17:06:55 -05:00
parent 128ed8ec43
commit 9a5b927953
7 changed files with 40 additions and 51 deletions

View File

@ -1,6 +1,13 @@
use Mix.Config
if Mix.env() == :test do
config :farmbot_ext, FarmbotExt, children: []
config :farmbot_ext, FarmbotExt.Bootstrap.Supervisor, children: []
mapper = fn mod -> config :farmbot_ext, mod, children: [] end
list = [
FarmbotExt,
FarmbotExt.AMQP.ChannelSupervisor,
FarmbotExt.API.DirtyWorker.Supervisor,
FarmbotExt.API.EagerLoader.Supervisor,
FarmbotExt.Bootstrap.Supervisor,
]
Enum.map(list, mapper)
end

View File

@ -19,17 +19,19 @@ defmodule FarmbotExt.AMQP.ChannelSupervisor do
end
def init([token]) do
jwt = JWT.decode!(token)
Supervisor.init(children(JWT.decode!(token)), strategy: :one_for_one)
end
children = [
def children(jwt) do
config = Application.get_env(:farmbot_ext, __MODULE__) || []
Keyword.get(config, :children, [
{TelemetryChannel, [jwt: jwt]},
{LogChannel, [jwt: jwt]},
{PingPongChannel, [jwt: jwt]},
{BotStateChannel, [jwt: jwt]},
{AutoSyncChannel, [jwt: jwt]},
{CeleryScriptChannel, [jwt: jwt]}
]
Supervisor.init(children, strategy: :one_for_one)
])
end
end

View File

@ -10,14 +10,17 @@ defmodule FarmbotExt.AMQP.Supervisor do
end
def init([]) do
Supervisor.init(children(), strategy: :one_for_all)
end
def children do
token = get_config_value(:string, "authorization", "token")
email = get_config_value(:string, "authorization", "email")
config = Application.get_env(:farmbot_ext, __MODULE__) || []
children = [
Keyword.get(config, :children, [
{FarmbotExt.AMQP.ConnectionWorker, [token: token, email: email]},
{FarmbotExt.AMQP.ChannelSupervisor, [token]}
]
Supervisor.init(children, strategy: :one_for_all)
])
end
end

View File

@ -33,7 +33,13 @@ defmodule FarmbotExt.API.DirtyWorker.Supervisor do
@impl Supervisor
def init(_args) do
children = [
Supervisor.init(children(), strategy: :one_for_one)
end
def children do
config = Application.get_env(:farmbot_ext, __MODULE__) || []
Keyword.get(config, :children, [
{DirtyWorker, Device},
{DirtyWorker, DeviceCert},
{DirtyWorker, FbosConfig},
@ -50,8 +56,6 @@ defmodule FarmbotExt.API.DirtyWorker.Supervisor do
{DirtyWorker, Sensor},
{DirtyWorker, Sequence},
{DirtyWorker, Tool}
]
Supervisor.init(children, strategy: :one_for_one)
])
end
end

View File

@ -39,7 +39,13 @@ defmodule FarmbotExt.API.EagerLoader.Supervisor do
@impl Supervisor
def init(_args) do
children = [
Supervisor.init(children(), strategy: :one_for_one)
end
def children do
config = Application.get_env(:farmbot_ext, __MODULE__) || []
Keyword.get(config, :children, [
{EagerLoader, Device},
{EagerLoader, FarmEvent},
{EagerLoader, FarmwareEnv},
@ -56,8 +62,6 @@ defmodule FarmbotExt.API.EagerLoader.Supervisor do
{EagerLoader, Sensor},
{EagerLoader, Sequence},
{EagerLoader, Tool}
]
Supervisor.init(children, strategy: :one_for_one)
])
end
end

View File

@ -17,6 +17,7 @@ defmodule FarmbotExt.Bootstrap.Supervisor do
def children() do
config = Application.get_env(:farmbot_ext, __MODULE__) || []
Keyword.get(config, :children, [
FarmbotExt.API.EagerLoader.Supervisor,
FarmbotExt.API.DirtyWorker.Supervisor,

View File

@ -32,35 +32,3 @@ defmodule Helpers do
end
end
defmodule Helpers.NamedProcess do
@moduledoc """
NOTE: Inspired by ex_venture test suite. Thanks! -RC
Register a globaly named process that fakes out a normally real process.
Any messages this process receives will forward them to the test process via `send`.
"""
use GenServer
@doc """
Link a new process to the test process
This takes place outside of the supervision tree, so the process does
not hang around.
"""
def start_link(name) do
GenServer.start_link(__MODULE__, [caller: self(), name: name], [name: {:global, name}])
end
@impl true
def init(state) do
{:ok, Enum.into(state, %{})}
end
@impl true
def handle_cast(message, state) do
send(state.caller, {state.name, {:cast, message}})
{:noreply, state}
end
end