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

Test sentry-resque without Rails, fix constantize issue #2248

Merged
merged 4 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Comment on lines -11 to -12
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes tests pass on Ruby 2.4 (fail log before this change)


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 @@

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'])

Check warning on line 38 in sentry-resque/lib/sentry/resque.rb

View check run for this annotation

Codecov / codecov/patch

sentry-resque/lib/sentry/resque.rb#L38

Added line #L38 was not covered by tests
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
Loading