Skip to content

Commit

Permalink
test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy committed Aug 1, 2024
1 parent f09e78e commit 5827e9c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/tower/ephemeral_reporter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@ defmodule Tower.EphemeralReporter do
end

@impl true
def report_event(%Event{time: time, kind: :error, reason: exception, stacktrace: stacktrace}) do
add_error(time, exception.__struct__, Exception.message(exception), stacktrace)
def report_event(%Event{id: id, time: time, kind: :error, reason: exception, stacktrace: stacktrace}) do
add_error(id, time, exception.__struct__, Exception.message(exception), stacktrace)
end

def report_event(%Event{time: time, kind: :exit, reason: reason, stacktrace: stacktrace}) do
add_error(time, :exit, reason, stacktrace)
def report_event(%Event{id: id, time: time, kind: :exit, reason: reason, stacktrace: stacktrace}) do
add_error(id, time, :exit, reason, stacktrace)
end

def report_event(%Event{time: time, kind: :throw, reason: reason, stacktrace: stacktrace}) do
add_error(time, :throw, reason, stacktrace)
def report_event(%Event{id: id, time: time, kind: :throw, reason: reason, stacktrace: stacktrace}) do
add_error(id, time, :throw, reason, stacktrace)
end

def report_event(%Event{time: time, kind: :message, level: level, reason: message}) do
def report_event(%Event{id: id, time: time, kind: :message, level: level, reason: message}) do
add(%{
id: id,
time: time,
level: level,
kind: nil,
Expand All @@ -36,8 +37,9 @@ defmodule Tower.EphemeralReporter do
Agent.get(__MODULE__, & &1)
end

defp add_error(time, kind, reason, stacktrace) do
defp add_error(id, time, kind, reason, stacktrace) do
add(%{
id: id,
time: time,
level: :error,
kind: kind,
Expand Down
26 changes: 26 additions & 0 deletions test/tower_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ defmodule TowerTest do
assert_eventually(
[
%{
id: id,
time: time,
level: :error,
kind: ArithmeticError,
Expand All @@ -35,6 +36,7 @@ defmodule TowerTest do
] = reported_events()
)

assert String.length(id) == 36
assert_in_delta(time, :logger.timestamp(), 100_000)
assert is_list(stacktrace)
end
Expand All @@ -48,6 +50,7 @@ defmodule TowerTest do
assert_eventually(
[
%{
id: id,
time: time,
level: :error,
kind: RuntimeError,
Expand All @@ -57,6 +60,7 @@ defmodule TowerTest do
] = reported_events()
)

assert String.length(id) == 36
assert_in_delta(time, :logger.timestamp(), 100_000)
assert is_list(stacktrace)
end
Expand All @@ -70,6 +74,7 @@ defmodule TowerTest do
assert_eventually(
[
%{
id: id,
time: time,
level: :error,
kind: :throw,
Expand All @@ -79,6 +84,7 @@ defmodule TowerTest do
] = reported_events()
)

assert String.length(id) == 36
assert_in_delta(time, :logger.timestamp(), 100_000)
assert is_list(stacktrace)
end
Expand All @@ -92,6 +98,7 @@ defmodule TowerTest do
assert_eventually(
[
%{
id: id,
time: time,
level: :error,
kind: :throw,
Expand All @@ -101,6 +108,7 @@ defmodule TowerTest do
] = reported_events()
)

assert String.length(id) == 36
assert_in_delta(time, :logger.timestamp(), 100_000)
assert is_list(stacktrace)
end
Expand All @@ -122,6 +130,7 @@ defmodule TowerTest do
assert_eventually(
[
%{
id: id,
time: time,
level: :error,
kind: :exit,
Expand All @@ -131,6 +140,7 @@ defmodule TowerTest do
] = reported_events()
)

assert String.length(id) == 36
assert_in_delta(time, :logger.timestamp(), 100_000)
assert is_list(stacktrace)
end
Expand All @@ -144,6 +154,7 @@ defmodule TowerTest do
assert_eventually(
[
%{
id: id,
time: time,
level: :error,
kind: :exit,
Expand All @@ -153,6 +164,7 @@ defmodule TowerTest do
] = reported_events()
)

assert String.length(id) == 36
assert_in_delta(time, :logger.timestamp(), 100_000)
assert is_list(stacktrace)
end
Expand All @@ -179,6 +191,7 @@ defmodule TowerTest do
assert_eventually(
[
%{
id: id,
time: time,
level: :error,
kind: nil,
Expand All @@ -188,6 +201,7 @@ defmodule TowerTest do
] = reported_events()
)

assert String.length(id) == 36
assert_in_delta(time, :logger.timestamp(), 100_000)
end

Expand All @@ -210,6 +224,7 @@ defmodule TowerTest do
assert_eventually(
[
%{
id: id,
time: time,
level: :error,
kind: nil,
Expand All @@ -220,6 +235,7 @@ defmodule TowerTest do
] = reported_events()
)

assert String.length(id) == 36
assert_in_delta(time, :logger.timestamp(), 100_000)
end

Expand All @@ -233,6 +249,7 @@ defmodule TowerTest do
assert_eventually(
[
%{
id: id,
time: time,
level: :critical,
kind: nil,
Expand All @@ -242,6 +259,7 @@ defmodule TowerTest do
] = reported_events()
)

assert String.length(id) == 36
assert_in_delta(time, :logger.timestamp(), 100_000)
end

Expand All @@ -251,6 +269,7 @@ defmodule TowerTest do
assert_eventually(
[
%{
id: id,
time: time,
level: :info,
kind: nil,
Expand All @@ -260,6 +279,7 @@ defmodule TowerTest do
] = reported_events()
)

assert String.length(id) == 36
assert_in_delta(time, :logger.timestamp(), 100_000)
end

Expand All @@ -276,6 +296,7 @@ defmodule TowerTest do
assert_eventually(
[
%{
id: id,
time: time,
level: :error,
kind: ArithmeticError,
Expand All @@ -285,6 +306,7 @@ defmodule TowerTest do
] = reported_events()
)

assert String.length(id) == 36
assert_in_delta(time, :logger.timestamp(), 100_000)
assert is_list(stacktrace)
end
Expand All @@ -303,6 +325,7 @@ defmodule TowerTest do
assert_eventually(
[
%{
id: id,
time: time,
level: :error,
kind: :throw,
Expand All @@ -312,6 +335,7 @@ defmodule TowerTest do
] = reported_events()
)

assert String.length(id) == 36
assert_in_delta(time, :logger.timestamp(), 100_000)
assert is_list(stacktrace)
end
Expand All @@ -330,6 +354,7 @@ defmodule TowerTest do
assert_eventually(
[
%{
id: id,
time: time,
level: :error,
kind: :exit,
Expand All @@ -339,6 +364,7 @@ defmodule TowerTest do
] = reported_events()
)

assert String.length(id) == 36
assert_in_delta(time, :logger.timestamp(), 100_000)
assert is_list(stacktrace)
end
Expand Down

0 comments on commit 5827e9c

Please sign in to comment.