2012-07-27 18:18:11 -04:00
|
|
|
require 'helper'
|
|
|
|
require 'sidekiq/fetch'
|
|
|
|
|
|
|
|
class TestFetcher < MiniTest::Unit::TestCase
|
2013-01-06 00:17:08 -05:00
|
|
|
|
|
|
|
def setup
|
2013-03-02 18:59:01 -05:00
|
|
|
Sidekiq.redis = { :namespace => 'fuzzy' }
|
2013-01-06 00:17:08 -05:00
|
|
|
Sidekiq.redis do |conn|
|
2013-01-17 00:53:48 -05:00
|
|
|
conn.flushdb
|
2013-01-06 00:17:08 -05:00
|
|
|
conn.rpush('queue:basic', 'msg')
|
2012-07-27 18:18:11 -04:00
|
|
|
end
|
|
|
|
end
|
2013-01-06 00:17:08 -05:00
|
|
|
|
|
|
|
def test_basic_fetch_retrieve
|
|
|
|
fetch = Sidekiq::BasicFetch.new(:queues => ['basic', 'bar'])
|
|
|
|
uow = fetch.retrieve_work
|
|
|
|
refute_nil uow
|
|
|
|
assert_equal 'basic', uow.queue_name
|
|
|
|
assert_equal 'msg', uow.message
|
|
|
|
q = Sidekiq::Queue.new('basic')
|
|
|
|
assert_equal 0, q.size
|
|
|
|
uow.requeue
|
|
|
|
assert_equal 1, q.size
|
|
|
|
assert_nil uow.acknowledge
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_basic_fetch_strict_retrieve
|
|
|
|
fetch = Sidekiq::BasicFetch.new(:queues => ['basic', 'bar', 'bar'], :strict => true)
|
|
|
|
cmd = fetch.queues_cmd
|
|
|
|
assert_equal cmd, ['queue:basic', 'queue:bar', 1]
|
|
|
|
end
|
2013-01-17 00:53:48 -05:00
|
|
|
|
|
|
|
def test_basic_fetch_bulk_requeue
|
|
|
|
q1 = Sidekiq::Queue.new('foo')
|
|
|
|
q2 = Sidekiq::Queue.new('bar')
|
|
|
|
assert_equal 0, q1.size
|
|
|
|
assert_equal 0, q2.size
|
|
|
|
uow = Sidekiq::BasicFetch::UnitOfWork
|
2013-03-02 18:59:01 -05:00
|
|
|
Sidekiq::BasicFetch.bulk_requeue([uow.new('fuzzy:queue:foo', 'bob'), uow.new('fuzzy:queue:foo', 'bar'), uow.new('fuzzy:queue:bar', 'widget')])
|
2013-01-17 00:53:48 -05:00
|
|
|
assert_equal 2, q1.size
|
|
|
|
assert_equal 1, q2.size
|
|
|
|
end
|
2012-07-27 18:18:11 -04:00
|
|
|
end
|