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

Sentry reports exception already caught by assert_raises #2277

Closed
amo13 opened this issue Mar 19, 2024 · 2 comments
Closed

Sentry reports exception already caught by assert_raises #2277

amo13 opened this issue Mar 19, 2024 · 2 comments
Assignees
Labels

Comments

@amo13
Copy link

amo13 commented Mar 19, 2024

I do not understand why my test cases following this pattern send exceptions to sentry. The assert_raises statement rescues the exception and does not reraise it. How can it still slip through and be reported to the sentry server? And what do I need to change to a) prevent these job tests to send report exception correctly caught by the assert_raises helper, and b) still report uncaught exceptions in the test environment?

require "test_helper"
require "minitest/mock"

class My::JobTest < ActiveJob::TestCase
  test "raise My::Error" do
    assert_raises My::Error do
      Ext::Api.stub :getsize, {size_gb: 1} do
        My::Job.perform_now
      end
    end
  end
end
class My::Job < ApplicationJob
  queue_as :myqueue
  queue_with_priority 5

  def perform(args)
    raise My::Error
  end
end

I can't imagine that this happens because I have configured GoodJob which is not supported by this gem because the tests use the test adapter anyway.
Any guidance with this would be greatly appreciated.

@sl0thentr0py
Copy link
Member

sl0thentr0py commented Mar 19, 2024

this is because we patch active job and thus the sentry stuff runs before your assert_raises

def perform_now
if !Sentry.initialized? || already_supported_by_sentry_integration?
super
else
SentryReporter.record(self) do
super
end
end
end

You can manually set config.enabled_environments = %w[development production], does so that sentry does not send in test, does that work for you or do you need to disable just this one usage?

edit: nvm sorry didn't read that you still want to send uncaught exceptions in tests.

Then your next best way is to use config.before_send and filter out those particular exceptions.
https://docs.sentry.io/platforms/ruby/configuration/filtering/#using-

@amo13
Copy link
Author

amo13 commented Mar 19, 2024

Thank you a lot for clarifying this!

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

No branches or pull requests

2 participants