2012-01-26 15:45:04 -05:00
|
|
|
require 'helper'
|
|
|
|
require 'sidekiq/processor'
|
|
|
|
|
|
|
|
class TestProcessor < MiniTest::Unit::TestCase
|
|
|
|
describe 'with mock setup' do
|
|
|
|
before do
|
|
|
|
$invokes = 0
|
|
|
|
$errors = []
|
|
|
|
@boss = MiniTest::Mock.new
|
2012-01-29 17:35:16 -05:00
|
|
|
Celluloid.logger = nil
|
2012-03-17 16:32:52 -04:00
|
|
|
Sidekiq.redis = REDIS
|
2012-01-26 15:45:04 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class MockWorker
|
2012-02-11 02:16:12 -05:00
|
|
|
include Sidekiq::Worker
|
2012-01-26 15:45:04 -05:00
|
|
|
def perform(args)
|
|
|
|
raise "kerboom!" if args == 'boom'
|
|
|
|
$invokes += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'processes as expected' do
|
|
|
|
msg = { 'class' => MockWorker.to_s, 'args' => ['myarg'] }
|
|
|
|
processor = ::Sidekiq::Processor.new(@boss)
|
|
|
|
@boss.expect(:processor_done!, nil, [processor])
|
2012-02-11 02:16:12 -05:00
|
|
|
processor.process(msg, 'default')
|
2012-01-26 15:45:04 -05:00
|
|
|
@boss.verify
|
|
|
|
assert_equal 1, $invokes
|
|
|
|
assert_equal 0, $errors.size
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|