Skip to content

Commit

Permalink
Test sentry-resque without Rails, fix constantize issue (#2248)
Browse files Browse the repository at this point in the history
* Allow custom Redis instance for tests

You probably don't want the tests to use the same Redis you use for any
app development.

Maybe you want to use Docker with custom port:

    docker run --rm -it -p 16379:6379 redis:6

* Run sentry-resque specs without Rails

Tests and fixes #2243

* Run with latest `psych`

I think ruby/psych#655 was resolved long ago

* Note `constantize` sentry-resque fix in CHANGELOG
  • Loading branch information
dentarg authored Feb 20, 2024
1 parent 1d80548 commit 7702905
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 9 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/sentry_resque_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ jobs:
bundle install --jobs 4 --retry 3
bundle exec rake
- name: Run specs with Rails
env:
BUNDLE_GEMFILE: Gemfile_with_rails.rb
RUBYOPT: ${{ matrix.options.rubyopt }}
run: |
bundle install --jobs 4 --retry 3
bundle exec rake
- name: Upload Coverage
if: ${{ matrix.options.codecov }}
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Bug Fixes

- Fix undefined method 'constantize' issue in `sentry-resque` ([#2248](https://github.com/getsentry/sentry-ruby/pull/2248))
- Only instantiate SessionFlusher when the SDK is enabled under the current env [#2245](https://github.com/getsentry/sentry-ruby/pull/2245)
- Fixes [#2234](https://github.com/getsentry/sentry-ruby/issues/2234)

Expand Down
1 change: 1 addition & 0 deletions sentry-resque/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/_yardoc/
/coverage/
/doc/
Gemfile_with_rails.rb.lock
/pkg/
/spec/reports/
/tmp/
Expand Down
6 changes: 0 additions & 6 deletions sentry-resque/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ git_source(:github) { |name| "https://github.com/#{name}.git" }
# Specify your gem's dependencies in sentry-ruby.gemspec
gemspec
gem "sentry-ruby", path: "../sentry-ruby"
gem "sentry-rails", path: "../sentry-rails"

gem "rails"

# For https://github.com/ruby/psych/issues/655
gem "psych", "5.1.0"

gem "resque-retry", "~> 1.8"

Expand Down
4 changes: 4 additions & 0 deletions sentry-resque/Gemfile_with_rails.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eval_gemfile File.expand_path("Gemfile", __dir__)

gem "sentry-rails", path: "../sentry-rails"
gem "rails"
6 changes: 5 additions & 1 deletion sentry-resque/lib/sentry/resque.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ def record(queue, worker, payload, &block)

finish_transaction(transaction, 200)
rescue Exception => exception
klass = payload['class'].constantize
klass = if payload['class'].respond_to?(:constantize)
payload['class'].constantize
else
Object.const_get(payload['class'])
end

raise if Sentry.configuration.resque.report_after_job_retries &&
defined?(::Resque::Plugins::Retry) == 'constant' &&
Expand Down
9 changes: 7 additions & 2 deletions sentry-resque/spec/sentry/resque_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,16 @@ def self.perform(msg)
end
end

context "with ActiveJob" do
rails_gems = begin
require "rails"
require "active_job"
require "sentry-rails"
true
rescue LoadError
false
end

context "with ActiveJob" do
class AJMessageJob < ActiveJob::Base
self.queue_adapter = :resque

Expand Down Expand Up @@ -290,7 +295,7 @@ def perform
expect(event[:contexts][:"Active-Job"][:job_class]).to eq("AJFailedJob")
end
end
end
end if rails_gems
end


Expand Down
3 changes: 3 additions & 0 deletions sentry-resque/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
require "resque"
require "resque-retry"

# Allow customization of the Redis instance used for tests
Resque.redis = ENV["REDIS_URL"] if ENV.key?("REDIS_URL")

# To workaround https://github.com/steveklabnik/mono_logger/issues/13
# Note: mono_logger is resque's default logger
Resque.logger = ::Logger.new(nil)
Expand Down

0 comments on commit 7702905

Please sign in to comment.