diff --git a/.github/workflows/sentry_sidekiq_test.yml b/.github/workflows/sentry_sidekiq_test.yml index 692007f49..650c35077 100644 --- a/.github/workflows/sentry_sidekiq_test.yml +++ b/.github/workflows/sentry_sidekiq_test.yml @@ -71,8 +71,6 @@ jobs: redis-version: ${{ (contains(matrix.sidekiq_version, '7.0') || contains(matrix.sidekiq_version, '8.0')) && 6 || 5 }} - name: Run specs with Sidekiq ${{ matrix.sidekiq_version }} - env: - WITH_SENTRY_RAILS: 1 run: bundle exec rake - name: Upload Coverage diff --git a/sentry-sidekiq/Rakefile b/sentry-sidekiq/Rakefile index 13afab191..9207ea5fe 100644 --- a/sentry-sidekiq/Rakefile +++ b/sentry-sidekiq/Rakefile @@ -1,10 +1,13 @@ # frozen_string_literal: true require "bundler/gem_tasks" -require "rspec/core/rake_task" +require_relative "../lib/sentry/test/rake_tasks" -RSpec::Core::RakeTask.new(:spec).tap do |task| - task.rspec_opts = "--order rand" -end +Sentry::Test::RakeTasks.define_spec_tasks( + spec_pattern: "spec/sentry/**/*_spec.rb", + spec_rspec_opts: "--order rand --format progress", + isolated_specs_pattern: "spec/isolated/**/*_spec.rb", + isolated_rspec_opts: "--format progress" +) -task default: :spec +task default: [:spec, :"spec:isolated"] diff --git a/sentry-sidekiq/spec/sentry/rails_spec.rb b/sentry-sidekiq/spec/isolated/rails_spec.rb similarity index 59% rename from sentry-sidekiq/spec/sentry/rails_spec.rb rename to sentry-sidekiq/spec/isolated/rails_spec.rb index 4026ed4d6..1a64c376b 100644 --- a/sentry-sidekiq/spec/sentry/rails_spec.rb +++ b/sentry-sidekiq/spec/isolated/rails_spec.rb @@ -1,14 +1,16 @@ # frozen_string_literal: true -return unless ENV["WITH_SENTRY_RAILS"] - -require "logger" +begin + require "simplecov" + SimpleCov.command_name "SidekiqRails" +rescue LoadError +end -require "rails" require "sentry-rails" -require "spec_helper" -require "action_controller/railtie" +# This MUST be required after sentry-rails because it requires sentry-sidekiq +# which checks if Railtie is defined to properly set things up +require_relative "../spec_helper" class TestApp < Rails::Application end @@ -23,15 +25,9 @@ def self.name app.config.hosts = nil app.config.secret_key_base = "test" app.config.eager_load = false + app.initializer :configure_sentry do - Sentry.init do |config| - config.release = 'beta' - config.dsn = "dummy://12345:67890@sentry.localdomain:3000/sentry/42" - config.transport.transport_class = Sentry::DummyTransport - # for sending events synchronously - config.background_worker_threads = 0 - yield(config, app) if block_given? - end + perform_basic_setup end app.initialize! diff --git a/sentry-sidekiq/spec/sentry/sidekiq/cron/job_spec.rb b/sentry-sidekiq/spec/sentry/sidekiq/cron/job_spec.rb index 087810f3e..9a0b3384d 100644 --- a/sentry-sidekiq/spec/sentry/sidekiq/cron/job_spec.rb +++ b/sentry-sidekiq/spec/sentry/sidekiq/cron/job_spec.rb @@ -109,10 +109,10 @@ expect(::Sidekiq::Queue.new.size).to eq(1) expect(transport.events.count).to eq(1) - event = transport.events.last - expect(event.spans.count).to eq(1) - expect(event.spans[0][:op]).to eq("queue.publish") - expect(event.spans[0][:data]['messaging.destination.name']).to eq('default') + + span = transport.events.last.spans.detect { |span| span[:op] == "queue.publish" } + expect(span[:op]).to eq("queue.publish") + expect(span[:data]['messaging.destination.name']).to eq('default') end it 'adds job to sidekiq within transaction' do @@ -124,12 +124,16 @@ expect(::Sidekiq::Queue.new.size).to eq(2) expect(transport.events.count).to eq(2) events = transport.events - expect(events[0].spans.count).to eq(1) - expect(events[0].spans[0][:op]).to eq("queue.publish") - expect(events[0].spans[0][:data]['messaging.destination.name']).to eq('default') - expect(events[1].spans.count).to eq(1) - expect(events[1].spans[0][:op]).to eq("queue.publish") - expect(events[1].spans[0][:data]['messaging.destination.name']).to eq('default') + + span = events[0].spans.detect { |span| span[:op] == "queue.publish" } + expect(span).not_to be_nil + expect(span[:op]).to eq("queue.publish") + expect(span[:data]['messaging.destination.name']).to eq('default') + + span = events[1].spans.detect { |span| span[:op] == "queue.publish" } + expect(span).not_to be_nil + expect(span[:op]).to eq("queue.publish") + expect(span[:data]['messaging.destination.name']).to eq('default') expect(events[0].dynamic_sampling_context['trace_id']).to_not eq(events[1].dynamic_sampling_context['trace_id']) end diff --git a/sentry-sidekiq/spec/sentry/sidekiq/sentry_context_middleware_spec.rb b/sentry-sidekiq/spec/sentry/sidekiq/sentry_context_middleware_spec.rb index c37580d57..edc4f941a 100644 --- a/sentry-sidekiq/spec/sentry/sidekiq/sentry_context_middleware_spec.rb +++ b/sentry-sidekiq/spec/sentry/sidekiq/sentry_context_middleware_spec.rb @@ -222,11 +222,12 @@ def ensure_queue_empty(queue, timeout: 0.1) transaction.finish expect(transport.events.count).to eq(1) - event = transport.events.last - expect(event.spans.count).to eq(1) - expect(event.spans[0][:op]).to eq("queue.publish") - expect(event.spans[0][:data]['messaging.message.id']).to eq(message_id) - expect(event.spans[0][:data]['messaging.destination.name']).to eq('default') + + span = transport.events.last.spans.detect { |span| span[:op] == "queue.publish" } + expect(span).not_to be_nil + expect(span[:op]).to eq("queue.publish") + expect(span[:data]['messaging.message.id']).to eq(message_id) + expect(span[:data]['messaging.destination.name']).to eq('default') end it "does not propagate headers with propagate_traces = false" do diff --git a/sentry-sidekiq/spec/spec_helper.rb b/sentry-sidekiq/spec/spec_helper.rb index 6aaf3c765..35454aac9 100644 --- a/sentry-sidekiq/spec/spec_helper.rb +++ b/sentry-sidekiq/spec/spec_helper.rb @@ -344,6 +344,7 @@ def perform_basic_setup config.sdk_logger = ::Logger.new(nil) config.background_worker_threads = 0 config.transport.transport_class = Sentry::DummyTransport + yield config if block_given? end end