From 8e98314bc9d89837f0a617c857baa58f8501927e Mon Sep 17 00:00:00 2001 From: awaw Date: Fri, 31 May 2013 02:39:01 +0800 Subject: [PATCH] raise error upon empty queue --- lib/sidekiq/testing.rb | 4 ++++ test/test_testing.rb | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/lib/sidekiq/testing.rb b/lib/sidekiq/testing.rb index 33b43ae4..10e9e758 100644 --- a/lib/sidekiq/testing.rb +++ b/lib/sidekiq/testing.rb @@ -1,5 +1,7 @@ module Sidekiq + class EmptyQueueError < RuntimeError; end + class Client class << self alias_method :raw_push_old, :raw_push @@ -90,6 +92,8 @@ module Sidekiq # Pop out a single job and perform it def perform_one + raise(EmptyQueueError, + "perform_one called with empty job queue") unless jobs.size > 0 job = jobs.shift new.perform(*job['args']) end diff --git a/test/test_testing.rb b/test/test_testing.rb index 25dcfb3c..256af4ce 100644 --- a/test/test_testing.rb +++ b/test/test_testing.rb @@ -130,6 +130,12 @@ class TestTesting < Minitest::Test DirectWorker.clear end + it 'perform_one raise error upon empty queue' do + assert_raises Sidekiq::EmptyQueueError do + DirectWorker.perform_one + end + end + class FirstWorker include Sidekiq::Worker class_attribute :count