Skip to content

Commit ca7d0ed

Browse files
committed
genserver timeout test
1 parent 4bba523 commit ca7d0ed

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/logger_backend_test.exs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,40 @@ defmodule Sentry.LoggerBackendTest do
149149
end)
150150
end
151151

152+
test "GenServer timeout makes call to Sentry API" do
153+
self_pid = self()
154+
Process.flag(:trap_exit, true)
155+
bypass = Bypass.open()
156+
157+
Bypass.expect(bypass, fn conn ->
158+
{:ok, body, conn} = Plug.Conn.read_body(conn)
159+
json = Jason.decode!(body)
160+
161+
exception_value =
162+
List.first(json["exception"])
163+
|> Map.fetch!("value")
164+
165+
assert String.contains?(exception_value, "{:timeout, {GenServer, :call")
166+
167+
assert conn.request_path == "/api/1/store/"
168+
assert conn.method == "POST"
169+
send(self_pid, "API called")
170+
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
171+
end)
172+
173+
modify_env(:sentry, dsn: "http://public:secret@localhost:#{bypass.port}/1")
174+
175+
{:ok, pid1} = Sentry.TestGenServer.start_link(self_pid)
176+
177+
capture_log(fn ->
178+
Task.start(fn ->
179+
GenServer.call(pid1, {:sleep, 20}, 1)
180+
end)
181+
182+
assert_receive "API called"
183+
end)
184+
end
185+
152186
test "only sends one error when a Plug process crashes" do
153187
Code.compile_string("""
154188
defmodule SentryApp do

0 commit comments

Comments
 (0)