Sha256: 1c9f5c51591f489d5291d3c8b9464db586db7330932adbcd42be5a3e59488fb8

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

Thread.abort_on_exception = true

RSpec.describe Sidekiq::LimitFetch do
  before do
    Sidekiq.redis do |it|
      it.del 'queue:queue1'
      it.lpush 'queue:queue1', 'task1'
      it.lpush 'queue:queue1', 'task2'
      it.expire 'queue:queue1', 30
    end
  end

  let(:options) {{ queues: queues, limits: limits }}
  let(:queues) { %w(queue1 queue1 queue2 queue2) }
  let(:limits) {{ 'queue1' => 1, 'queue2' => 2 }}

  before { subject::Queues.start options }

  it 'should acquire lock on queue for execution' do
    work = subject.retrieve_work
    expect(work.queue_name).to eq 'queue1'
    expect(work.message).to eq 'task1'

    expect(Sidekiq::Queue['queue1'].busy).to eq 1
    expect(Sidekiq::Queue['queue2'].busy).to eq 0

    expect(subject.retrieve_work).not_to be
    work.requeue

    expect(Sidekiq::Queue['queue1'].busy).to eq 0
    expect(Sidekiq::Queue['queue2'].busy).to eq 0

    work = subject.retrieve_work
    expect(work.message).to eq 'task1'

    expect(Sidekiq::Queue['queue1'].busy).to eq 1
    expect(Sidekiq::Queue['queue2'].busy).to eq 0

    expect(subject.retrieve_work).not_to be
    work.acknowledge

    expect(Sidekiq::Queue['queue1'].busy).to eq 0
    expect(Sidekiq::Queue['queue2'].busy).to eq 0

    work = subject.retrieve_work
    expect(work.message).to eq 'task2'
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sidekiq-limit_fetch-3.0.1 spec/sidekiq/limit_fetch_spec.rb
sidekiq-limit_fetch-3.0.0 spec/sidekiq/limit_fetch_spec.rb