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_client.rb
Mike Perham a1f78816a7 Implement generic Ruby support via simple require flag
Various cleanups
It's "assert_equal(expected, actual)"
2012-02-09 20:32:59 -08:00

70 lines
2.1 KiB
Ruby

require 'helper'
require 'sidekiq/client'
require 'sidekiq/worker'
class TestClient < MiniTest::Unit::TestCase
describe 'with real redis' do
before do
Sidekiq::Client.redis = Redis.connect(:url => 'redis://localhost/sidekiq_test')
Sidekiq::Client.redis.flushdb
end
it 'does not push duplicate messages when configured for unique only' do
Sidekiq::Client.ignore_duplicate_jobs = true
10.times { Sidekiq::Client.push('customqueue', 'class' => 'Foo', 'args' => [1, 2]) }
assert_equal 1, Sidekiq::Client.redis.llen("queue:customqueue")
end
it 'does push duplicate messages when not configured for unique only' do
Sidekiq::Client.ignore_duplicate_jobs = false
10.times { Sidekiq::Client.push('customqueue2', 'class' => 'Foo', 'args' => [1, 2]) }
assert_equal 10, Sidekiq::Client.redis.llen("queue:customqueue2")
end
end
describe 'with mock redis' do
before do
@redis = MiniTest::Mock.new
def @redis.multi; yield; end
def @redis.set(*); true; end
def @redis.expire(*); true; end
Sidekiq::Client.redis = @redis
Sidekiq::Client.ignore_duplicate_jobs = false
end
it 'raises ArgumentError with invalid params' do
assert_raises ArgumentError do
Sidekiq::Client.push('foo', 1)
end
assert_raises ArgumentError do
Sidekiq::Client.push('foo', :class => 'Foo', :noargs => [1, 2])
end
end
it 'pushes messages to redis' do
@redis.expect :rpush, 1, ['queue:foo', String]
count = Sidekiq::Client.push('foo', 'class' => 'Foo', 'args' => [1, 2])
assert count > 0
@redis.verify
end
class MyWorker
include Sidekiq::Worker
end
it 'handles perform_async' do
@redis.expect :rpush, 1, ['queue:default', String]
count = MyWorker.perform_async(1, 2)
assert count > 0
@redis.verify
end
it 'enqueues messages to redis' do
@redis.expect :rpush, 1, ['queue:default', String]
count = Sidekiq::Client.enqueue(MyWorker, 1, 2)
assert count > 0
@redis.verify
end
end
end