diff --git a/farmbot_ext/.gitignore b/farmbot_ext/.gitignore index 9575d916..93ae1d43 100644 --- a/farmbot_ext/.gitignore +++ b/farmbot_ext/.gitignore @@ -23,3 +23,4 @@ erl_crash.dump farmbot_ext-*.tar *.sqlite3 +*.coverdata diff --git a/farmbot_ext/lib/farmbot_ext/amqp/auto_sync_channel.ex b/farmbot_ext/lib/farmbot_ext/amqp/auto_sync_channel.ex index dc7409d5..a261ed30 100644 --- a/farmbot_ext/lib/farmbot_ext/amqp/auto_sync_channel.ex +++ b/farmbot_ext/lib/farmbot_ext/amqp/auto_sync_channel.ex @@ -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 diff --git a/farmbot_ext/test/farmbot_ext/amqp/auto_sync_channel_test.exs b/farmbot_ext/test/farmbot_ext/amqp/auto_sync_channel_test.exs index a412bbcd..86cca22f 100644 --- a/farmbot_ext/test/farmbot_ext/amqp/auto_sync_channel_test.exs +++ b/farmbot_ext/test/farmbot_ext/amqp/auto_sync_channel_test.exs @@ -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