Sha256: 950007c005781b0abdea7ca2ff306af5b7b09daac62cc407a3ed9ad3180ca8d3

Contents?: true

Size: 1.22 KB

Versions: 18

Compression:

Stored size: 1.22 KB

Contents

require 'spec_helper'

describe Sidekiq::LimitFetch do
  before :each 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

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

  it 'should acquire lock on queue for execution' do
    work = subject.retrieve_work
    work.queue_name.should == 'queue1'
    work.message.should == 'task1'

    Sidekiq::Queue['queue1'].busy.should == 1
    Sidekiq::Queue['queue2'].busy.should == 0

    subject.retrieve_work.should_not be
    work.requeue

    Sidekiq::Queue['queue1'].busy.should == 0
    Sidekiq::Queue['queue2'].busy.should == 0

    work = subject.retrieve_work
    work.message.should == 'task1'

    Sidekiq::Queue['queue1'].busy.should == 1
    Sidekiq::Queue['queue2'].busy.should == 0

    subject.retrieve_work.should_not be
    work.acknowledge

    Sidekiq::Queue['queue1'].busy.should == 0
    Sidekiq::Queue['queue2'].busy.should == 0

    work = subject.retrieve_work
    work.message.should == 'task2'
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
sidekiq-limit_fetch-2.4.1 spec/sidekiq/limit_fetch_spec.rb
sidekiq-limit_fetch-2.4.0 spec/sidekiq/limit_fetch_spec.rb
sidekiq-limit_fetch-2.3.0 spec/sidekiq/limit_fetch_spec.rb
sidekiq-limit_fetch-2.2.7 spec/sidekiq/limit_fetch_spec.rb
sidekiq-limit_fetch-2.2.6 spec/sidekiq/limit_fetch_spec.rb
sidekiq-limit_fetch-2.2.5 spec/sidekiq/limit_fetch_spec.rb
sidekiq-limit_fetch-2.2.4 spec/sidekiq/limit_fetch_spec.rb
sidekiq-limit_fetch-2.2.3 spec/sidekiq/limit_fetch_spec.rb
sidekiq-limit_fetch-2.2.2 spec/sidekiq/limit_fetch_spec.rb
sidekiq-limit_fetch-2.2.1 spec/sidekiq/limit_fetch_spec.rb
sidekiq-limit_fetch-2.2.0 spec/sidekiq/limit_fetch_spec.rb
sidekiq-limit_fetch-2.1.3 spec/sidekiq/limit_fetch_spec.rb
sidekiq-limit_fetch-2.1.2 spec/sidekiq/limit_fetch_spec.rb
sidekiq-limit_fetch-2.1.1 spec/sidekiq/limit_fetch_spec.rb
sidekiq-limit_fetch-2.1.0 spec/sidekiq/limit_fetch_spec.rb
sidekiq-limit_fetch-2.0.2 spec/sidekiq/limit_fetch_spec.rb
sidekiq-limit_fetch-2.0.1 spec/sidekiq/limit_fetch_spec.rb
sidekiq-limit_fetch-2.0 spec/sidekiq/limit_fetch_spec.rb