Skip to content

Commit

Permalink
Improve error output tests per recommendation
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrudel committed Dec 4, 2024
1 parent e2a8ea7 commit 5dd2943
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
19 changes: 10 additions & 9 deletions test/bandit/http1/request_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ defmodule HTTP1RequestTest do
Process.sleep(1100)
end)

assert errors =~ "(Bandit.HTTPError) Body read timeout"
assert errors =~ "[error] ** (Bandit.HTTPError) Body read timeout"
end

def short_body(conn) do
Expand Down Expand Up @@ -1054,7 +1054,8 @@ defmodule HTTP1RequestTest do
Process.sleep(100)
end)

assert errors =~ "(ArgumentError) upgrade to unsupported not supported by Bandit.Adapter"
assert errors =~
"[error] ** (ArgumentError) upgrade to unsupported not supported by Bandit.Adapter"
end

def upgrade_unsupported(conn) do
Expand Down Expand Up @@ -1086,7 +1087,7 @@ defmodule HTTP1RequestTest do
Process.sleep(100)
end)

assert errors =~ "(Bandit.HTTPError) HTTP method POST unsupported"
assert errors =~ "[error] ** (Bandit.HTTPError) HTTP method POST unsupported"
end

test "returns a 400 and errors loudly in cases where an upgrade is indicated but upgrade header is incorrect",
Expand All @@ -1113,7 +1114,7 @@ defmodule HTTP1RequestTest do
end)

assert errors =~
"(Bandit.HTTPError) 'upgrade' header must contain 'websocket', got [\"NOPE\"]"
"[error] ** (Bandit.HTTPError) 'upgrade' header must contain 'websocket', got [\"NOPE\"]"
end

test "returns a 400 and errors loudly in cases where an upgrade is indicated but connection header is incorrect",
Expand All @@ -1140,7 +1141,7 @@ defmodule HTTP1RequestTest do
end)

assert errors =~
"(Bandit.HTTPError) 'connection' header must contain 'upgrade', got [\"NOPE\"]"
"[error] ** (Bandit.HTTPError) 'connection' header must contain 'upgrade', got [\"NOPE\"]"
end

test "returns a 400 and errors loudly in cases where an upgrade is indicated but key header is incorrect",
Expand All @@ -1165,7 +1166,7 @@ defmodule HTTP1RequestTest do
Process.sleep(100)
end)

assert errors =~ "(Bandit.HTTPError) 'sec-websocket-key' header is absent"
assert errors =~ "[error] ** (Bandit.HTTPError) 'sec-websocket-key' header is absent"
end

test "returns a 400 and errors loudly in cases where an upgrade is indicated but version header is incorrect",
Expand All @@ -1192,7 +1193,7 @@ defmodule HTTP1RequestTest do
end)

assert errors =~
"(Bandit.HTTPError) 'sec-websocket-version' header must equal '13', got [\"99\"]"
"[error] ** (Bandit.HTTPError) 'sec-websocket-version' header must equal '13', got [\"99\"]"
end

test "returns a 400 and errors loudly if websocket support is not enabled", context do
Expand Down Expand Up @@ -2398,7 +2399,7 @@ defmodule HTTP1RequestTest do
Process.sleep(500)
end)

assert output =~ "(Bandit.TransportError) Unrecoverable error: closed"
assert output =~ "[error] ** (Bandit.TransportError) Unrecoverable error: closed"
refute output =~ "IMPOSSIBLE"
assert ThousandIsland.connection_pids(context[:server_pid]) == {:ok, []}
end
Expand Down Expand Up @@ -2462,7 +2463,7 @@ defmodule HTTP1RequestTest do
Transport.close(client)

output = capture_log(fn -> Process.sleep(500) end)
assert output =~ "(Bandit.TransportError) Unrecoverable error: closed"
assert output =~ "[error] ** (Bandit.TransportError) Unrecoverable error: closed"
refute output =~ "IMPOSSIBLE"
assert ThousandIsland.connection_pids(context[:server_pid]) == {:ok, []}
end
Expand Down
16 changes: 10 additions & 6 deletions test/bandit/http2/protocol_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ defmodule HTTP2ProtocolTest do
end)

assert errors =~
"(Bandit.HTTP2.Errors.ConnectionError) Received WINDOW_UPDATE in idle state"
"[error] ** (Bandit.HTTP2.Errors.ConnectionError) Received WINDOW_UPDATE in idle state"
end

test "it should shut down the stream gracefully and log when encountering a stream error",
Expand All @@ -114,7 +114,7 @@ defmodule HTTP2ProtocolTest do
end)

assert errors =~
"(Bandit.HTTP2.Errors.StreamError) Received trailers with pseudo headers"
"[error] ** (Bandit.HTTP2.Errors.StreamError) Received trailers with pseudo headers"
end

test "stream errors are short logged by default", context do
Expand Down Expand Up @@ -1952,7 +1952,8 @@ defmodule HTTP2ProtocolTest do
Process.sleep(100)
end)

assert errors =~ "Terminating stream in remote_closed state"
assert errors =~
"[error] ** (Bandit.HTTP2.Errors.StreamError) Terminating stream in remote_closed state"
end

def no_response_get(conn) do
Expand All @@ -1974,7 +1975,8 @@ defmodule HTTP2ProtocolTest do
Process.sleep(100)
end)

assert errors =~ "Terminating stream in open state"
assert errors =~
"[error] ** (Bandit.HTTP2.Errors.StreamError) Terminating stream in open state"
end

def no_response_post(conn) do
Expand Down Expand Up @@ -2007,7 +2009,8 @@ defmodule HTTP2ProtocolTest do
Process.sleep(100)
end)

assert errors =~ "(Bandit.TransportError) Received RST_STREAM from client: unknown (99)"
assert errors =~
"[error] ** (Bandit.TransportError) Received RST_STREAM from client: unknown (99)"
end

def expect_reset(conn) do
Expand All @@ -2024,7 +2027,8 @@ defmodule HTTP2ProtocolTest do
Process.sleep(200)
end)

assert errors =~ "(Bandit.TransportError) Received RST_STREAM from client: unknown (99)"
assert errors =~
"[error] ** (Bandit.TransportError) Received RST_STREAM from client: unknown (99)"
end

def write_after_delay(conn) do
Expand Down

0 comments on commit 5dd2943

Please sign in to comment.