2012-02-03 13:02:57 -05:00
|
|
|
require 'helper'
|
|
|
|
require 'sidekiq'
|
|
|
|
require 'sidekiq/manager'
|
2012-02-10 00:46:44 -05:00
|
|
|
|
|
|
|
# for TimedQueue
|
2012-02-07 01:35:14 -05:00
|
|
|
require 'connection_pool'
|
2012-02-03 13:02:57 -05:00
|
|
|
|
|
|
|
class TestManager < MiniTest::Unit::TestCase
|
|
|
|
describe 'with redis' do
|
|
|
|
before do
|
2012-03-14 00:19:46 -04:00
|
|
|
Sidekiq.redis = REDIS
|
2012-03-28 22:16:54 -04:00
|
|
|
Sidekiq.redis {|c| c.flushdb }
|
2012-02-03 13:02:57 -05:00
|
|
|
$processed = 0
|
2012-02-10 00:46:44 -05:00
|
|
|
$mutex = Mutex.new
|
2012-02-03 13:02:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class IntegrationWorker
|
|
|
|
include Sidekiq::Worker
|
2012-04-26 11:40:07 -04:00
|
|
|
sidekiq_options :queue => 'foo'
|
2012-02-03 13:02:57 -05:00
|
|
|
|
|
|
|
def perform(a, b)
|
2012-02-10 00:46:44 -05:00
|
|
|
$mutex.synchronize do
|
|
|
|
$processed += 1
|
|
|
|
end
|
2012-02-03 13:02:57 -05:00
|
|
|
a + b
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'processes messages' do
|
2012-04-26 11:40:07 -04:00
|
|
|
IntegrationWorker.perform_async(1, 2)
|
|
|
|
IntegrationWorker.perform_async(1, 3)
|
2012-02-03 13:02:57 -05:00
|
|
|
|
|
|
|
q = TimedQueue.new
|
2012-02-16 12:45:55 -05:00
|
|
|
mgr = Sidekiq::Manager.new(:queues => [:foo], :concurrency => 2)
|
2012-02-03 13:02:57 -05:00
|
|
|
mgr.when_done do |_|
|
|
|
|
q << 'done' if $processed == 2
|
|
|
|
end
|
|
|
|
mgr.start!
|
2012-02-07 06:29:09 -05:00
|
|
|
result = q.timed_pop(1.0)
|
2012-02-03 13:02:57 -05:00
|
|
|
assert_equal 'done', result
|
|
|
|
mgr.stop
|
2012-04-24 22:58:52 -04:00
|
|
|
mgr.terminate
|
|
|
|
|
|
|
|
# Gross bloody hack because I can't get the actor threads
|
|
|
|
# to shut down cleanly in the test. Need @bascule's help here.
|
|
|
|
(Thread.list - [Thread.current]).each do |t|
|
|
|
|
t.raise Interrupt
|
|
|
|
end
|
2012-02-03 13:02:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|