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:
parent
be84d53c7f
commit
b3757fdfa6
4 changed files with 12 additions and 26 deletions
|
@ -73,14 +73,14 @@ module Sidekiq
|
||||||
# Messages are enqueued to the 'default' queue.
|
# Messages are enqueued to the 'default' queue.
|
||||||
#
|
#
|
||||||
def self.enqueue(klass, *args)
|
def self.enqueue(klass, *args)
|
||||||
klass.client_push('class' => self, 'args' => args)
|
klass.client_push('class' => klass, 'args' => args)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Example usage:
|
# Example usage:
|
||||||
# Sidekiq::Client.enqueue_to(:queue_name, MyWorker, 'foo', 1, :bat => 'bar')
|
# Sidekiq::Client.enqueue_to(:queue_name, MyWorker, 'foo', 1, :bat => 'bar')
|
||||||
#
|
#
|
||||||
def self.enqueue_to(queue, klass, *args)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
module Sidekiq
|
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
|
# actually calls perform instead. This allows workers to be run inline in a
|
||||||
# testing environment.
|
# testing environment.
|
||||||
#
|
#
|
||||||
|
@ -26,10 +26,10 @@ module Sidekiq
|
||||||
# ExternalWorker.perform_async
|
# ExternalWorker.perform_async
|
||||||
# assert_equal 1, $external_variable
|
# assert_equal 1, $external_variable
|
||||||
#
|
#
|
||||||
module ClassMethods
|
singleton_class.class_eval do
|
||||||
alias_method :perform_async_old, :perform_async
|
alias_method :push_old, :push
|
||||||
def perform_async(*args)
|
def push(hash)
|
||||||
new.perform(*Sidekiq.load_json(Sidekiq.dump_json(args)))
|
hash['class'].new.perform(*Sidekiq.load_json(Sidekiq.dump_json(hash['args'])))
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -69,20 +69,6 @@ class TestClient < MiniTest::Unit::TestCase
|
||||||
@redis.verify
|
@redis.verify
|
||||||
end
|
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
|
it 'enqueues messages to redis' do
|
||||||
@redis.expect :rpush, 1, ['queue:custom_queue', String]
|
@redis.expect :rpush, 1, ['queue:custom_queue', String]
|
||||||
pushed = Sidekiq::Client.enqueue_to(:custom_queue, MyWorker, 1, 2)
|
pushed = Sidekiq::Client.enqueue_to(:custom_queue, MyWorker, 1, 2)
|
||||||
|
|
|
@ -45,10 +45,10 @@ class TestInline < MiniTest::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
after do
|
||||||
Sidekiq::Worker::ClassMethods.class_eval do
|
Sidekiq::Client.singleton_class.class_eval do
|
||||||
remove_method :perform_async
|
remove_method :push
|
||||||
alias_method :perform_async, :perform_async_old
|
alias_method :push, :push_old
|
||||||
remove_method :perform_async_old
|
remove_method :push_old
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue