Skip to content

Commit

Permalink
test: captures log only when really necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy committed Sep 10, 2024
1 parent 297ca06 commit c02f77f
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions test/tower_rollbar_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ defmodule TowerRollbarTest do
use ExUnit.Case
doctest TowerRollbar

import ExUnit.CaptureLog, only: [capture_log: 1]

setup do
bypass = Bypass.open()

Expand All @@ -19,7 +21,6 @@ defmodule TowerRollbarTest do
{:ok, bypass: bypass}
end

@tag capture_log: true
test "reports arithmetic error when a Plug.Conn NOT present", %{bypass: bypass} do
# ref message synchronization trick copied from
# https://github.com/PSPDFKit-labs/bypass/issues/112
Expand Down Expand Up @@ -54,7 +55,7 @@ defmodule TowerRollbarTest do
"method" =>
~s(anonymous fn/0 in TowerRollbarTest."test reports arithmetic error when a Plug.Conn NOT present"/1),
"filename" => "test/tower_rollbar_test.exs",
"lineno" => 69
"lineno" => 71
} = List.last(frames)
)

Expand All @@ -65,14 +66,15 @@ defmodule TowerRollbarTest do
|> Plug.Conn.resp(200, Jason.encode!(%{"ok" => true}))
end)

in_unlinked_process(fn ->
1 / 0
capture_log(fn ->
in_unlinked_process(fn ->
1 / 0

Check warning on line 71 in test/tower_rollbar_test.exs

View workflow job for this annotation

GitHub Actions / main (1.15, 25.3.2.12, plug_1_15)

the call to //2 will fail with ArithmeticError

Check warning on line 71 in test/tower_rollbar_test.exs

View workflow job for this annotation

GitHub Actions / main (1.15, 24.3.4.17, plug_1_14)

the call to //2 will fail with ArithmeticError

Check warning on line 71 in test/tower_rollbar_test.exs

View workflow job for this annotation

GitHub Actions / main (1.15, 25.3.2.12, plug_1_15)

the call to //2 will fail with ArithmeticError

Check warning on line 71 in test/tower_rollbar_test.exs

View workflow job for this annotation

GitHub Actions / main (1.15, 24.3.4.17, plug_1_14)

the call to //2 will fail with ArithmeticError
end)
end)

assert_receive({^ref, :sent}, 500)
end

@tag capture_log: true
test "reports arithmetic error when a Plug.Conn IS present with Plug.Cowboy", %{bypass: bypass} do
# ref message synchronization trick copied from
# https://github.com/PSPDFKit-labs/bypass/issues/112
Expand Down Expand Up @@ -130,12 +132,13 @@ defmodule TowerRollbarTest do
{Plug.Cowboy, plug: TowerRollbar.ErrorTestPlug, scheme: :http, port: plug_port}
)

{:ok, _response} = :httpc.request(:get, {url, [{~c"user-agent", "httpc client"}]}, [], [])
capture_log(fn ->
{:ok, _response} = :httpc.request(:get, {url, [{~c"user-agent", "httpc client"}]}, [], [])
end)

assert_receive({^ref, :sent}, 500)
end

@tag capture_log: true
test "reports arithmetic error when a Plug.Conn IS present with Bandit", %{bypass: bypass} do

Check failure on line 142 in test/tower_rollbar_test.exs

View workflow job for this annotation

GitHub Actions / main (1.15, 25.3.2.12, plug_1_15)

test reports arithmetic error when a Plug.Conn IS present with Bandit (TowerRollbarTest)
# ref message synchronization trick copied from
# https://github.com/PSPDFKit-labs/bypass/issues/112
Expand Down Expand Up @@ -189,9 +192,13 @@ defmodule TowerRollbarTest do
|> Plug.Conn.resp(200, Jason.encode!(%{"ok" => true}))
end)

start_supervised!({Bandit, plug: TowerRollbar.ErrorTestPlug, scheme: :http, port: plug_port})
capture_log(fn ->
start_supervised!(
{Bandit, plug: TowerRollbar.ErrorTestPlug, scheme: :http, port: plug_port}
)

{:ok, _response} = :httpc.request(:get, {url, [{~c"user-agent", "httpc client"}]}, [], [])
{:ok, _response} = :httpc.request(:get, {url, [{~c"user-agent", "httpc client"}]}, [], [])
end)

assert_receive({^ref, :sent}, 500)
end
Expand Down

0 comments on commit c02f77f

Please sign in to comment.