diff --git a/lib/shoryuken/manager.rb b/lib/shoryuken/manager.rb index 9c1faf3d..ed3463dc 100644 --- a/lib/shoryuken/manager.rb +++ b/lib/shoryuken/manager.rb @@ -74,9 +74,9 @@ def assign(queue_name, sqs_msg) end def dispatch_batch(queue) - return if (batch = @fetcher.fetch(queue, BATCH_LIMIT)).none? + batch = @fetcher.fetch(queue, BATCH_LIMIT) @polling_strategy.messages_found(queue.name, batch.size) - assign(queue.name, patch_batch!(batch)) + assign(queue.name, patch_batch!(batch)) if batch.any? end def dispatch_single_messages(queue) diff --git a/spec/shoryuken/manager_spec.rb b/spec/shoryuken/manager_spec.rb index cc7b1307..68b7eaf9 100644 --- a/spec/shoryuken/manager_spec.rb +++ b/spec/shoryuken/manager_spec.rb @@ -90,6 +90,21 @@ subject.send(:dispatch) end + + context "and there are no messages in the queue" do + specify do + messages = %w[] + q = Shoryuken::Polling::QueueConfiguration.new(queue, {}) + + expect(fetcher).to receive(:fetch).with(q, described_class::BATCH_LIMIT).and_return(messages) + expect(subject).to receive(:fire_event).with(:dispatch, false, queue_name: q.name) + allow(subject).to receive(:batched_queue?).with(q).and_return(true) + expect(polling_strategy).to receive(:messages_found).with(q.name, 0) + expect_any_instance_of(described_class).to receive(:assign).never + + subject.send(:dispatch) + end + end end end