2019-03-05 10:14:01 -07:00
|
|
|
defmodule FarmbotCeleryScript.SchedulerTest do
|
2019-06-14 15:09:15 -06:00
|
|
|
use ExUnit.Case
|
2020-01-23 15:31:43 -07:00
|
|
|
use Mimic
|
2019-06-14 15:09:15 -06:00
|
|
|
alias FarmbotCeleryScript.{Scheduler, AST}
|
2020-01-23 15:31:43 -07:00
|
|
|
alias FarmbotCeleryScript.SysCalls.Stubs
|
2020-04-03 13:04:36 -06:00
|
|
|
import ExUnit.CaptureLog
|
2019-02-20 12:57:45 -07:00
|
|
|
|
2020-01-23 15:31:43 -07:00
|
|
|
setup :set_mimic_global
|
2020-01-25 10:48:52 -07:00
|
|
|
setup :verify_on_exit!
|
2020-01-17 08:58:53 -07:00
|
|
|
|
2020-01-23 15:31:43 -07:00
|
|
|
test "schedules a sequence to run in the future" do
|
|
|
|
expect(Stubs, :read_pin, 1, fn _num, _mode ->
|
|
|
|
23
|
|
|
|
end)
|
|
|
|
|
2020-01-23 15:40:19 -07:00
|
|
|
{:ok, sch} =
|
|
|
|
Scheduler.start_link([registry_name: :"#{:random.uniform()}"], [])
|
2019-02-20 12:57:45 -07:00
|
|
|
|
2019-06-14 15:09:15 -06:00
|
|
|
ast =
|
|
|
|
AST.Factory.new()
|
|
|
|
|> AST.Factory.rpc_request("hello world")
|
|
|
|
|> AST.Factory.read_pin(9, 0)
|
2019-02-20 12:57:45 -07:00
|
|
|
|
2019-06-14 15:09:15 -06:00
|
|
|
scheduled_time = DateTime.utc_now() |> DateTime.add(100, :millisecond)
|
2020-04-03 13:04:36 -06:00
|
|
|
# msg = "[info] Next execution is ready for execution: now"
|
2019-07-10 13:07:47 -06:00
|
|
|
{:ok, _} = Scheduler.schedule(sch, ast, scheduled_time, %{})
|
2020-01-17 08:58:53 -07:00
|
|
|
|
2019-07-11 12:31:32 -06:00
|
|
|
# Hack to force the scheduler to checkup instead of waiting the normal 15 seconds
|
2020-04-03 13:04:36 -06:00
|
|
|
assert capture_log(fn ->
|
|
|
|
send(sch, :checkup)
|
|
|
|
# Sorry.
|
|
|
|
Process.sleep(1100)
|
|
|
|
end) =~ "[info] Next execution is ready for execution: now"
|
2019-02-20 12:57:45 -07:00
|
|
|
end
|
|
|
|
end
|