From c02f77f626d9e04cec625fcdbb6a34c74c9996d1 Mon Sep 17 00:00:00 2001 From: Gonzalo <456459+grzuy@users.noreply.github.com> Date: Tue, 10 Sep 2024 12:17:13 -0300 Subject: [PATCH] test: captures log only when really necessary --- test/tower_rollbar_test.exs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/test/tower_rollbar_test.exs b/test/tower_rollbar_test.exs index 8f9fb4c..a9a6b5c 100644 --- a/test/tower_rollbar_test.exs +++ b/test/tower_rollbar_test.exs @@ -2,6 +2,8 @@ defmodule TowerRollbarTest do use ExUnit.Case doctest TowerRollbar + import ExUnit.CaptureLog, only: [capture_log: 1] + setup do bypass = Bypass.open() @@ -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 @@ -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) ) @@ -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 + 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 @@ -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 # ref message synchronization trick copied from # https://github.com/PSPDFKit-labs/bypass/issues/112 @@ -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