-
Notifications
You must be signed in to change notification settings - Fork 0
/
crash_test.exs
43 lines (31 loc) · 941 Bytes
/
crash_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
defmodule CrashTest.GenServer do
use GenServer
@impl true
def init(_) do
{:ok, :alive}
end
@impl true
def handle_call({:crash, :sync}, _from, state) do
raise "oops"
IO.puts("I'm synchronously dead")
{:reply, state, state}
end
@impl true
def handle_call({:crash, :spawn}, _from, state) do
spawn_link(fn -> raise "oops" end)
IO.puts("I'm killed by my child process")
{:reply, state, state}
end
@impl true
def handle_call({:crash, :task}, _from, state) do
Task.start_link(fn -> raise "oops" end)
IO.puts("I'm fine")
Process.sleep(1000)
IO.puts("I should not be printed")
{:reply, state, state}
end
end
{:ok, server} = GenServer.start_link(CrashTest.GenServer, nil)
GenServer.call(server, {:crash, :task}) |> inspect |> IO.puts()
GenServer.call(server, {:crash, :spawn}) |> inspect |> IO.puts()
GenServer.call(server, {:crash, :sync}) |> inspect |> IO.puts()