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_fetch.rb
Andrew Babichev ea9b34a953 Add CLI Run Test - Write Pid, System Boot, Print Banner (#4039)
* Add appraisal

* Test CLI run (write pid, system boot, print banner)

* Cleanup test helper

* Set REDIS_URL to use non-default host in test env

* Move mintiest-focus to test bundle group
2018-12-07 08:59:42 -08:00

46 lines
1.3 KiB
Ruby

# frozen_string_literal: true
require_relative 'helper'
require 'sidekiq/fetch'
require 'sidekiq/api'
class TestFetcher < Minitest::Test
describe 'fetcher' do
before do
Sidekiq.redis do |conn|
conn.flushdb
conn.rpush('queue:basic', 'msg')
end
end
it 'retrieves' do
fetch = Sidekiq::BasicFetch.new(:queues => ['basic', 'bar'])
uow = fetch.retrieve_work
refute_nil uow
assert_equal 'basic', uow.queue_name
assert_equal 'msg', uow.job
q = Sidekiq::Queue.new('basic')
assert_equal 0, q.size
uow.requeue
assert_equal 1, q.size
assert_nil uow.acknowledge
end
it 'retrieves with strict setting' do
fetch = Sidekiq::BasicFetch.new(:queues => ['basic', 'bar', 'bar'], :strict => true)
cmd = fetch.queues_cmd
assert_equal cmd, ['queue:basic', 'queue:bar', Sidekiq::BasicFetch::TIMEOUT]
end
it 'bulk requeues' do
q1 = Sidekiq::Queue.new('foo')
q2 = Sidekiq::Queue.new('bar')
assert_equal 0, q1.size
assert_equal 0, q2.size
uow = Sidekiq::BasicFetch::UnitOfWork
Sidekiq::BasicFetch.bulk_requeue([uow.new('fuzzy:queue:foo', 'bob'), uow.new('fuzzy:queue:foo', 'bar'), uow.new('fuzzy:queue:bar', 'widget')], {:queues => []})
assert_equal 2, q1.size
assert_equal 1, q2.size
end
end
end