1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00
mperham--sidekiq/test/test_manager.rb
Mike Perham f9af66edd7 Rework redis connections so that the manager and
the client use separate pools.

This is so the Rails app Sidekiq::Client and 
Sidekiq::Manager can use different configurations.

Also, fix issue where workers were not unregistered
in Redis upon shutdown.
2012-02-11 13:14:03 -08:00

43 lines
1.1 KiB
Ruby

require 'helper'
require 'sidekiq'
require 'sidekiq/manager'
# for TimedQueue
require 'connection_pool'
class TestManager < MiniTest::Unit::TestCase
describe 'with redis' do
before do
Sidekiq::Manager.redis = Sidekiq::Client.redis = @redis = Sidekiq::RedisConnection.create(:url => 'redis://localhost/sidekiq_test')
@redis.flushdb
$processed = 0
$mutex = Mutex.new
end
class IntegrationWorker
include Sidekiq::Worker
def perform(a, b)
$mutex.synchronize do
$processed += 1
end
a + b
end
end
it 'processes messages' do
Sidekiq::Client.push(:foo, 'class' => IntegrationWorker, 'args' => [1, 2])
Sidekiq::Client.push(:foo, 'class' => IntegrationWorker, 'args' => [1, 3])
q = TimedQueue.new
mgr = Sidekiq::Manager.new(:queues => [:foo], :processor_count => 2)
mgr.when_done do |_|
q << 'done' if $processed == 2
end
mgr.start!
result = q.timed_pop(1.0)
assert_equal 'done', result
mgr.stop
end
end
end