Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add tests for new client instances

  • Loading branch information...
commit e63a9d8863a43f2cbbe3e2efd34aa9fac9536143 1 parent fef6dac
@mperham authored
View
4 lib/sidekiq/middleware/chain.rb
@@ -64,6 +64,10 @@ class Chain
include Enumerable
attr_reader :entries
+ def initialize_copy(copy)
+ copy.instance_variable_set(:@entries, entries.dup)
+ end
+
def each(&block)
entries.each(&block)
end
View
30 test/test_client.rb
@@ -46,7 +46,30 @@ def @redis.exec; true; end
assert_raises ArgumentError do
Sidekiq::Client.push('queue' => 'foo', 'class' => MyWorker, 'args' => 1)
end
+ end
+
+ describe 'as instance' do
+ it 'can push' do
+ @redis.expect :lpush, 1, ['queue:default', Array]
+ client = Sidekiq::Client.new
+ jid = client.push('class' => 'Blah', 'args' => [1,2,3])
+ assert_equal 24, jid.size
+ end
+ it 'allows local middleware modification' do
+ @redis.expect :lpush, 1, ['queue:default', Array]
+ $called = false
+ mware = Class.new { def call(worker_klass,msg,q); $called = true; msg;end }
+ client = Sidekiq::Client.new
+ client.middleware do |chain|
+ chain.add mware
+ end
+ client.push('class' => 'Blah', 'args' => [1,2,3])
+
+ assert $called
+ assert client.middleware.exists?(mware)
+ refute Sidekiq.client_middleware.exists?(mware)
+ end
end
it 'pushes messages to redis' do
@@ -136,12 +159,7 @@ class QueuedWorker
it 'retrieves queues' do
@redis.expect :smembers, ['bob'], ['queues']
- assert_equal ['bob'], Sidekiq::Client.registered_queues
- end
-
- it 'retrieves workers' do
- @redis.expect :smembers, ['bob'], ['workers']
- assert_equal ['bob'], Sidekiq::Client.registered_workers
+ assert_equal ['bob'], Sidekiq::Queue.all.map(&:name)
end
end
View
12 test/test_extensions.rb
@@ -22,18 +22,18 @@ def self.long_class_method
end
it 'allows delayed execution of ActiveRecord class methods' do
- assert_equal [], Sidekiq::Client.registered_queues
+ assert_equal [], Sidekiq::Queue.all.map(&:name)
assert_equal 0, Sidekiq.redis {|c| c.llen('queue:default') }
MyModel.delay.long_class_method
- assert_equal ['default'], Sidekiq::Client.registered_queues
+ assert_equal ['default'], Sidekiq::Queue.all.map(&:name)
assert_equal 1, Sidekiq.redis {|c| c.llen('queue:default') }
end
it 'uses and stringifies specified options' do
- assert_equal [], Sidekiq::Client.registered_queues
+ assert_equal [], Sidekiq::Queue.all.map(&:name)
assert_equal 0, Sidekiq.redis {|c| c.llen('queue:notdefault') }
MyModel.delay(queue: :notdefault).long_class_method
- assert_equal ['notdefault'], Sidekiq::Client.registered_queues
+ assert_equal ['notdefault'], Sidekiq::Queue.all.map(&:name)
assert_equal 1, Sidekiq.redis {|c| c.llen('queue:notdefault') }
end
@@ -56,10 +56,10 @@ def greetings(a, b)
end
it 'allows delayed delivery of ActionMailer mails' do
- assert_equal [], Sidekiq::Client.registered_queues
+ assert_equal [], Sidekiq::Queue.all.map(&:name)
assert_equal 0, Sidekiq.redis {|c| c.llen('queue:default') }
UserMailer.delay.greetings(1, 2)
- assert_equal ['default'], Sidekiq::Client.registered_queues
+ assert_equal ['default'], Sidekiq::Queue.all.map(&:name)
assert_equal 1, Sidekiq.redis {|c| c.llen('queue:default') }
end
Please sign in to comment.
Something went wrong with that request. Please try again.