Sha256: f3a17fa105c8d39c040b80b10672c0df966e34c9d6a35994e2932a323b8fee99

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

require 'spec_helper'

RSpec.describe SidekiqUniqueJobs::Lock::UntilAndWhileExecuting do
  let(:item) do
    {
      'jid' => 'maaaahjid',
      'queue' => 'dupsallowed',
      'class' => 'UntilAndWhileExecuting',
      'unique' => 'until_executed',
      'args' => [1]
    }
  end
  let(:callback) { -> {} }
  subject { described_class.new(item) }
  describe '#execute' do
    before do
      Sidekiq.redis(&:flushdb)
      Sidekiq::Worker.clear_all
      subject.lock(:client)
    end
    let(:runtime_lock) { SidekiqUniqueJobs::Lock::WhileExecuting.new(item, nil) }

    it 'unlocks the unique key before yielding' do
      expect(SidekiqUniqueJobs::Lock::WhileExecuting)
        .to receive(:new).with(item, nil)
        .and_return(runtime_lock)

      expect(callback).to receive(:call)

      subject.execute(callback) do
        Sidekiq.redis do |c|
          expect(c.keys('uniquejobs:*').size).to eq(1)
        end

        10.times { Sidekiq::Client.push(item) }

        Sidekiq.redis do |c|
          expect(c.keys('uniquejobs:*').size).to eq(2)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-4.0.18 spec/lib/sidekiq_unique_jobs/lock/until_and_while_executing_spec.rb