Sha256: 7a7e9fcb3c4328d453794a90f777115cc9d2f24ba2eaa0a894c8056e41e9c992

Contents?: true

Size: 1.62 KB

Versions: 9

Compression:

Stored size: 1.62 KB

Contents

require 'spec_helper'
require 'delayed_job_active_record'
require 'timecop'

require 'roqua/probes/delayed_job_probe'

describe Roqua::Probes::DelayedJobProbe do
  before { Timecop.freeze }
  after { Timecop.return }
  subject(:probe) { Roqua::Probes::DelayedJobProbe.new }

  describe 'backlog_count' do
    context 'if a single job unlocked job exists that has a run_at in the past' do
      def create_jobs
        Delayed::Job.create!(run_at: 1.second.ago)
        2.times { Delayed::Job.create!(run_at: 1.second.ago, locked_at: Time.zone.now) }
        Delayed::Job.create!(run_at: Time.zone.now)
        Delayed::Job.create!(run_at: 1.second.from_now)
      end

      it 'returns 1' do
        expect { create_jobs }.to change { probe.backlog_count }.from(0).to(1)
      end
    end
  end

  describe 'call' do
    it 'sends the correct metric to Appsignal' do
      expect(probe).to receive(:backlog_count).and_return(12)
      expect(Appsignal).to receive(:set_gauge).with('delayed_job_backlog_count', 12)
      probe.call
    end
  end

  context '.enable' do
    before { Appsignal::Minutely.probes.clear }
    after { Appsignal::Minutely.probes.clear }

    it 'adds our custom probes to Appsignal' do
      expect { Roqua::Probes::DelayedJobProbe.enable }
        .to change { Appsignal::Minutely.probes.count }.by(1)

      expect(Appsignal::Minutely.probes.map(&:class)).to include(Roqua::Probes::DelayedJobProbe)
    end

    it 'will not add the same probe twice if called multiple times' do
      expect { 2.times { Roqua::Probes::DelayedJobProbe.enable } }
        .to change { Appsignal::Minutely.probes.count }.by(1)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
roqua-support-0.1.34 spec/roqua/probes/delayed_job_probe_spec.rb
roqua-support-0.1.33 spec/roqua/probes/delayed_job_probe_spec.rb
roqua-support-0.1.32 spec/roqua/probes/delayed_job_probe_spec.rb
roqua-support-0.1.31 spec/roqua/probes/delayed_job_probe_spec.rb
roqua-support-0.1.30 spec/roqua/probes/delayed_job_probe_spec.rb
roqua-support-0.1.29 spec/roqua/probes/delayed_job_probe_spec.rb
roqua-support-0.1.28 spec/roqua/probes/delayed_job_probe_spec.rb
roqua-support-0.1.27 spec/roqua/probes/delayed_job_probe_spec.rb
roqua-support-0.1.26 spec/roqua/probes/delayed_job_probe_spec.rb