Sha256: 7d33860fdfaa404608dafcafa8913e0e529f33051b2c6debd9e216b682334ee0

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

require 'spec_helper'

RSpec.describe SidekiqUniqueJobs::Lock::UntilExecuted do
  describe '#execute' do
    subject { described_class.new(item) }
    let(:item) do
      { 'jid' => 'maaaahjid', 'class' => 'UntilExecutedJob', 'unique' => 'until_executed' }
    end
    let(:empty_callback) { -> {} }

    def execute
      subject.execute(empty_callback)
    end

    context 'when yield fails with Sidekiq::Shutdown' do
      before do
        allow(subject).to receive(:after_yield_yield) { raise Sidekiq::Shutdown }
      end

      it 'raises Sidekiq::Shutdown' do
        allow(subject).to receive(:unlock).and_return(true)
        expect(subject).not_to receive(:unlock)
        expect(empty_callback).not_to receive(:call)
        expect { subject.execute(empty_callback) }.to raise_error(Sidekiq::Shutdown)
      end
    end

    context 'when yield fails with other errors' do
      before do
        allow(subject).to receive(:after_yield_yield) { raise 'Hell' }
      end

      it 'raises Sidekiq::Shutdown' do
        expect(subject).to receive(:unlock).and_return(true)
        expect(empty_callback).to receive(:call)
        expect { subject.execute(empty_callback) }.to raise_error('Hell')
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-4.0.17 spec/lib/sidekiq_unique_jobs/lock/until_executed_spec.rb
sidekiq-unique-jobs-4.0.16 spec/lib/sidekiq_unique_jobs/lock/until_executed_spec.rb
sidekiq-unique-jobs-4.0.15 spec/lib/sidekiq_unique_jobs/lock/until_executed_spec.rb