Unit tests for AutoSyncChannel.terminate
parent
5ef5bb7b91
commit
1d85b95a48
|
@ -23,3 +23,4 @@ erl_crash.dump
|
|||
farmbot_ext-*.tar
|
||||
|
||||
*.sqlite3
|
||||
*.coverdata
|
||||
|
|
|
@ -68,12 +68,15 @@ defmodule FarmbotExt.AMQP.AutoSyncChannel do
|
|||
def terminate(reason, state) do
|
||||
FarmbotCore.Logger.error(1, "Disconnected from AutoSync channel: #{inspect(reason)}")
|
||||
# If a channel was still open, close it.
|
||||
if state.chan, do: ConnectionWorker.close_channel(state.chan)
|
||||
if state.chan do
|
||||
ConnectionWorker.close_channel(state.chan)
|
||||
end
|
||||
|
||||
try do
|
||||
EagerLoader.Supervisor.drop_all_cache()
|
||||
catch
|
||||
_, _ -> :ok
|
||||
_, _ ->
|
||||
:ok
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -54,14 +54,15 @@ defmodule AutoSyncChannelTest do
|
|||
# test suite except under limited circumstances.
|
||||
expect(ConnectionWorker, :maybe_connect_autosync, ok1)
|
||||
|
||||
stub(FarmbotExt.API.EagerLoader.Supervisor, :drop_all_cache, ok)
|
||||
expect(FarmbotExt.API.EagerLoader.Supervisor, :drop_all_cache, ok)
|
||||
{:ok, pid} = AutoSyncChannel.start_link([jwt: jwt], [])
|
||||
pid
|
||||
end
|
||||
|
||||
test "init / terminate" do
|
||||
# Most assertions are handled by `gnerate_pid`:
|
||||
pid = generate_pid()
|
||||
assert %{chan: nil, conn: nil, preloaded: true} == AutoSyncChannel.network_status(pid)
|
||||
Process.exit(pid, :normal)
|
||||
GenServer.stop(pid, :normal)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue