Sha256: 3e3d31d7459b9ca65e8bed919be6ccbeb9e02b3c04189950a5f75a291a9a521d

Contents?: true

Size: 1.99 KB

Versions: 4

Compression:

Stored size: 1.99 KB

Contents

require 'spec_helper'

class VerySpecificError < RuntimeError
end

describe "Sidekiq integration" do
  let(:file) { File.expand_path('lib/appsignal/integrations/sidekiq.rb') }
  before :all do
    module Sidekiq
      def self.configure_server
      end
    end
  end
  before do
    load file
    start_agent
  end

  let(:worker) { double }
  let(:queue) { double }
  let(:current_transaction) { Appsignal::Transaction.create(SecureRandom.uuid, {}) }
  let(:item) {{
    'class' => 'TestClass',
    'retry_count' => 0,
    'queue' => 'default',
    'enqueued_at' => Time.parse('01-01-2001 10:00:00UTC')
  }}

  before do
    Appsignal.stub(:is_ignored_exception? => false)
    Appsignal::Transaction.stub(:current => current_transaction)
  end

  context "with a performance call" do
    it "should create an instrumentation with the correct params" do
      ActiveSupport::Notifications.should_receive(:instrument).with(
        'perform_job.sidekiq',
        :class => 'TestClass',
        :method => 'perform',
        :attempts => 0,
        :queue => 'default',
        :queue_time => 60_000
      )
    end

    after do
      Timecop.freeze(Time.parse('01-01-2001 10:01:00UTC')) do
        Appsignal::Integrations::SidekiqPlugin.new.call(worker, item, queue) do
          # nothing
        end
      end
    end
  end

  context "with an erroring call" do
    let(:error) { VerySpecificError.new('the roof') }
    it "should add exception to appsignal" do
      current_transaction.should_receive(:add_exception).with(error)
    end

    after do
      begin
        Timecop.freeze(Time.parse('01-01-2001 10:01:00UTC')) do
          Appsignal::Integrations::SidekiqPlugin.new.call(worker, item, queue) do
            raise error
          end
        end
      rescue VerySpecificError
      end
    end
  end

  context "without sidekiq" do
    before(:all) { Object.send(:remove_const, :Sidekiq) }

    specify { expect { Sidekiq }.to raise_error(NameError) }
    specify { expect { load file }.to_not raise_error }
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
appsignal-0.8.0 spec/lib/appsignal/integrations/sidekiq_spec.rb
appsignal-0.8.0.beta.1 spec/lib/appsignal/integrations/sidekiq_spec.rb
appsignal-0.8.0.beta.0 spec/lib/appsignal/integrations/sidekiq_spec.rb
appsignal-0.8.0.alpha.0 spec/lib/appsignal/integrations/sidekiq_spec.rb