-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
82 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,70 @@ | ||
defmodule TowerRollbarTest do | ||
use ExUnit.Case | ||
doctest TowerRollbar | ||
|
||
setup do | ||
bypass = Bypass.open() | ||
|
||
Application.put_env(:tower, :reporters, [TowerRollbar.Reporter]) | ||
Application.put_env(:tower_rollbar, :rollbar_base_url, "http://localhost:#{bypass.port}/") | ||
Application.put_env(:tower_rollbar, :environment, :test) | ||
Application.put_env(:tower_rollbar, :access_token, "fake-token") | ||
Application.put_env(:tower_rollbar, :enabled, true) | ||
|
||
Tower.attach() | ||
|
||
on_exit(fn -> | ||
Tower.detach() | ||
end) | ||
|
||
{:ok, bypass: bypass} | ||
end | ||
|
||
@tag capture_log: true | ||
test "reports arithmetic error", %{bypass: bypass} do | ||
# ref message synchronization trick copied from | ||
# https://github.com/PSPDFKit-labs/bypass/issues/112 | ||
parent = self() | ||
ref = make_ref() | ||
|
||
Bypass.expect_once(bypass, "POST", "/item", fn conn -> | ||
{:ok, body, conn} = Plug.Conn.read_body(conn) | ||
|
||
assert( | ||
%{ | ||
"data" => %{ | ||
"environment" => "test", | ||
"body" => %{ | ||
"trace" => %{ | ||
"exception" => %{ | ||
"class" => "ArithmeticError", | ||
"message" => "bad argument in arithmetic expression" | ||
} | ||
} | ||
} | ||
} | ||
} = Jason.decode!(body) | ||
) | ||
|
||
send(parent, {ref, :sent}) | ||
|
||
conn | ||
|> Plug.Conn.put_resp_content_type("application/json") | ||
|> Plug.Conn.resp(200, Jason.encode!(%{"ok" => true})) | ||
end) | ||
|
||
in_unlinked_process(fn -> | ||
1 / 0 | ||
Check warning on line 57 in test/tower_rollbar_test.exs
|
||
end) | ||
|
||
assert_receive({^ref, :sent}, 500) | ||
end | ||
|
||
defp in_unlinked_process(fun) when is_function(fun, 0) do | ||
{:ok, pid} = Task.Supervisor.start_link() | ||
|
||
pid | ||
|> Task.Supervisor.async_nolink(fun) | ||
|> Task.yield() | ||
end | ||
end |