Skip to content

Instantly share code, notes, and snippets.

@arjan
Last active November 2, 2020 09:55
Show Gist options
  • Save arjan/1340a1ad6935eb5ca50c3513033cf2b1 to your computer and use it in GitHub Desktop.
Save arjan/1340a1ad6935eb5ca50c3513033cf2b1 to your computer and use it in GitHub Desktop.
defmodule DynamicSupervisorDeadlockTest do
require Logger
use ExUnit.Case
alias Horde.DynamicSupervisor
setup do
n1 = :"horde_#{:rand.uniform(100_000_000)}"
{:ok, horde_1_sup_pid} =
DynamicSupervisor.start_link(
name: n1,
strategy: :one_for_one,
delta_crdt_options: [sync_interval: 20]
)
# give the processes a couple ms to sync up
Process.sleep(100)
[
horde_1: n1,
horde_1_sup_pid: horde_1_sup_pid
]
end
defmodule MyServer do
use GenServer
def start_link(arg) do
GenServer.start_link(__MODULE__, arg)
end
def init(:crash) do
Process.sleep(200)
{:ok, {}, 0}
end
def init(:normal) do
Process.sleep(200)
{:ok, {}}
end
def handle_info(:timeout, state) do
raise "crash!"
end
end
test "restart / init deadlock", context do
{:ok, _} =
Horde.DynamicSupervisor.start_child(context.horde_1, %{
id: "1",
restart: :permanent,
start: {MyServer, :start_link, [:crash]}
})
|> IO.inspect(label: "d1")
{:ok, pid} =
Horde.DynamicSupervisor.start_child(context.horde_1, %{
id: "1",
restart: :permanent,
start: {MyServer, :start_link, [:normal]}
})
Process.sleep(500)
Horde.DynamicSupervisor.which_children(context.horde_1)
|> IO.inspect(label: "ccc")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment