fix: guard device cache refresh when stopped
This commit is contained in:
parent
59aee0416e
commit
35962c195b
2 changed files with 33 additions and 1 deletions
|
|
@ -46,7 +46,10 @@ defmodule Aprsme.DeviceCache do
|
|||
Refreshes the device cache from the database.
|
||||
"""
|
||||
def refresh_cache do
|
||||
GenServer.call(__MODULE__, :refresh_cache)
|
||||
case Process.whereis(__MODULE__) do
|
||||
nil -> :ok
|
||||
_pid -> GenServer.call(__MODULE__, :refresh_cache)
|
||||
end
|
||||
end
|
||||
|
||||
# Server callbacks
|
||||
|
|
|
|||
29
test/aprsme/device_cache_test.exs
Normal file
29
test/aprsme/device_cache_test.exs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
defmodule Aprsme.DeviceCacheTest do
|
||||
use ExUnit.Case, async: false
|
||||
|
||||
alias Aprsme.DeviceCache
|
||||
|
||||
setup do
|
||||
pid = Process.whereis(DeviceCache)
|
||||
|
||||
if pid do
|
||||
:erlang.unregister(DeviceCache)
|
||||
end
|
||||
|
||||
on_exit(fn ->
|
||||
if pid && !Process.whereis(DeviceCache) do
|
||||
true = Process.register(pid, DeviceCache)
|
||||
end
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
test "refresh_cache/0 returns :ok when the cache server is not running" do
|
||||
assert DeviceCache.refresh_cache() == :ok
|
||||
end
|
||||
|
||||
test "lookup_device/1 returns nil on cache miss without crashing when server is not running" do
|
||||
assert DeviceCache.lookup_device("TEST-DEVICE") == nil
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue