Set `async` to `false` in a few missing places
parent
9a5b927953
commit
33b0947c7a
|
@ -2,12 +2,14 @@ use Mix.Config
|
||||||
|
|
||||||
if Mix.env() == :test do
|
if Mix.env() == :test do
|
||||||
mapper = fn mod -> config :farmbot_ext, mod, children: [] end
|
mapper = fn mod -> config :farmbot_ext, mod, children: [] end
|
||||||
|
|
||||||
list = [
|
list = [
|
||||||
FarmbotExt,
|
FarmbotExt,
|
||||||
FarmbotExt.AMQP.ChannelSupervisor,
|
FarmbotExt.AMQP.ChannelSupervisor,
|
||||||
FarmbotExt.API.DirtyWorker.Supervisor,
|
FarmbotExt.API.DirtyWorker.Supervisor,
|
||||||
FarmbotExt.API.EagerLoader.Supervisor,
|
FarmbotExt.API.EagerLoader.Supervisor,
|
||||||
FarmbotExt.Bootstrap.Supervisor,
|
FarmbotExt.Bootstrap.Supervisor
|
||||||
]
|
]
|
||||||
|
|
||||||
Enum.map(list, mapper)
|
Enum.map(list, mapper)
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,13 +4,11 @@ defmodule FarmbotExt do
|
||||||
use Application
|
use Application
|
||||||
|
|
||||||
def start(_type, _args) do
|
def start(_type, _args) do
|
||||||
opts = [strategy: :one_for_one, name: __MODULE__]
|
Supervisor.start_link(children(), opts())
|
||||||
Supervisor.start_link(children(), opts)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# This only exists because I was getting too many crashed
|
def opts, do: [strategy: :one_for_one, name: __MODULE__]
|
||||||
# supervisor reports in the test suite (distraction from
|
|
||||||
# real test failures).
|
|
||||||
def children do
|
def children do
|
||||||
config = Application.get_env(:farmbot_ext, __MODULE__) || []
|
config = Application.get_env(:farmbot_ext, __MODULE__) || []
|
||||||
Keyword.get(config, :children, [FarmbotExt.Bootstrap])
|
Keyword.get(config, :children, [FarmbotExt.Bootstrap])
|
||||||
|
|
|
@ -44,6 +44,8 @@ defmodule FarmbotExt.API.ImageUploader do
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_continue([], state), do: {:noreply, state, @checkup_time_ms}
|
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
|
# the meta here is likely inaccurate here because of
|
||||||
# pulling the location data from the cache instead of from the firmware
|
# 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
|
defp try_upload(image_filename) do
|
||||||
%{x: x, y: y, z: z} = BotState.fetch().location_data.position
|
%{x: x, y: y, z: z} = BotState.fetch().location_data.position
|
||||||
meta = %{x: x, y: y, z: z, name: Path.rootname(image_filename)}
|
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 <-
|
defp finalize(file, {:ok, %{status: s, body: _}}) when s > 199 and s < 300 do
|
||||||
API.upload_image(image_filename, meta) do
|
FarmbotCore.Logger.success(3, "Uploaded image: #{file}")
|
||||||
FarmbotCore.Logger.success(3, "Uploaded image: #{image_filename}")
|
File.rm(file)
|
||||||
File.rm(image_filename)
|
end
|
||||||
end
|
|
||||||
|
defp finalize(fname, other) do
|
||||||
|
FarmbotCore.Logger.success(3, "Upload Error (#{fname}): #{inspect(other)}")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Stolen from
|
# Stolen from
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
defmodule AutoSyncAssetHandlerTest do
|
defmodule AutoSyncAssetHandlerTest do
|
||||||
use ExUnit.Case, async: true
|
use ExUnit.Case, async: false
|
||||||
use Mimic
|
use Mimic
|
||||||
|
|
||||||
setup :verify_on_exit!
|
setup :verify_on_exit!
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
defmodule AutoSyncChannelTest do
|
defmodule AutoSyncChannelTest do
|
||||||
require Helpers
|
require Helpers
|
||||||
use ExUnit.Case, async: true
|
use ExUnit.Case, async: false
|
||||||
use Mimic
|
use Mimic
|
||||||
alias FarmbotExt.AMQP.AutoSyncChannel
|
alias FarmbotExt.AMQP.AutoSyncChannel
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
defmodule FarmbotExt.AMQP.BotStateChannelTest do
|
defmodule FarmbotExt.AMQP.BotStateChannelTest do
|
||||||
use ExUnit.Case
|
use ExUnit.Case, async: false
|
||||||
use Mimic
|
use Mimic
|
||||||
|
|
||||||
# alias FarmbotExt.AMQP.BotStateChannel
|
# alias FarmbotExt.AMQP.BotStateChannel
|
||||||
|
|
|
@ -1,26 +1,39 @@
|
||||||
defmodule FarmbotExt.API.ImageUploaderTest do
|
defmodule FarmbotExt.API.ImageUploaderTest do
|
||||||
use ExUnit.Case
|
use ExUnit.Case, async: false
|
||||||
use Mimic
|
use Mimic
|
||||||
alias FarmbotExt.API.ImageUploader
|
alias FarmbotExt.API.ImageUploader
|
||||||
setup :verify_on_exit!
|
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
|
test "force checkup" do
|
||||||
Helpers.NamedProcess.start_link({ImageUploader, "force_checkup_test"})
|
pid =
|
||||||
# TODO: Get some single pixel jpg, jpeg, png, gif files.
|
if Process.whereis(ImageUploader) do
|
||||||
# TODO: Stub `API.upload_image`
|
Process.whereis(ImageUploader)
|
||||||
|
else
|
||||||
|
{:ok, p} = ImageUploader.start_link([])
|
||||||
|
p
|
||||||
|
end
|
||||||
|
|
||||||
# upload_image_mock = fn _fname ->
|
# ref = Process.monitor(pid)
|
||||||
# raise "HMMM...."
|
Enum.map(
|
||||||
# end
|
["a.jpg", "b.jpeg", "c.png", "d.gif"],
|
||||||
|
fn fname -> File.touch!("/tmp/images/#{fname}") end
|
||||||
|
)
|
||||||
|
|
||||||
mapper = fn fname ->
|
expect(FarmbotExt.API, :upload_image, 1, fn _image_filename, _meta ->
|
||||||
File.touch!("/tmp/images/#{fname}")
|
IO.puts("-=-=--==-=-=-=-=--=-=-==--=-=-=-==-")
|
||||||
end
|
{: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()
|
ImageUploader.force_checkup()
|
||||||
Process.sleep(100)
|
GenServer.call(pid, :noop)
|
||||||
assert_receive :lol
|
send(pid, :timeout)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,14 +13,10 @@ Mimic.copy(FarmbotExt.API.Preloader)
|
||||||
Mimic.copy(FarmbotExt.API)
|
Mimic.copy(FarmbotExt.API)
|
||||||
Mimic.copy(FarmbotExt.AMQP.AutoSyncAssetHandler)
|
Mimic.copy(FarmbotExt.AMQP.AutoSyncAssetHandler)
|
||||||
|
|
||||||
timeout = System.get_env("EXUNIT_TIMEOUT")
|
timeout = System.get_env("EXUNIT_TIMEOUT") || "5000"
|
||||||
System.put_env("LOG_SILENCE", "true")
|
System.put_env("LOG_SILENCE", "true")
|
||||||
|
|
||||||
if timeout do
|
ExUnit.start(assert_receive_timeout: String.to_integer(timeout))
|
||||||
ExUnit.start(assert_receive_timeout: String.to_integer(timeout))
|
|
||||||
else
|
|
||||||
ExUnit.start()
|
|
||||||
end
|
|
||||||
|
|
||||||
defmodule Helpers do
|
defmodule Helpers do
|
||||||
defmacro expect_log(message) do
|
defmacro expect_log(message) do
|
||||||
|
@ -31,4 +27,3 @@ defmodule Helpers do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue