Skip to content

Commit

Permalink
Add test for client middleware short circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed Sep 13, 2012
1 parent 92bec16 commit c78d4e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sidekiq/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def self.push(item)
conn.rpush("queue:#{normed['queue']}", payload)
end
end
end
end if normed
pushed ? normed['jid'] : nil
end

Expand Down
20 changes: 20 additions & 0 deletions test/test_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,26 @@ class BWorker < BaseWorker
sidekiq_options 'retry' => 'b'
end

describe 'client middleware' do

class Stopper
def call(worker_class, message, queue)
yield if message['args'].first.odd?
end
end

it 'can stop some of the jobs from pushing' do
Sidekiq.client_middleware.add Stopper
begin
assert_equal nil, Sidekiq::Client.push('class' => MyWorker, 'args' => [0])
assert_match /[0-9a-f]{12}/, Sidekiq::Client.push('class' => MyWorker, 'args' => [1])
assert_equal 1, Sidekiq::Client.push_batch('class' => MyWorker, 'args' => [[0], [1]])
ensure
Sidekiq.client_middleware.remove Stopper
end
end
end

describe 'inheritance' do
it 'should inherit sidekiq options' do
assert_equal 'base', AWorker.get_sidekiq_options['retry']
Expand Down

0 comments on commit c78d4e7

Please sign in to comment.