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

DRY testing API

This commit is contained in:
Dimitrij Denissenko 2012-06-28 08:46:18 +01:00
parent 83bdf72acc
commit 8dbea0fbe1
3 changed files with 13 additions and 20 deletions

View file

@ -24,22 +24,12 @@ module Sidekiq
# assert_equal 1, Sidekiq::Extensions::DelayedMailer.jobs.size
#
module ClassMethods
alias_method :perform_async_old, :perform_async
def perform_async(*args)
jobs << { 'class' => self.name, 'args' => args }
alias_method :client_push_old, :client_push
def client_push(opts)
jobs << opts
true
end
alias_method :perform_in_old, :perform_in
alias_method :perform_at_old, :perform_at
def perform_in(interval, *args)
int = interval.to_f
ts = (int < 1_000_000_000 ? Time.now.to_f + int : int)
jobs << { 'class' => self.name, 'args' => args, 'at' => ts }
true
end
alias_method :perform_at, :perform_in
def jobs
@pushed ||= []
end

View file

@ -32,13 +32,13 @@ module Sidekiq
module ClassMethods
def perform_async(*args)
Sidekiq::Client.push('class' => self, 'args' => args)
client_push('class' => self, 'args' => args)
end
def perform_in(interval, *args)
int = interval.to_f
ts = (int < 1_000_000_000 ? Time.now.to_f + int : int)
Sidekiq::Client.push('class' => self, 'args' => args, 'at' => ts)
client_push('class' => self, 'args' => args, 'at' => ts)
end
alias_method :perform_at, :perform_in
@ -68,6 +68,11 @@ module Sidekiq
end
hash
end
def client_push(*args)
Sidekiq::Client.push(*args)
end
end
end
end

View file

@ -53,11 +53,9 @@ class TestTesting < MiniTest::Unit::TestCase
after do
# Undo override
Sidekiq::Worker::ClassMethods.class_eval do
%w(async at in).each do |token|
remove_method :"perform_#{token}"
alias_method :"perform_#{token}", :"perform_#{token}_old"
remove_method :"perform_#{token}_old"
end
remove_method :client_push
alias_method :client_push, :client_push_old
remove_method :client_push_old
end
end