test: LeaderElection direct handle_info callbacks
This commit is contained in:
parent
e1ef5b6b54
commit
59e478449a
1 changed files with 62 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue