Set `async` to `false` in a few missing places

pull/1182/head
Rick Carlino 2020-03-30 17:43:29 -05:00
parent 9a5b927953
commit 33b0947c7a
8 changed files with 49 additions and 35 deletions

View File

@ -2,12 +2,14 @@ use Mix.Config
if Mix.env() == :test do
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,
FarmbotExt.Bootstrap.Supervisor
]
Enum.map(list, mapper)
end

View File

@ -4,13 +4,11 @@ defmodule FarmbotExt do
use Application
def start(_type, _args) do
opts = [strategy: :one_for_one, name: __MODULE__]
Supervisor.start_link(children(), opts)
Supervisor.start_link(children(), opts())
end
# This only exists because I was getting too many crashed
# supervisor reports in the test suite (distraction from
# real test failures).
def opts, do: [strategy: :one_for_one, name: __MODULE__]
def children do
config = Application.get_env(:farmbot_ext, __MODULE__) || []
Keyword.get(config, :children, [FarmbotExt.Bootstrap])

View File

@ -44,6 +44,8 @@ defmodule FarmbotExt.API.ImageUploader do
end
def handle_continue([], state), do: {:noreply, state, @checkup_time_ms}
# WIP - RC
def handle_call(:noop, _, s), do: {:reply, :ok, s}
# the meta here is likely inaccurate here because of
# pulling the location data from the cache instead of from the firmware
@ -52,12 +54,16 @@ defmodule FarmbotExt.API.ImageUploader do
defp try_upload(image_filename) do
%{x: x, y: y, z: z} = BotState.fetch().location_data.position
meta = %{x: x, y: y, z: z, name: Path.rootname(image_filename)}
finalize(image_filename, API.upload_image(image_filename, meta))
end
with {:ok, %{status: s, body: _body}} when s > 199 and s < 300 <-
API.upload_image(image_filename, meta) do
FarmbotCore.Logger.success(3, "Uploaded image: #{image_filename}")
File.rm(image_filename)
end
defp finalize(file, {:ok, %{status: s, body: _}}) when s > 199 and s < 300 do
FarmbotCore.Logger.success(3, "Uploaded image: #{file}")
File.rm(file)
end
defp finalize(fname, other) do
FarmbotCore.Logger.success(3, "Upload Error (#{fname}): #{inspect(other)}")
end
# Stolen from

View File

@ -1,5 +1,5 @@
defmodule AutoSyncAssetHandlerTest do
use ExUnit.Case, async: true
use ExUnit.Case, async: false
use Mimic
setup :verify_on_exit!

View File

@ -1,6 +1,6 @@
defmodule AutoSyncChannelTest do
require Helpers
use ExUnit.Case, async: true
use ExUnit.Case, async: false
use Mimic
alias FarmbotExt.AMQP.AutoSyncChannel

View File

@ -1,5 +1,5 @@
defmodule FarmbotExt.AMQP.BotStateChannelTest do
use ExUnit.Case
use ExUnit.Case, async: false
use Mimic
# alias FarmbotExt.AMQP.BotStateChannel

View File

@ -1,26 +1,39 @@
defmodule FarmbotExt.API.ImageUploaderTest do
use ExUnit.Case
use ExUnit.Case, async: false
use Mimic
alias FarmbotExt.API.ImageUploader
setup :verify_on_exit!
setup :set_mimic_global
# TODO: Get some single pixel jpg, jpeg, png, gif files.
# TODO: Stub `API.upload_image`
# upload_image_mock = fn _fname ->
# raise "HMMM...."
# end
test "force checkup" do
Helpers.NamedProcess.start_link({ImageUploader, "force_checkup_test"})
# TODO: Get some single pixel jpg, jpeg, png, gif files.
# TODO: Stub `API.upload_image`
pid =
if Process.whereis(ImageUploader) do
Process.whereis(ImageUploader)
else
{:ok, p} = ImageUploader.start_link([])
p
end
# upload_image_mock = fn _fname ->
# raise "HMMM...."
# end
# ref = Process.monitor(pid)
Enum.map(
["a.jpg", "b.jpeg", "c.png", "d.gif"],
fn fname -> File.touch!("/tmp/images/#{fname}") end
)
mapper = fn fname ->
File.touch!("/tmp/images/#{fname}")
end
expect(FarmbotExt.API, :upload_image, 1, fn _image_filename, _meta ->
IO.puts("-=-=--==-=-=-=-=--=-=-==--=-=-=-==-")
{:ok, %{status: 201, body: %{}}}
end)
# expect(FarmbotExt.API, :upload_image, 3, upload_image_mock)
["a.jpg", "b.jpeg", "c.png", "d.gif"] |> Enum.map(mapper)
ImageUploader.force_checkup()
Process.sleep(100)
assert_receive :lol
GenServer.call(pid, :noop)
send(pid, :timeout)
end
end

View File

@ -13,14 +13,10 @@ Mimic.copy(FarmbotExt.API.Preloader)
Mimic.copy(FarmbotExt.API)
Mimic.copy(FarmbotExt.AMQP.AutoSyncAssetHandler)
timeout = System.get_env("EXUNIT_TIMEOUT")
timeout = System.get_env("EXUNIT_TIMEOUT") || "5000"
System.put_env("LOG_SILENCE", "true")
if timeout do
ExUnit.start(assert_receive_timeout: String.to_integer(timeout))
else
ExUnit.start()
end
ExUnit.start(assert_receive_timeout: String.to_integer(timeout))
defmodule Helpers do
defmacro expect_log(message) do
@ -31,4 +27,3 @@ defmodule Helpers do
end
end
end