1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Rejigger inline testing to handle enqueue/enqueue_to

This commit is contained in:
Mike Perham 2012-09-07 08:59:04 -07:00
parent be84d53c7f
commit b3757fdfa6
4 changed files with 12 additions and 26 deletions

View file

@ -73,14 +73,14 @@ module Sidekiq
# Messages are enqueued to the 'default' queue.
#
def self.enqueue(klass, *args)
klass.client_push('class' => self, 'args' => args)
klass.client_push('class' => klass, 'args' => args)
end
# Example usage:
# Sidekiq::Client.enqueue_to(:queue_name, MyWorker, 'foo', 1, :bat => 'bar')
#
def self.enqueue_to(queue, klass, *args)
klass.client_push('queue' => queue, 'class' => self, 'args' => args)
klass.client_push('queue' => queue, 'class' => klass, 'args' => args)
end
end
end

View file

@ -1,8 +1,8 @@
module Sidekiq
module Worker
class Client
##
# The Sidekiq inline infrastructure overrides the perform_async so that it
# The Sidekiq inline infrastructure overrides perform_async so that it
# actually calls perform instead. This allows workers to be run inline in a
# testing environment.
#
@ -26,10 +26,10 @@ module Sidekiq
# ExternalWorker.perform_async
# assert_equal 1, $external_variable
#
module ClassMethods
alias_method :perform_async_old, :perform_async
def perform_async(*args)
new.perform(*Sidekiq.load_json(Sidekiq.dump_json(args)))
singleton_class.class_eval do
alias_method :push_old, :push
def push(hash)
hash['class'].new.perform(*Sidekiq.load_json(Sidekiq.dump_json(hash['args'])))
true
end
end

View file

@ -69,20 +69,6 @@ class TestClient < MiniTest::Unit::TestCase
@redis.verify
end
it 'handles perform_in_queue' do
@redis.expect :rpush, 1, ['queue:custom_queue', String]
pushed = MyWorker.perform_in_queue(:custom_queue, 1, 2)
assert pushed
@redis.verify
end
it 'handles perform_in_queue on failure' do
@redis.expect :rpush, nil, ['queue:custom_queue', String]
pushed = MyWorker.perform_in_queue(:custom_queue, 1, 2)
refute pushed
@redis.verify
end
it 'enqueues messages to redis' do
@redis.expect :rpush, 1, ['queue:custom_queue', String]
pushed = Sidekiq::Client.enqueue_to(:custom_queue, MyWorker, 1, 2)

View file

@ -45,10 +45,10 @@ class TestInline < MiniTest::Unit::TestCase
end
after do
Sidekiq::Worker::ClassMethods.class_eval do
remove_method :perform_async
alias_method :perform_async, :perform_async_old
remove_method :perform_async_old
Sidekiq::Client.singleton_class.class_eval do
remove_method :push
alias_method :push, :push_old
remove_method :push_old
end
end