Skip to content

Commit

Permalink
Monitor tainted supervisors (#9)
Browse files Browse the repository at this point in the history
* Monitor supervisor on tainted mode

* Monitor tainted dynamic supervisors in the cluster

* Format
  • Loading branch information
studzien authored Oct 7, 2024
1 parent 0d8c9ae commit 18e5254
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/horde/dynamic_supervisor_impl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,9 @@ defmodule Horde.DynamicSupervisorImpl do
{name, %{status: :alive}} ->
[name]

{name, %{status: :tainted}} ->
[name]

_ ->
[]
end)
Expand Down
40 changes: 40 additions & 0 deletions test/dynamic_supervisor_taints_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,46 @@ defmodule DynamicSupervisorTaintsTest do
end
end

test "a process is migrated from the tainted node that's being shutdown" do
# given
{n1, n2} = {:horde_1, :horde_2}
start_supervised!({Horde.DynamicSupervisor, Keyword.merge(@common_opts, name: n1)})
child_spec = make_child_spec(1)

# process started on node 1, then tainted, then clustered with n2
{:ok, _} = Horde.DynamicSupervisor.start_child(n1, child_spec)
Horde.DynamicSupervisor.taint(n1)
start_supervised!({Horde.DynamicSupervisor, Keyword.merge(@common_opts, name: n2)})
cluster([n1, n2])

# when
Process.flag(:trap_exit, true)
Horde.DynamicSupervisor.stop(n1, :shutdown)

# then
eventually(fn -> assert count_local_children(n2) == 1 end)
end

test "a process is migrated from the tainted node that's being killed" do
# given
{n1, n2} = {:horde_1, :horde_2}
start_supervised!({Horde.DynamicSupervisor, Keyword.merge(@common_opts, name: n1)})
child_spec = make_child_spec(1)

# process started on node 1, then tainted, then clustered with n2
{:ok, _} = Horde.DynamicSupervisor.start_child(n1, child_spec)
Horde.DynamicSupervisor.taint(n1)
start_supervised!({Horde.DynamicSupervisor, Keyword.merge(@common_opts, name: n2)})
cluster([n1, n2])

# when
Process.flag(:trap_exit, true)
Horde.DynamicSupervisor.stop(n1, :kill)

# then
eventually(fn -> assert count_local_children(n2) == 1 end)
end

defp setup_cluster(size, opts) do
members =
for i <- 1..size do
Expand Down

0 comments on commit 18e5254

Please sign in to comment.