-
-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add isolated tests to sentry-rails (#1497)
* Add isolated test case for ActiveJob extension * Add a rake task for isolated specs
- Loading branch information
Showing
2 changed files
with
66 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# frozen_string_literal: true | ||
# for https://github.com/getsentry/sentry-ruby/issues/1249 | ||
require "active_job" | ||
require "active_support/all" | ||
require "sentry/rails" | ||
require "minitest/autorun" | ||
|
||
class TestApp < Rails::Application | ||
end | ||
|
||
IO_STUB = StringIO.new | ||
|
||
app = TestApp | ||
|
||
# to simulate jobs being load during the eager_load initializer | ||
app.initializer :eager_load! do | ||
Object.class_eval <<~CODE | ||
class ApplicationJob < ActiveJob::Base | ||
self.logger = Logger.new(IO_STUB) | ||
self.queue_adapter = :inline | ||
rescue_from Exception do |exception| | ||
logger.info(">>> RESCUED") | ||
end | ||
end | ||
class ErrorJob < ApplicationJob | ||
around_perform do |job, block| | ||
result = block.call | ||
logger.info(">>> I SHOULD NEVER BE EXECUTED!") | ||
end | ||
def perform | ||
1/0 | ||
end | ||
end | ||
CODE | ||
end | ||
|
||
app.config.eager_load = true | ||
app.initializer :sentry do | ||
Sentry.init do |config| | ||
config.logger = Logger.new(nil) | ||
config.dsn = 'https://2fb45f003d054a7ea47feb45898f7649@o447951.ingest.sentry.io/5434472' | ||
config.background_worker_threads = 0 | ||
end | ||
end | ||
|
||
app.initialize! | ||
|
||
class ActiveJobExtensionsTest < ActiveSupport::TestCase | ||
def test_the_extension_is_loaded_before_eager_load_is_called | ||
ErrorJob.perform_later | ||
|
||
log_result = IO_STUB.string | ||
assert_match(/RESCUED/, log_result, "ApplicationJob's rescue_from should be called") | ||
refute_match(/I SHOULD NEVER BE EXECUTED/, log_result, "ErrorJob's around_perform should not be triggered") | ||
end | ||
end |