fix: guard connection monitor stats lookup
This commit is contained in:
parent
37c5932f96
commit
1631352786
2 changed files with 13 additions and 1 deletions
|
|
@ -77,7 +77,7 @@ defmodule Aprsme.ConnectionMonitor do
|
|||
Get current node statistics
|
||||
"""
|
||||
def get_stats do
|
||||
if cluster_enabled?() do
|
||||
if cluster_enabled?() and Process.whereis(__MODULE__) != nil do
|
||||
GenServer.call(__MODULE__, :get_stats)
|
||||
else
|
||||
%{connections: 0, cpu: 0.0, memory: 0.0}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,18 @@ defmodule Aprsme.ConnectionMonitorTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "cluster enabled without a running monitor" do
|
||||
test "get_stats/0 returns default stats instead of crashing" do
|
||||
Application.put_env(:aprsme, :cluster_enabled, true)
|
||||
|
||||
on_exit(fn ->
|
||||
Application.put_env(:aprsme, :cluster_enabled, false)
|
||||
end)
|
||||
|
||||
assert ConnectionMonitor.get_stats() == %{connections: 0, cpu: 0.0, memory: 0.0}
|
||||
end
|
||||
end
|
||||
|
||||
describe "cluster enabled" do
|
||||
setup do
|
||||
Application.put_env(:aprsme, :cluster_enabled, true)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue