Skip to content

Commit

Permalink
spec that each of the strategies can still retrieve work
Browse files Browse the repository at this point in the history
  • Loading branch information
woodhull committed May 3, 2017
1 parent e308e54 commit ea6912b
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions spec/sidekiq-rate-limiter/fetch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,25 @@ def perform(arg1, arg2); end
expect(fetch.queues_cmd).to eql(["queue:#{queue}", "queue:#{another_queue}", timeout])
end

it 'should retrieve work', queuing: true do
worker.perform_async(*args)
fetch = described_class.new(options)
work = fetch.retrieve_work
parsed = JSON.parse(work.respond_to?(:message) ? work.message : work.job)
shared_examples 'retrieve_work' do |parameter|

expect(work).not_to be_nil
expect(work.queue_name).to eql(queue)
expect(work.acknowledge).to be_nil
it 'should retrieve work', queuing: true do
worker.perform_async(*args)
fetch = described_class.new(options)
work = fetch.retrieve_work
parsed = JSON.parse(work.respond_to?(:message) ? work.message : work.job)

expect(parsed).to include(worker.get_sidekiq_options)
expect(parsed).to include("class" => worker.to_s, "args" => args)
expect(parsed).to include("jid", "enqueued_at")
expect(work).not_to be_nil
expect(work.queue_name).to eql(queue)
expect(work.acknowledge).to be_nil

q = Sidekiq::Queue.new(queue)
expect(q.size).to eq 0
expect(parsed).to include(worker.get_sidekiq_options)
expect(parsed).to include("class" => worker.to_s, "args" => args)
expect(parsed).to include("jid", "enqueued_at")

q = Sidekiq::Queue.new(queue)
expect(q.size).to eq 0
end
end

it 'should place rate-limited work at the back of the queue', queuing: true do
Expand All @@ -81,13 +84,19 @@ def perform(arg1, arg2); end
expect(q.size).to eq 1
end

context 'with the basic strategy' do
include_examples 'retrieve_work'
end

context 'with the sleep strategy' do
before :each do
Sidekiq::RateLimiter.configure do |config|
config.fetch_strategy = Sidekiq::RateLimiter::SleepStrategy
end
end

include_examples 'retrieve_work'

it 'should place rate-limited work at the back of the queue immediately when retry_in? is less than 1.0', queuing: true do
worker.perform_async(*args)
expect_any_instance_of(Sidekiq::RateLimiter::Limit).to receive(:exceeded?).and_return(true)
Expand Down Expand Up @@ -130,6 +139,8 @@ def perform(arg1, arg2); end
end
end

include_examples 'retrieve_work'

it 'should place rate-limited work at the back of the queue', queuing: true do
worker.perform_async(*args)
expect_any_instance_of(Sidekiq::RateLimiter::Limit).to receive(:exceeded?).and_return(true)
Expand Down

0 comments on commit ea6912b

Please # to comment.