Sha256: c952cf9ae0ca422556bf814621b33fcbffc751d6b8df43ca44e9f9adb7b12e9d

Contents?: true

Size: 1.78 KB

Versions: 9

Compression:

Stored size: 1.78 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) { described_class.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

    it 'increments the probe call counter' do
      expect(Appsignal).to receive(:increment_counter).with('probe.call.completed', 1, probe_name: "delayed_job_probe")
      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[:"Roqua::Probes::DelayedJobProbe"]).to be
    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.4.4 spec/roqua/probes/delayed_job_probe_spec.rb
roqua-support-0.4.3 spec/roqua/probes/delayed_job_probe_spec.rb
roqua-support-0.4.2 spec/roqua/probes/delayed_job_probe_spec.rb
roqua-support-0.4.1 spec/roqua/probes/delayed_job_probe_spec.rb
roqua-support-0.4.0 spec/roqua/probes/delayed_job_probe_spec.rb
roqua-support-0.3.5 spec/roqua/probes/delayed_job_probe_spec.rb
roqua-support-0.3.4 spec/roqua/probes/delayed_job_probe_spec.rb
roqua-support-0.3.3 spec/roqua/probes/delayed_job_probe_spec.rb
roqua-support-0.3.2 spec/roqua/probes/delayed_job_probe_spec.rb