diff --git a/spec/sidekiq-rate-limiter/fetch_spec.rb b/spec/sidekiq-rate-limiter/fetch_spec.rb index 2206dcd..5ece981 100644 --- a/spec/sidekiq-rate-limiter/fetch_spec.rb +++ b/spec/sidekiq-rate-limiter/fetch_spec.rb @@ -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 @@ -81,6 +84,10 @@ 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| @@ -88,6 +95,8 @@ def perform(arg1, arg2); end 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) @@ -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)