Skip to content

Commit

Permalink
test bandit exit
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy committed Aug 19, 2024
1 parent 665ded9 commit 6900aff
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/plug/tower_plug_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,37 @@ defmodule TowerPlugTest do
assert Plug.Conn.request_url(plug_conn) == url
end

@tag capture_log: true
test "reports abnormal exit during plug dispatch with Bandit" do
# An ephemeral port hopefully not being in the host running this code
plug_port = 51111
url = "http://127.0.0.1:#{plug_port}/abnormal-exit"

start_link_supervised!({Bandit, plug: Tower.TestPlug, scheme: :http, port: plug_port})

:httpc.request(url)

assert_eventually(
[
%{
id: id,
datetime: datetime,
level: :error,
kind: :exit,
reason: :abnormal,
stacktrace: stacktrace
# Bandit doesn't handle exits so it doesn't provide the conn in the metadata
# plug_conn: %Plug.Conn{} = plug_conn
}
] = Tower.EphemeralReporter.events()
)

assert String.length(id) == 36
assert recent_datetime?(datetime)
assert is_list(stacktrace)
# assert Plug.Conn.request_url(plug_conn) == url
end

test "reports message plug_conn manually" do
Tower.handle_message(
:info,
Expand Down

0 comments on commit 6900aff

Please sign in to comment.