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