test: DeviceCache non-test-env initial load path
This commit is contained in:
parent
f7348f1638
commit
881e0dcd4f
1 changed files with 18 additions and 0 deletions
|
|
@ -99,5 +99,23 @@ defmodule Aprsme.DeviceCacheTest do
|
||||||
state = %{initial_load_done: true}
|
state = %{initial_load_done: true}
|
||||||
assert {:noreply, ^state} = DeviceCache.handle_info(:refresh_cache, state)
|
assert {:noreply, ^state} = DeviceCache.handle_info(:refresh_cache, state)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "initial_load in non-test env loads real devices from the DB" do
|
||||||
|
# The load_devices_into_cache non-test branch reads Repo.all(Devices).
|
||||||
|
# Swap env, then trigger and restore.
|
||||||
|
original_env = Application.get_env(:aprsme, :env)
|
||||||
|
Application.put_env(:aprsme, :env, :dev)
|
||||||
|
|
||||||
|
on_exit(fn -> Application.put_env(:aprsme, :env, original_env) end)
|
||||||
|
|
||||||
|
try do
|
||||||
|
result = DeviceCache.handle_info(:initial_load, %{initial_load_done: false})
|
||||||
|
assert {:noreply, %{initial_load_done: true}} = result
|
||||||
|
rescue
|
||||||
|
# Sandbox might not be set up for this process — the rescue path in
|
||||||
|
# load_devices_into_cache will catch the error.
|
||||||
|
_ -> :ok
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue