Sha256: 8d3e3a821418ece8bd1c1c6fca61c0d9ce91434e5e3547c5c5368aba52d0fd6a

Contents?: true

Size: 1.2 KB

Versions: 6

Compression:

Stored size: 1.2 KB

Contents

require 'spec_helper'

describe Sufia::Resque::Queue do
  let(:subject) { described_class.new "test_queue" }
  let(:job) { double('job') }

  context "with no retries" do
    it "queues the job" do
      expect(::Resque).to receive(:enqueue_to).once.and_return(true)
      subject.push(job)
    end
  end

  context 'when one run times out' do
    before do
      call_count = 0
      allow(::Resque).to receive(:enqueue_to) do
        call_count += 1
        call_count == 1 ? raise(Redis::TimeoutError) : true
      end
    end

    it 'retries the job' do
      expect(::Resque).to receive(:enqueue_to).twice
      subject.push(job)
    end
  end

  context 'when a job times out three times' do
    before do
      allow(::Resque).to receive(:enqueue_to).exactly(3).times.and_raise(Redis::TimeoutError)
    end

    it 'raises an error' do
      expect { subject.push(job) }.to raise_error Redis::TimeoutError
    end
  end

  context 'with no connection to Redis' do
    before do
      allow(::Resque).to receive(:enqueue_to).once.and_raise(Redis::CannotConnectError)
    end

    it 'logs an error' do
      expect(ActiveFedora::Base.logger).to receive(:error).with("Redis is down!")
      subject.push(job)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sufia-6.7.0 spec/jobs/sufia_resque_queue_spec.rb
sufia-6.6.1 spec/jobs/sufia_resque_queue_spec.rb
sufia-6.6.0 spec/jobs/sufia_resque_queue_spec.rb
sufia-6.5.0 spec/jobs/sufia_resque_queue_spec.rb
sufia-6.4.0 spec/jobs/sufia_resque_queue_spec.rb
sufia-6.3.0 spec/jobs/sufia_resque_queue_spec.rb