test: LeaderElection direct handle_info callbacks

This commit is contained in:
Graham McIntire 2026-04-23 18:19:41 -05:00
parent e1ef5b6b54
commit 59e478449a
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -340,4 +340,66 @@ defmodule Aprsme.Cluster.LeaderElectionTest do
assert Process.alive?(pid)
end
end
describe "handle_info(:check_cluster_and_elect) direct callback" do
test "no-ops when election already forced" do
state = %LeaderElection{
cluster_enabled: true,
election_forced: true
}
assert {:noreply, ^state} =
LeaderElection.handle_info(:check_cluster_and_elect, state)
end
test "reschedules itself when cluster has no peers yet" do
state = %LeaderElection{
cluster_enabled: true,
election_forced: false
}
assert {:noreply, new_state} =
LeaderElection.handle_info(:check_cluster_and_elect, state)
# Still not forced — we're still waiting.
refute new_state.election_forced
end
end
describe "handle_info(:force_election_timeout) direct callback" do
test "no-ops when election already forced" do
state = %LeaderElection{
cluster_enabled: true,
election_forced: true,
is_leader: false
}
assert {:noreply, ^state} =
LeaderElection.handle_info(:force_election_timeout, state)
end
test "no-ops when already leader" do
state = %LeaderElection{
cluster_enabled: true,
election_forced: false,
is_leader: true
}
assert {:noreply, ^state} =
LeaderElection.handle_info(:force_election_timeout, state)
end
test "forces election when not yet forced and not leader" do
state = %LeaderElection{
cluster_enabled: true,
election_forced: false,
is_leader: false
}
assert {:noreply, new_state} =
LeaderElection.handle_info(:force_election_timeout, state)
assert new_state.election_forced
end
end
end