Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests and resolve a bug in ExecutionBroadcaster #468

Merged
merged 3 commits into from
Nov 30, 2020

Conversation

pnezis
Copy link
Contributor

@pnezis pnezis commented Nov 30, 2020

Includes the following changes:

  • Make all tests work again (Tests are not executed properly #466) (had to include :crash_reason in logger metadata, and remove the custom :crash_reason from log_exception
  • Fix a bug in ExecutionBroadcaster . In case of invalid timezone no state was returned and as a result the GenServer was crashing:
22:41:29.638 [error] Invalid Timezone "foobar" provided for job :test.
22:41:29.655 [error] GenServer Jobex.Scheduler.ExecutionBroadcaster terminating
** (FunctionClauseError) no function clause matching in Quantum.ExecutionBroadcaster.sort_state/1
    (quantum) lib/quantum/execution_broadcaster.ex:299: Quantum.ExecutionBroadcaster.sort_state(:ok)
    (quantum) lib/quantum/execution_broadcaster.ex:170: Quantum.ExecutionBroadcaster.handle_event/2
    (quantum) lib/quantum/execution_broadcaster.ex:91: anonymous fn/2 in Quantum.ExecutionBroadcaster.handle_events/3
    (elixir) lib/enum.ex:1948: Enum."-reduce/3-lists^foldl/2-0-"/3
    (quantum) lib/quantum/execution_broadcaster.ex:90: Quantum.ExecutionBroadcaster.handle_events/3
    (gen_stage) lib/gen_stage.ex:2395: GenStage.consumer_dispatch/6
    (gen_stage) lib/gen_stage.ex:2574: GenStage.take_pc_events/3
    (stdlib) gen_server.erl:637: :gen_server.try_dispatch/4

Closes #466

- Include `:crash_reason` in logger metadata
- Remove `:crash_reason` from `log_exception`
- Change tests pattern matching
In case of invalid timezone no state was returned and as a result the
GenServer was crashing due to a `FunctionClauseError`
@coveralls
Copy link

coveralls commented Nov 30, 2020

Pull Request Test Coverage Report for Build 414bee22b4d6846254a703b342587281fcdb595c-PR-468

  • 3 of 5 (60.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.4%) to 86.188%

Changes Missing Coverage Covered Lines Changed/Added Lines %
lib/quantum/executor.ex 2 4 50.0%
Totals Coverage Status
Change from base Build 5c3e4a2b826c1f62256ca734506af6633d44b17c: -0.4%
Covered Lines: 312
Relevant Lines: 362

💛 - Coveralls

Exception.format(kind, reason, stacktrace),
crash_reason: crash_reason
)
Logger.error(Exception.format(kind, reason, stacktrace))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The crash reason metadata is actually quite important. Have a look at this PR: #464

We also discussed it together with Jose Va im via the mailing list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the docs (https://hexdocs.pm/logger/Logger.html) :crash_reason is always added automatically by Logger whenever possible

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pnezis Except we're logging manually and it can't do it automatically.

https://groups.google.com/g/elixir-lang-core/c/pWz-uTVMEVM/m/QGXncxD1AQAJ

Copy link
Member

@maennchen maennchen Nov 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defmodule CaptureLogErrorTest do
  use ExUnit.Case

  require Logger

  import ExUnit.CaptureLog

  test "greets the world" do
    assert capture_log(fn ->
             try do
               raise "foo"
             rescue
               error in RuntimeError ->
                 reason = Exception.normalize(:error, error, __STACKTRACE__)

                 Logger.error(
                   Exception.format(:error, reason, __STACKTRACE__),
                   crash_reason: {reason, __STACKTRACE__}
                 )
             end
           end) =~ "foo"
  end
end

This produces no error for me. Does it for you?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh this only happens in Elixir < 1.10.

Then I'd rather just raise the elixir requirement.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or detect the elixir version and only do it in Elixir ~> 1.10 with a TODO to remove the condition in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirm it is an elixir 1.9 issue. I will add the version check and push

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maennchen Added the version check.

@maennchen maennchen merged commit eca5ee0 into quantum-elixir:master Nov 30, 2020
@maennchen
Copy link
Member

@pnezis Thanks a lot again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tests are not executed properly
3 participants