Skip to content

Commit

Permalink
Fix tests and resolve a bug in ExecutionBroadcaster (#468)
Browse files Browse the repository at this point in the history
* Fix test issues

- Include `:crash_reason` in logger metadata
- Remove `:crash_reason` from `log_exception`
- Change tests pattern matching

* Return `state` in case of invalid timezone

In case of invalid timezone no state was returned and as a result the
GenServer was crashing due to a `FunctionClauseError`

* Do not set crash_reason if elixir < 1.10
  • Loading branch information
pnezis authored Nov 30, 2020
1 parent 5c3e4a2 commit eca5ee0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
use Mix.Config
config :logger, :console, metadata: :all
config :logger, :console, metadata: [:all, :crash_reason]
config :elixir, :time_zone_database, Tzdata.TimeZoneDatabase
2 changes: 2 additions & 0 deletions lib/quantum/execution_broadcaster.ex
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ defmodule Quantum.ExecutionBroadcaster do
job: job,
error: e
)

state
end

defp get_next_execution_time(
Expand Down
23 changes: 14 additions & 9 deletions lib/quantum/executor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,20 @@ defmodule Quantum.Executor do
def log_exception(kind, reason, stacktrace) do
reason = Exception.normalize(kind, reason, stacktrace)

crash_reason =
case kind do
:throw -> {{:nocatch, reason}, stacktrace}
_ -> {reason, stacktrace}
end
# TODO: Remove in a future version and make elixir 1.10 minimum requirement
if Version.match?(System.version(), "< 1.10.0") do
Logger.error(Exception.format(kind, reason, stacktrace))
else
crash_reason =
case kind do
:throw -> {{:nocatch, reason}, stacktrace}
_ -> {reason, stacktrace}
end

Logger.error(
Exception.format(kind, reason, stacktrace),
crash_reason: crash_reason
)
Logger.error(
Exception.format(kind, reason, stacktrace),
crash_reason: crash_reason
)
end
end
end
8 changes: 3 additions & 5 deletions test/quantum/executor_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ defmodule Quantum.ExecutorTest do
assert :ok == wait_for_termination(task)
end)

assert logs =~ ~r/type=error/
assert logs =~ ~r/[error]/
assert logs =~ ~r/Execution failed for job/
assert_receive %{test_id: ^test_id, type: :start}

Expand Down Expand Up @@ -409,8 +409,6 @@ defmodule Quantum.ExecutorTest do
assert :ok == wait_for_termination(task)
end)

assert logs =~ ~r/type=exit/
assert logs =~ ~r/value=failure/
assert logs =~ "[error] ** (exit) :failure"
assert_receive %{test_id: ^test_id, type: :start}

Expand Down Expand Up @@ -463,8 +461,8 @@ defmodule Quantum.ExecutorTest do
end)

'#Ref' ++ rest = :erlang.ref_to_list(ref)
assert logs =~ "type=throw"
assert logs =~ "value=#{rest}"
assert logs =~ "[error] ** (throw)"
assert logs =~ "#{rest}"
assert_receive %{test_id: ^test_id, type: :start}

assert_receive %{
Expand Down

0 comments on commit eca5ee0

Please sign in to comment.