Sha256: 8012caafb211cd62f88e5a02c93ba7eca10b7a0f48dded3c02df248857865434

Contents?: true

Size: 1.2 KB

Versions: 7

Compression:

Stored size: 1.2 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) { fail 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) { fail '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

7 entries across 7 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-4.0.13 spec/lib/sidekiq_unique_jobs/lock/until_executed_spec.rb
sidekiq-unique-jobs-4.0.12 spec/lib/sidekiq_unique_jobs/lock/until_executed_spec.rb
sidekiq-unique-jobs-4.0.11 spec/lib/sidekiq_unique_jobs/lock/until_executed_spec.rb
sidekiq-unique-jobs-4.0.10 spec/lib/sidekiq_unique_jobs/lock/until_executed_spec.rb
sidekiq-unique-jobs-4.0.9 spec/lib/sidekiq_unique_jobs/lock/until_executed_spec.rb
sidekiq-unique-jobs-4.0.8 spec/lib/sidekiq_unique_jobs/lock/until_executed_spec.rb
sidekiq-unique-jobs-4.0.7 spec/lib/sidekiq_unique_jobs/lock/until_executed_spec.rb