mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Test suite overhaul
Remove Redis mocking. Minimize Redis flushing where possible.
This commit is contained in:
parent
9c27882aa8
commit
53e6b9e2df
19 changed files with 344 additions and 658 deletions
|
@ -3,23 +3,16 @@ require_relative 'helper'
|
|||
class TestApi < Sidekiq::Test
|
||||
|
||||
describe "stats" do
|
||||
before do
|
||||
@before = DateTime::DATE_FORMATS[:default]
|
||||
DateTime::DATE_FORMATS[:default] = "%d/%m/%Y %H:%M:%S"
|
||||
Sidekiq.redis = REDIS
|
||||
Sidekiq.redis {|c| c.flushdb }
|
||||
end
|
||||
|
||||
after do
|
||||
DateTime::DATE_FORMATS[:default] = @before
|
||||
it "is initially zero" do
|
||||
Sidekiq.redis {|c| c.flushdb }
|
||||
s = Sidekiq::Stats.new
|
||||
assert_equal 0, s.processed
|
||||
assert_equal 0, s.failed
|
||||
assert_equal 0, s.enqueued
|
||||
end
|
||||
|
||||
describe "processed" do
|
||||
it "is initially zero" do
|
||||
s = Sidekiq::Stats.new
|
||||
assert_equal 0, s.processed
|
||||
end
|
||||
|
||||
it "returns number of processed jobs" do
|
||||
Sidekiq.redis { |conn| conn.set("stat:processed", 5) }
|
||||
s = Sidekiq::Stats.new
|
||||
|
@ -28,11 +21,6 @@ class TestApi < Sidekiq::Test
|
|||
end
|
||||
|
||||
describe "failed" do
|
||||
it "is initially zero" do
|
||||
s = Sidekiq::Stats.new
|
||||
assert_equal 0, s.failed
|
||||
end
|
||||
|
||||
it "returns number of failed jobs" do
|
||||
Sidekiq.redis { |conn| conn.set("stat:failed", 5) }
|
||||
s = Sidekiq::Stats.new
|
||||
|
@ -50,40 +38,36 @@ class TestApi < Sidekiq::Test
|
|||
|
||||
it 'will reset all stats by default' do
|
||||
Sidekiq::Stats.new.reset
|
||||
Sidekiq.redis do |conn|
|
||||
assert_equal '0', conn.get('stat:processed')
|
||||
assert_equal '0', conn.get('stat:failed')
|
||||
end
|
||||
s = Sidekiq::Stats.new
|
||||
assert_equal 0, s.failed
|
||||
assert_equal 0, s.processed
|
||||
end
|
||||
|
||||
it 'can reset individual stats' do
|
||||
Sidekiq::Stats.new.reset('failed')
|
||||
Sidekiq.redis do |conn|
|
||||
assert_equal '5', conn.get('stat:processed')
|
||||
assert_equal '0', conn.get('stat:failed')
|
||||
end
|
||||
s = Sidekiq::Stats.new
|
||||
assert_equal 0, s.failed
|
||||
assert_equal 5, s.processed
|
||||
end
|
||||
|
||||
it 'can accept anything that responds to #to_s' do
|
||||
Sidekiq::Stats.new.reset(:failed)
|
||||
Sidekiq.redis do |conn|
|
||||
assert_equal '5', conn.get('stat:processed')
|
||||
assert_equal '0', conn.get('stat:failed')
|
||||
end
|
||||
s = Sidekiq::Stats.new
|
||||
assert_equal 0, s.failed
|
||||
assert_equal 5, s.processed
|
||||
end
|
||||
|
||||
it 'ignores anything other than "failed" or "processed"' do
|
||||
Sidekiq::Stats.new.reset((1..10).to_a, ['failed'])
|
||||
Sidekiq.redis do |conn|
|
||||
assert_equal '5', conn.get('stat:processed')
|
||||
assert_equal '0', conn.get('stat:failed')
|
||||
end
|
||||
s = Sidekiq::Stats.new
|
||||
assert_equal 0, s.failed
|
||||
assert_equal 5, s.processed
|
||||
end
|
||||
end
|
||||
|
||||
describe "queues" do
|
||||
it "returns all queues" do
|
||||
assert_equal Sidekiq::Stats.new.queues, Sidekiq::Stats::Queues.new.lengths
|
||||
before do
|
||||
Sidekiq.redis {|c| c.flushdb }
|
||||
end
|
||||
|
||||
it "is initially empty" do
|
||||
|
@ -103,17 +87,15 @@ class TestApi < Sidekiq::Test
|
|||
s = Sidekiq::Stats::Queues.new
|
||||
assert_equal ({ "foo" => 1, "bar" => 3 }), s.lengths
|
||||
assert_equal "bar", s.lengths.first.first
|
||||
|
||||
assert_equal Sidekiq::Stats.new.queues, Sidekiq::Stats::Queues.new.lengths
|
||||
end
|
||||
end
|
||||
|
||||
describe "enqueued" do
|
||||
it "is initially empty" do
|
||||
s = Sidekiq::Stats.new
|
||||
assert_equal 0, s.enqueued
|
||||
end
|
||||
|
||||
it "returns total enqueued jobs" do
|
||||
Sidekiq.redis do |conn|
|
||||
conn.flushdb
|
||||
conn.rpush 'queue:foo', '{}'
|
||||
conn.sadd 'queues', 'foo'
|
||||
|
||||
|
@ -127,6 +109,15 @@ class TestApi < Sidekiq::Test
|
|||
end
|
||||
|
||||
describe "over time" do
|
||||
before do
|
||||
@before = DateTime::DATE_FORMATS[:default]
|
||||
DateTime::DATE_FORMATS[:default] = "%d/%m/%Y %H:%M:%S"
|
||||
end
|
||||
|
||||
after do
|
||||
DateTime::DATE_FORMATS[:default] = @before
|
||||
end
|
||||
|
||||
describe "processed" do
|
||||
it 'retrieves hash of dates' do
|
||||
Sidekiq.redis do |c|
|
||||
|
@ -137,13 +128,13 @@ class TestApi < Sidekiq::Test
|
|||
end
|
||||
Time.stub(:now, Time.parse("2012-12-26 1:00:00 -0500")) do
|
||||
s = Sidekiq::Stats::History.new(2)
|
||||
assert_equal ({ "2012-12-26" => 6, "2012-12-25" => 1 }), s.processed
|
||||
assert_equal({ "2012-12-26" => 6, "2012-12-25" => 1 }, s.processed)
|
||||
|
||||
s = Sidekiq::Stats::History.new(3)
|
||||
assert_equal ({ "2012-12-26" => 6, "2012-12-25" => 1, "2012-12-24" => 4 }), s.processed
|
||||
assert_equal({ "2012-12-26" => 6, "2012-12-25" => 1, "2012-12-24" => 4 }, s.processed)
|
||||
|
||||
s = Sidekiq::Stats::History.new(2, Date.parse("2012-12-25"))
|
||||
assert_equal ({ "2012-12-25" => 1, "2012-12-24" => 4 }), s.processed
|
||||
assert_equal({ "2012-12-25" => 1, "2012-12-24" => 4 }, s.processed)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -172,10 +163,7 @@ class TestApi < Sidekiq::Test
|
|||
end
|
||||
|
||||
describe 'with an empty database' do
|
||||
include Sidekiq::Util
|
||||
|
||||
before do
|
||||
Sidekiq.redis = REDIS
|
||||
Sidekiq.redis {|c| c.flushdb }
|
||||
end
|
||||
|
||||
|
@ -389,7 +377,7 @@ class TestApi < Sidekiq::Test
|
|||
identity_string = "identity_string"
|
||||
odata = {
|
||||
'pid' => 123,
|
||||
'hostname' => hostname,
|
||||
'hostname' => Socket.gethostname,
|
||||
'key' => identity_string,
|
||||
'identity' => identity_string,
|
||||
'started_at' => Time.now.to_f - 15,
|
||||
|
@ -424,8 +412,9 @@ class TestApi < Sidekiq::Test
|
|||
assert false
|
||||
end
|
||||
|
||||
key = "#{hostname}:#{$$}"
|
||||
pdata = { 'pid' => $$, 'hostname' => hostname, 'started_at' => Time.now.to_i }
|
||||
hn = Socket.gethostname
|
||||
key = "#{hn}:#{$$}"
|
||||
pdata = { 'pid' => $$, 'hostname' => hn, 'started_at' => Time.now.to_i }
|
||||
Sidekiq.redis do |conn|
|
||||
conn.sadd('processes', key)
|
||||
conn.hmset(key, 'info', Sidekiq.dump_json(pdata), 'busy', 0, 'beat', Time.now.to_f)
|
||||
|
|
|
@ -168,35 +168,14 @@ class TestCli < Sidekiq::Test
|
|||
@cli.parse(['sidekiq', '-C', './test/config.yml'])
|
||||
end
|
||||
|
||||
it 'takes a path' do
|
||||
it 'parses as expected' do
|
||||
assert_equal './test/config.yml', Sidekiq.options[:config_file]
|
||||
end
|
||||
|
||||
it 'sets verbose' do
|
||||
refute Sidekiq.options[:verbose]
|
||||
end
|
||||
|
||||
it 'sets require file' do
|
||||
assert_equal './test/fake_env.rb', Sidekiq.options[:require]
|
||||
end
|
||||
|
||||
it 'does not set environment' do
|
||||
assert_equal nil, Sidekiq.options[:environment]
|
||||
end
|
||||
|
||||
it 'sets concurrency' do
|
||||
assert_equal 50, Sidekiq.options[:concurrency]
|
||||
end
|
||||
|
||||
it 'sets pid file' do
|
||||
assert_equal '/tmp/sidekiq-config-test.pid', Sidekiq.options[:pidfile]
|
||||
end
|
||||
|
||||
it 'sets logfile' do
|
||||
assert_equal '/tmp/sidekiq.log', Sidekiq.options[:logfile]
|
||||
end
|
||||
|
||||
it 'sets queues' do
|
||||
assert_equal 2, Sidekiq.options[:queues].count { |q| q == 'very_often' }
|
||||
assert_equal 1, Sidekiq.options[:queues].count { |q| q == 'seldom' }
|
||||
end
|
||||
|
@ -207,35 +186,14 @@ class TestCli < Sidekiq::Test
|
|||
@cli.parse(['sidekiq', '-e', 'staging', '-C', './test/env_based_config.yml'])
|
||||
end
|
||||
|
||||
it 'takes a path' do
|
||||
it 'parses as expected' do
|
||||
assert_equal './test/env_based_config.yml', Sidekiq.options[:config_file]
|
||||
end
|
||||
|
||||
it 'sets verbose' do
|
||||
refute Sidekiq.options[:verbose]
|
||||
end
|
||||
|
||||
it 'sets require file' do
|
||||
assert_equal './test/fake_env.rb', Sidekiq.options[:require]
|
||||
end
|
||||
|
||||
it 'sets environment' do
|
||||
assert_equal 'staging', Sidekiq.options[:environment]
|
||||
end
|
||||
|
||||
it 'sets concurrency' do
|
||||
assert_equal 5, Sidekiq.options[:concurrency]
|
||||
end
|
||||
|
||||
it 'sets pid file' do
|
||||
assert_equal '/tmp/sidekiq-config-test.pid', Sidekiq.options[:pidfile]
|
||||
end
|
||||
|
||||
it 'sets logfile' do
|
||||
assert_equal '/tmp/sidekiq.log', Sidekiq.options[:logfile]
|
||||
end
|
||||
|
||||
it 'sets queues' do
|
||||
assert_equal 2, Sidekiq.options[:queues].count { |q| q == 'very_often' }
|
||||
assert_equal 1, Sidekiq.options[:queues].count { |q| q == 'seldom' }
|
||||
end
|
||||
|
@ -297,23 +255,11 @@ class TestCli < Sidekiq::Test
|
|||
File.unlink @tmp_path if File.exist? @tmp_path
|
||||
end
|
||||
|
||||
it 'uses concurrency flag' do
|
||||
it 'gives the expected options' do
|
||||
assert_equal 100, Sidekiq.options[:concurrency]
|
||||
end
|
||||
|
||||
it 'uses require file flag' do
|
||||
assert_equal @tmp_lib_path, Sidekiq.options[:require]
|
||||
end
|
||||
|
||||
it 'uses environment flag' do
|
||||
assert_equal 'snoop', Sidekiq.options[:environment]
|
||||
end
|
||||
|
||||
it 'uses pidfile flag' do
|
||||
assert_equal @tmp_path, Sidekiq.options[:pidfile]
|
||||
end
|
||||
|
||||
it 'sets queues' do
|
||||
assert_equal 7, Sidekiq.options[:queues].count { |q| q == 'often' }
|
||||
assert_equal 3, Sidekiq.options[:queues].count { |q| q == 'seldom' }
|
||||
end
|
||||
|
|
|
@ -1,33 +1,7 @@
|
|||
require_relative 'helper'
|
||||
require 'sidekiq/client'
|
||||
require 'sidekiq/worker'
|
||||
|
||||
class TestClient < Sidekiq::Test
|
||||
describe 'with mock redis' do
|
||||
before do
|
||||
@redis = Minitest::Mock.new
|
||||
def @redis.multi; [yield] * 2 if block_given?; end
|
||||
def @redis.set(*); true; end
|
||||
def @redis.sadd(*); true; end
|
||||
def @redis.srem(*); true; end
|
||||
def @redis.get(*); nil; end
|
||||
def @redis.del(*); nil; end
|
||||
def @redis.incrby(*); nil; end
|
||||
def @redis.setex(*); true; end
|
||||
def @redis.expire(*); true; end
|
||||
def @redis.watch(*); true; end
|
||||
def @redis.with_connection; yield self; end
|
||||
def @redis.with; yield self; end
|
||||
def @redis.exec; true; end
|
||||
Sidekiq.instance_variable_set(:@redis, @redis)
|
||||
Sidekiq::Client.instance_variable_set(:@default, nil)
|
||||
end
|
||||
|
||||
after do
|
||||
Sidekiq.redis = REDIS
|
||||
Sidekiq::Client.instance_variable_set(:@default, nil)
|
||||
end
|
||||
|
||||
describe 'errors' do
|
||||
it 'raises ArgumentError with invalid params' do
|
||||
assert_raises ArgumentError do
|
||||
Sidekiq::Client.push('foo', 1)
|
||||
|
@ -49,112 +23,71 @@ class TestClient < Sidekiq::Test
|
|||
Sidekiq::Client.push('queue' => 'foo', 'class' => MyWorker, 'args' => 1)
|
||||
end
|
||||
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,r); $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
|
||||
describe 'as instance' do
|
||||
it 'can push' do
|
||||
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
|
||||
$called = false
|
||||
mware = Class.new { def call(worker_klass,msg,q,r); $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
|
||||
|
||||
describe 'client' do
|
||||
it 'pushes messages to redis' do
|
||||
@redis.expect :lpush, 1, ['queue:foo', Array]
|
||||
pushed = Sidekiq::Client.push('queue' => 'foo', 'class' => MyWorker, 'args' => [1, 2])
|
||||
assert pushed
|
||||
assert_equal 24, pushed.size
|
||||
@redis.verify
|
||||
q = Sidekiq::Queue.new('foo')
|
||||
pre = q.size
|
||||
jid = Sidekiq::Client.push('queue' => 'foo', 'class' => MyWorker, 'args' => [1, 2])
|
||||
assert jid
|
||||
assert_equal 24, jid.size
|
||||
assert_equal pre + 1, q.size
|
||||
end
|
||||
|
||||
it 'pushes messages to redis using a String class' do
|
||||
@redis.expect :lpush, 1, ['queue:foo', Array]
|
||||
pushed = Sidekiq::Client.push('queue' => 'foo', 'class' => 'MyWorker', 'args' => [1, 2])
|
||||
assert pushed
|
||||
assert_equal 24, pushed.size
|
||||
@redis.verify
|
||||
q = Sidekiq::Queue.new('foo')
|
||||
pre = q.size
|
||||
jid = Sidekiq::Client.push('queue' => 'foo', 'class' => 'MyWorker', 'args' => [1, 2])
|
||||
assert jid
|
||||
assert_equal 24, jid.size
|
||||
assert_equal pre + 1, q.size
|
||||
end
|
||||
|
||||
class MyWorker
|
||||
include Sidekiq::Worker
|
||||
end
|
||||
|
||||
it 'has default options' do
|
||||
assert_equal Sidekiq.default_worker_options, MyWorker.get_sidekiq_options
|
||||
end
|
||||
|
||||
it 'handles perform_async' do
|
||||
@redis.expect :lpush, 1, ['queue:default', Array]
|
||||
pushed = MyWorker.perform_async(1, 2)
|
||||
assert pushed
|
||||
@redis.verify
|
||||
end
|
||||
|
||||
it 'enqueues messages to redis' do
|
||||
@redis.expect :lpush, 1, ['queue:default', Array]
|
||||
pushed = Sidekiq::Client.enqueue(MyWorker, 1, 2)
|
||||
assert pushed
|
||||
@redis.verify
|
||||
end
|
||||
|
||||
it 'enqueues messages to redis' do
|
||||
@redis.expect :lpush, 1, ['queue:custom_queue', Array]
|
||||
pushed = Sidekiq::Client.enqueue_to(:custom_queue, MyWorker, 1, 2)
|
||||
assert pushed
|
||||
@redis.verify
|
||||
end
|
||||
|
||||
it 'enqueues messages to redis (delayed, custom queue)' do
|
||||
@redis.expect :zadd, 1, ['schedule', Array]
|
||||
pushed = Sidekiq::Client.enqueue_to_in(:custom_queue, 3.minutes, MyWorker, 1, 2)
|
||||
assert pushed
|
||||
@redis.verify
|
||||
end
|
||||
|
||||
it 'enqueues messages to redis (delayed into past, custom queue)' do
|
||||
@redis.expect :lpush, 1, ['queue:custom_queue', Array]
|
||||
pushed = Sidekiq::Client.enqueue_to_in(:custom_queue, -3.minutes, MyWorker, 1, 2)
|
||||
assert pushed
|
||||
@redis.verify
|
||||
end
|
||||
|
||||
it 'enqueues messages to redis (delayed)' do
|
||||
@redis.expect :zadd, 1, ['schedule', Array]
|
||||
pushed = Sidekiq::Client.enqueue_in(3.minutes, MyWorker, 1, 2)
|
||||
assert pushed
|
||||
@redis.verify
|
||||
end
|
||||
|
||||
class QueuedWorker
|
||||
include Sidekiq::Worker
|
||||
sidekiq_options :queue => :flimflam
|
||||
end
|
||||
|
||||
it 'enqueues to the named queue' do
|
||||
@redis.expect :lpush, 1, ['queue:flimflam', Array]
|
||||
pushed = QueuedWorker.perform_async(1, 2)
|
||||
assert pushed
|
||||
@redis.verify
|
||||
end
|
||||
|
||||
it 'retrieves queues' do
|
||||
@redis.expect :smembers, ['bob'], ['queues']
|
||||
assert_equal ['bob'], Sidekiq::Queue.all.map(&:name)
|
||||
it 'enqueues' do
|
||||
Sidekiq.redis {|c| c.flushdb }
|
||||
assert_equal Sidekiq.default_worker_options, MyWorker.get_sidekiq_options
|
||||
assert MyWorker.perform_async(1, 2)
|
||||
assert Sidekiq::Client.enqueue(MyWorker, 1, 2)
|
||||
assert Sidekiq::Client.enqueue_to(:custom_queue, MyWorker, 1, 2)
|
||||
assert_equal 1, Sidekiq::Queue.new('custom_queue').size
|
||||
assert Sidekiq::Client.enqueue_to_in(:custom_queue, 3.minutes, MyWorker, 1, 2)
|
||||
assert Sidekiq::Client.enqueue_to_in(:custom_queue, -3.minutes, MyWorker, 1, 2)
|
||||
assert_equal 2, Sidekiq::Queue.new('custom_queue').size
|
||||
assert Sidekiq::Client.enqueue_in(3.minutes, MyWorker, 1, 2)
|
||||
assert QueuedWorker.perform_async(1, 2)
|
||||
assert_equal 1, Sidekiq::Queue.new('flimflam').size
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -191,24 +124,23 @@ class TestClient < Sidekiq::Test
|
|||
end
|
||||
|
||||
describe 'client middleware' do
|
||||
|
||||
class Stopper
|
||||
def call(worker_class, message, queue, r)
|
||||
def call(worker_class, job, queue, r)
|
||||
raise ArgumentError unless r
|
||||
yield if message['args'].first.odd?
|
||||
yield if job['args'].first.odd?
|
||||
end
|
||||
end
|
||||
|
||||
it 'can stop some of the jobs from pushing' do
|
||||
Sidekiq.client_middleware.add Stopper
|
||||
begin
|
||||
assert_equal nil, Sidekiq::Client.push('class' => MyWorker, 'args' => [0])
|
||||
assert_match(/[0-9a-f]{12}/, Sidekiq::Client.push('class' => MyWorker, 'args' => [1]))
|
||||
Sidekiq::Client.push_bulk('class' => MyWorker, 'args' => [[0], [1]]).each do |jid|
|
||||
assert_match(/[0-9a-f]{12}/, jid)
|
||||
end
|
||||
ensure
|
||||
Sidekiq.client_middleware.remove Stopper
|
||||
client = Sidekiq::Client.new
|
||||
client.middleware do |chain|
|
||||
chain.add Stopper
|
||||
end
|
||||
|
||||
assert_equal nil, client.push('class' => MyWorker, 'args' => [0])
|
||||
assert_match(/[0-9a-f]{12}/, client.push('class' => MyWorker, 'args' => [1]))
|
||||
client.push_bulk('class' => MyWorker, 'args' => [[0], [1]]).each do |jid|
|
||||
assert_match(/[0-9a-f]{12}/, jid)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -220,19 +152,10 @@ class TestClient < Sidekiq::Test
|
|||
end
|
||||
end
|
||||
|
||||
describe 'item normalization' do
|
||||
it 'defaults retry to true' do
|
||||
assert_equal true, Sidekiq::Client.new.__send__(:normalize_item, 'class' => QueuedWorker, 'args' => [])['retry']
|
||||
end
|
||||
|
||||
it "does not normalize numeric retry's" do
|
||||
assert_equal 2, Sidekiq::Client.new.__send__(:normalize_item, 'class' => CWorker, 'args' => [])['retry']
|
||||
end
|
||||
end
|
||||
|
||||
describe 'sharding' do
|
||||
class DWorker < BaseWorker
|
||||
end
|
||||
|
||||
it 'allows sidekiq_options to point to different Redi' do
|
||||
conn = MiniTest::Mock.new
|
||||
conn.expect(:multi, [0, 1])
|
||||
|
@ -240,6 +163,7 @@ class TestClient < Sidekiq::Test
|
|||
DWorker.perform_async(1,2,3)
|
||||
conn.verify
|
||||
end
|
||||
|
||||
it 'allows #via to point to different Redi' do
|
||||
conn = MiniTest::Mock.new
|
||||
conn.expect(:multi, [0, 1])
|
||||
|
@ -257,6 +181,7 @@ class TestClient < Sidekiq::Test
|
|||
assert_equal default, Sidekiq::Client.new.redis_pool
|
||||
conn.verify
|
||||
end
|
||||
|
||||
it 'allows Resque helpers to point to different Redi' do
|
||||
conn = MiniTest::Mock.new
|
||||
conn.expect(:multi, []) { |*args, &block| block.call }
|
||||
|
|
|
@ -23,30 +23,34 @@ class TestExtensions < Sidekiq::Test
|
|||
|
||||
it 'allows delayed execution of ActiveRecord class methods' do
|
||||
assert_equal [], Sidekiq::Queue.all.map(&:name)
|
||||
assert_equal 0, Sidekiq.redis {|c| c.llen('queue:default') }
|
||||
q = Sidekiq::Queue.new
|
||||
assert_equal 0, q.size
|
||||
MyModel.delay.long_class_method
|
||||
assert_equal ['default'], Sidekiq::Queue.all.map(&:name)
|
||||
assert_equal 1, Sidekiq.redis {|c| c.llen('queue:default') }
|
||||
assert_equal 1, q.size
|
||||
end
|
||||
|
||||
it 'uses and stringifies specified options' do
|
||||
assert_equal [], Sidekiq::Queue.all.map(&:name)
|
||||
assert_equal 0, Sidekiq.redis {|c| c.llen('queue:notdefault') }
|
||||
q = Sidekiq::Queue.new('notdefault')
|
||||
assert_equal 0, q.size
|
||||
MyModel.delay(queue: :notdefault).long_class_method
|
||||
assert_equal ['notdefault'], Sidekiq::Queue.all.map(&:name)
|
||||
assert_equal 1, Sidekiq.redis {|c| c.llen('queue:notdefault') }
|
||||
assert_equal 1, q.size
|
||||
end
|
||||
|
||||
it 'allows delayed scheduling of AR class methods' do
|
||||
assert_equal 0, Sidekiq.redis {|c| c.zcard('schedule') }
|
||||
ss = Sidekiq::ScheduledSet.new
|
||||
assert_equal 0, ss.size
|
||||
MyModel.delay_for(5.days).long_class_method
|
||||
assert_equal 1, Sidekiq.redis {|c| c.zcard('schedule') }
|
||||
assert_equal 1, ss.size
|
||||
end
|
||||
|
||||
it 'allows until delayed scheduling of AR class methods' do
|
||||
assert_equal 0, Sidekiq.redis {|c| c.zcard('schedule') }
|
||||
ss = Sidekiq::ScheduledSet.new
|
||||
assert_equal 0, ss.size
|
||||
MyModel.delay_until(1.day.from_now).long_class_method
|
||||
assert_equal 1, Sidekiq.redis {|c| c.zcard('schedule') }
|
||||
assert_equal 1, ss.size
|
||||
end
|
||||
|
||||
class UserMailer < ActionMailer::Base
|
||||
|
@ -57,22 +61,25 @@ class TestExtensions < Sidekiq::Test
|
|||
|
||||
it 'allows delayed delivery of ActionMailer mails' do
|
||||
assert_equal [], Sidekiq::Queue.all.map(&:name)
|
||||
assert_equal 0, Sidekiq.redis {|c| c.llen('queue:default') }
|
||||
q = Sidekiq::Queue.new
|
||||
assert_equal 0, q.size
|
||||
UserMailer.delay.greetings(1, 2)
|
||||
assert_equal ['default'], Sidekiq::Queue.all.map(&:name)
|
||||
assert_equal 1, Sidekiq.redis {|c| c.llen('queue:default') }
|
||||
assert_equal 1, q.size
|
||||
end
|
||||
|
||||
it 'allows delayed scheduling of AM mails' do
|
||||
assert_equal 0, Sidekiq.redis {|c| c.zcard('schedule') }
|
||||
ss = Sidekiq::ScheduledSet.new
|
||||
assert_equal 0, ss.size
|
||||
UserMailer.delay_for(5.days).greetings(1, 2)
|
||||
assert_equal 1, Sidekiq.redis {|c| c.zcard('schedule') }
|
||||
assert_equal 1, ss.size
|
||||
end
|
||||
|
||||
it 'allows until delay scheduling of AM mails' do
|
||||
assert_equal 0, Sidekiq.redis {|c| c.zcard('schedule') }
|
||||
ss = Sidekiq::ScheduledSet.new
|
||||
assert_equal 0, ss.size
|
||||
UserMailer.delay_until(5.days.from_now).greetings(1, 2)
|
||||
assert_equal 1, Sidekiq.redis {|c| c.zcard('schedule') }
|
||||
assert_equal 1, ss.size
|
||||
end
|
||||
|
||||
class SomeClass
|
||||
|
@ -81,9 +88,10 @@ class TestExtensions < Sidekiq::Test
|
|||
end
|
||||
|
||||
it 'allows delay of any ole class method' do
|
||||
assert_equal 0, queue_size
|
||||
q = Sidekiq::Queue.new
|
||||
assert_equal 0, q.size
|
||||
SomeClass.delay.doit(Date.today)
|
||||
assert_equal 1, queue_size
|
||||
assert_equal 1, q.size
|
||||
end
|
||||
|
||||
module SomeModule
|
||||
|
@ -92,18 +100,16 @@ class TestExtensions < Sidekiq::Test
|
|||
end
|
||||
|
||||
it 'allows delay of any module class method' do
|
||||
assert_equal 0, queue_size
|
||||
q = Sidekiq::Queue.new
|
||||
assert_equal 0, q.size
|
||||
SomeModule.delay.doit(Date.today)
|
||||
assert_equal 1, queue_size
|
||||
end
|
||||
|
||||
def queue_size(name='default')
|
||||
Sidekiq::Queue.new(name).size
|
||||
assert_equal 1, q.size
|
||||
end
|
||||
|
||||
it 'allows removing of the #delay methods' do
|
||||
q = Sidekiq::Queue.new
|
||||
Sidekiq.remove_delay!
|
||||
assert_equal 0, queue_size
|
||||
assert_equal 0, q.size
|
||||
assert_raises NoMethodError do
|
||||
SomeModule.delay.doit(Date.today)
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require_relative 'helper'
|
||||
require 'sidekiq/logging'
|
||||
|
||||
class TestFetcher < Sidekiq::Test
|
||||
class TestLogging < Sidekiq::Test
|
||||
describe Sidekiq::Logging do
|
||||
describe "#with_context" do
|
||||
def context
|
||||
|
|
|
@ -5,7 +5,6 @@ class TestManager < Sidekiq::Test
|
|||
|
||||
describe 'manager' do
|
||||
before do
|
||||
Sidekiq.redis = REDIS
|
||||
Sidekiq.redis {|c| c.flushdb }
|
||||
end
|
||||
|
||||
|
|
|
@ -10,8 +10,6 @@ class TestProcessor < Sidekiq::Test
|
|||
$invokes = 0
|
||||
@boss = Minitest::Mock.new
|
||||
@processor = ::Sidekiq::Processor.new(@boss)
|
||||
Celluloid.logger = nil
|
||||
Sidekiq.redis = REDIS
|
||||
end
|
||||
|
||||
class MockWorker
|
||||
|
@ -192,18 +190,8 @@ class TestProcessor < Sidekiq::Test
|
|||
Sidekiq.redis {|c| c.flushdb }
|
||||
end
|
||||
|
||||
def with_expire(time)
|
||||
begin
|
||||
old = Sidekiq::Processor::STATS_TIMEOUT
|
||||
silence_warnings { Sidekiq::Processor.const_set(:STATS_TIMEOUT, time) }
|
||||
yield
|
||||
ensure
|
||||
silence_warnings { Sidekiq::Processor.const_set(:STATS_TIMEOUT, old) }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when successful' do
|
||||
let(:processed_today_key) { "stat:processed:#{Time.now.utc.to_date}" }
|
||||
let(:processed_today_key) { "stat:processed:#{Time.now.utc.strftime("%Y-%m-%d")}" }
|
||||
|
||||
def successful_job
|
||||
msg = Sidekiq.dump_json({ 'class' => MockWorker.to_s, 'args' => ['myarg'] })
|
||||
|
@ -216,23 +204,15 @@ class TestProcessor < Sidekiq::Test
|
|||
end
|
||||
|
||||
it 'increments processed stat' do
|
||||
assert_equal 0, Sidekiq::Stats.new.processed
|
||||
successful_job
|
||||
assert_equal 1, Sidekiq::Stats.new.processed
|
||||
end
|
||||
|
||||
it 'expires processed stat' do
|
||||
successful_job
|
||||
assert_equal Sidekiq::Processor::STATS_TIMEOUT, Sidekiq.redis { |conn| conn.ttl(processed_today_key) }
|
||||
end
|
||||
|
||||
it 'increments date processed stat' do
|
||||
successful_job
|
||||
assert_equal 1, Sidekiq.redis { |conn| conn.get(processed_today_key) }.to_i
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when failed' do
|
||||
let(:failed_today_key) { "stat:failed:#{Time.now.utc.to_date}" }
|
||||
let(:failed_today_key) { "stat:failed:#{Time.now.utc.strftime("%Y-%m-%d")}" }
|
||||
|
||||
def failed_job
|
||||
actor = Minitest::Mock.new
|
||||
|
@ -246,17 +226,9 @@ class TestProcessor < Sidekiq::Test
|
|||
end
|
||||
|
||||
it 'increments failed stat' do
|
||||
assert_equal 0, Sidekiq::Stats.new.failed
|
||||
failed_job
|
||||
assert_equal 1, Sidekiq::Stats.new.failed
|
||||
end
|
||||
|
||||
it 'increments date failed stat' do
|
||||
failed_job
|
||||
assert_equal 1, Sidekiq.redis { |conn| conn.get(failed_today_key) }.to_i
|
||||
end
|
||||
|
||||
it 'expires failed stat' do
|
||||
failed_job
|
||||
assert_equal Sidekiq::Processor::STATS_TIMEOUT, Sidekiq.redis { |conn| conn.ttl(failed_today_key) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
require_relative 'helper'
|
||||
require 'sidekiq'
|
||||
require 'sidekiq/web_helpers'
|
||||
|
||||
$HAS_AJ = true
|
||||
begin
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
require_relative 'helper'
|
||||
require 'sidekiq/redis_connection'
|
||||
|
||||
class TestRedisConnection < Sidekiq::Test
|
||||
|
||||
|
|
|
@ -5,175 +5,136 @@ require 'sidekiq/middleware/server/retry_jobs'
|
|||
|
||||
class TestRetry < Sidekiq::Test
|
||||
describe 'middleware' do
|
||||
class SomeWorker
|
||||
include Sidekiq::Worker
|
||||
end
|
||||
|
||||
before do
|
||||
@redis = Minitest::Mock.new
|
||||
# Ugh, this is terrible.
|
||||
Sidekiq.instance_variable_set(:@redis, @redis)
|
||||
|
||||
def @redis.with; yield self; end
|
||||
def @redis.multi; yield self; end
|
||||
Sidekiq.redis {|c| c.flushdb }
|
||||
end
|
||||
|
||||
after do
|
||||
Sidekiq.redis = REDIS
|
||||
def worker
|
||||
@worker ||= SomeWorker.new
|
||||
end
|
||||
|
||||
let(:worker) do
|
||||
Class.new do
|
||||
include ::Sidekiq::Worker
|
||||
end
|
||||
def handler(options={})
|
||||
@handler ||= Sidekiq::Middleware::Server::RetryJobs.new(options)
|
||||
end
|
||||
|
||||
def job(options={})
|
||||
@job ||= { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => true }.merge(options)
|
||||
end
|
||||
|
||||
it 'allows disabling retry' do
|
||||
msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => false }
|
||||
msg2 = msg.dup
|
||||
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
||||
assert_raises RuntimeError do
|
||||
handler.call(worker, msg2, 'default') do
|
||||
handler.call(worker, job('retry' => false), 'default') do
|
||||
raise "kerblammo!"
|
||||
end
|
||||
end
|
||||
assert_equal msg, msg2
|
||||
assert_equal 0, Sidekiq::RetrySet.new.size
|
||||
end
|
||||
|
||||
it 'allows a numeric retry' do
|
||||
@redis.expect :zadd, 1, ['retry', String, String]
|
||||
msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => 2 }
|
||||
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
||||
assert_raises RuntimeError do
|
||||
handler.call(worker, msg, 'default') do
|
||||
handler.call(worker, job('retry' => 2), 'default') do
|
||||
raise "kerblammo!"
|
||||
end
|
||||
end
|
||||
msg.delete('failed_at')
|
||||
assert_equal({"class"=>"Bob", "args"=>[1, 2, "foo"], "retry"=>2, "queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "retry_count"=>0}, msg)
|
||||
@redis.verify
|
||||
assert_equal 1, Sidekiq::RetrySet.new.size
|
||||
assert_equal 0, Sidekiq::DeadSet.new.size
|
||||
end
|
||||
|
||||
it 'allows 0 retry => no retry and dead queue' do
|
||||
@redis.expect :zadd, 1, ['dead', Float, String]
|
||||
@redis.expect :zremrangebyscore, 0, ['dead', String, Float]
|
||||
@redis.expect :zremrangebyrank, 0, ['dead', Numeric, Numeric]
|
||||
msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => 0 }
|
||||
msg2 = msg.dup
|
||||
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
||||
assert_raises RuntimeError do
|
||||
handler.call(worker, msg, 'default') do
|
||||
handler.call(worker, job('retry' => 0), 'default') do
|
||||
raise "kerblammo!"
|
||||
end
|
||||
end
|
||||
msg.delete('failed_at')
|
||||
expected = msg2.merge "queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "retry_count"=>0
|
||||
assert_equal expected, msg
|
||||
@redis.verify # not called
|
||||
assert_equal 0, Sidekiq::RetrySet.new.size
|
||||
assert_equal 1, Sidekiq::DeadSet.new.size
|
||||
end
|
||||
|
||||
it 'handles zany characters in error message, #1705' do
|
||||
skip 'skipped! test requires ruby 2.1+' if RUBY_VERSION <= '2.1.0'
|
||||
@redis.expect :zadd, 1, ['retry', String, String]
|
||||
msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => 2 }
|
||||
msg2 = msg.dup
|
||||
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
||||
|
||||
assert_raises RuntimeError do
|
||||
handler.call(worker, msg2, 'default') do
|
||||
handler.call(worker, job, 'default') do
|
||||
raise "kerblammo! #{195.chr}"
|
||||
end
|
||||
end
|
||||
msg2.delete('failed_at')
|
||||
assert_equal({"class"=>"Bob", "args"=>[1, 2, "foo"], "retry"=>2, "queue"=>"default", "error_message"=>"kerblammo! <20>", "error_class"=>"RuntimeError", "retry_count"=>0}, msg2)
|
||||
@redis.verify
|
||||
assert_equal "kerblammo! <20>", job["error_message"]
|
||||
end
|
||||
|
||||
|
||||
it 'allows a max_retries option in initializer' do
|
||||
max_retries = 7
|
||||
1.upto(max_retries) do
|
||||
@redis.expect :zadd, 1, ['retry', String, String]
|
||||
end
|
||||
@redis.expect :zadd, 1, ['dead', Float, String]
|
||||
@redis.expect :zremrangebyscore, 0, ['dead', String, Float]
|
||||
@redis.expect :zremrangebyrank, 0, ['dead', Numeric, Numeric]
|
||||
msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => true }
|
||||
handler = Sidekiq::Middleware::Server::RetryJobs.new({:max_retries => max_retries})
|
||||
1.upto(max_retries + 1) do
|
||||
assert_raises RuntimeError do
|
||||
handler.call(worker, msg, 'default') do
|
||||
handler(:max_retries => max_retries).call(worker, job, 'default') do
|
||||
raise "kerblammo!"
|
||||
end
|
||||
end
|
||||
end
|
||||
@redis.verify
|
||||
|
||||
assert_equal max_retries, Sidekiq::RetrySet.new.size
|
||||
assert_equal 1, Sidekiq::DeadSet.new.size
|
||||
end
|
||||
|
||||
it 'saves backtraces' do
|
||||
@redis.expect :zadd, 1, ['retry', String, String]
|
||||
msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => true, 'backtrace' => true }
|
||||
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
||||
c = nil
|
||||
assert_raises RuntimeError do
|
||||
handler.call(worker, msg, 'default') do
|
||||
handler.call(worker, job('backtrace' => true), 'default') do
|
||||
c = caller(0); raise "kerblammo!"
|
||||
end
|
||||
end
|
||||
assert msg["error_backtrace"]
|
||||
assert_equal c[0], msg["error_backtrace"][0]
|
||||
@redis.verify
|
||||
assert job["error_backtrace"]
|
||||
assert_equal c[0], job["error_backtrace"][0]
|
||||
end
|
||||
|
||||
it 'saves partial backtraces' do
|
||||
@redis.expect :zadd, 1, ['retry', String, String]
|
||||
msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => true, 'backtrace' => 3 }
|
||||
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
||||
c = nil
|
||||
assert_raises RuntimeError do
|
||||
handler.call(worker, msg, 'default') do
|
||||
handler.call(worker, job('backtrace' => 3), 'default') do
|
||||
c = caller(0)[0...3]; raise "kerblammo!"
|
||||
end
|
||||
end
|
||||
assert msg["error_backtrace"]
|
||||
assert_equal c, msg["error_backtrace"]
|
||||
assert job["error_backtrace"]
|
||||
assert_equal c, job["error_backtrace"]
|
||||
assert_equal 3, c.size
|
||||
assert_equal 3, msg["error_backtrace"].size
|
||||
end
|
||||
|
||||
it 'handles a new failed message' do
|
||||
@redis.expect :zadd, 1, ['retry', String, String]
|
||||
msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => true }
|
||||
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
||||
assert_raises RuntimeError do
|
||||
handler.call(worker, msg, 'default') do
|
||||
handler.call(worker, job, 'default') do
|
||||
raise "kerblammo!"
|
||||
end
|
||||
end
|
||||
assert_equal 'default', msg["queue"]
|
||||
assert_equal 'kerblammo!', msg["error_message"]
|
||||
assert_equal 'RuntimeError', msg["error_class"]
|
||||
assert_equal 0, msg["retry_count"]
|
||||
refute msg["error_backtrace"]
|
||||
assert msg["failed_at"]
|
||||
@redis.verify
|
||||
assert_equal 'default', job["queue"]
|
||||
assert_equal 'kerblammo!', job["error_message"]
|
||||
assert_equal 'RuntimeError', job["error_class"]
|
||||
assert_equal 0, job["retry_count"]
|
||||
refute job["error_backtrace"]
|
||||
assert job["failed_at"]
|
||||
end
|
||||
|
||||
it 'shuts down without retrying work-in-progress, which will resume' do
|
||||
@redis.expect :zadd, 1, ['retry', String, String]
|
||||
rs = Sidekiq::RetrySet.new
|
||||
assert_equal 0, rs.size
|
||||
msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => true }
|
||||
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
||||
assert_raises Sidekiq::Shutdown do
|
||||
handler.call(worker, msg, 'default') do
|
||||
raise Sidekiq::Shutdown
|
||||
end
|
||||
end
|
||||
assert_raises(MockExpectationError, "zadd should not be called") do
|
||||
@redis.verify
|
||||
end
|
||||
assert_equal 0, rs.size
|
||||
end
|
||||
|
||||
it 'shuts down cleanly when shutdown causes exception' do
|
||||
skip('Not supported in Ruby < 2.1.0') if RUBY_VERSION < '2.1.0'
|
||||
|
||||
@redis.expect :zadd, 1, ['retry', String, String]
|
||||
rs = Sidekiq::RetrySet.new
|
||||
assert_equal 0, rs.size
|
||||
msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => true }
|
||||
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
||||
assert_raises Sidekiq::Shutdown do
|
||||
handler.call(worker, msg, 'default') do
|
||||
begin
|
||||
|
@ -183,19 +144,16 @@ class TestRetry < Sidekiq::Test
|
|||
end
|
||||
end
|
||||
end
|
||||
assert_raises(MockExpectationError, "zadd should not be called") do
|
||||
@redis.verify
|
||||
end
|
||||
assert_equal 0, rs.size
|
||||
end
|
||||
|
||||
it 'shuts down cleanly when shutdown causes chained exceptions' do
|
||||
skip('Not supported in Ruby < 2.1.0') if RUBY_VERSION < '2.1.0'
|
||||
|
||||
@redis.expect :zadd, 1, ['retry', String, String]
|
||||
msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => true }
|
||||
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
||||
rs = Sidekiq::RetrySet.new
|
||||
assert_equal 0, rs.size
|
||||
assert_raises Sidekiq::Shutdown do
|
||||
handler.call(worker, msg, 'default') do
|
||||
handler.call(worker, job, 'default') do
|
||||
begin
|
||||
raise Sidekiq::Shutdown
|
||||
rescue Interrupt
|
||||
|
@ -207,93 +165,55 @@ class TestRetry < Sidekiq::Test
|
|||
end
|
||||
end
|
||||
end
|
||||
assert_raises(MockExpectationError, "zadd should not be called") do
|
||||
@redis.verify
|
||||
end
|
||||
assert_equal 0, rs.size
|
||||
end
|
||||
|
||||
it 'allows a retry queue' do
|
||||
@redis.expect :zadd, 1, ['retry', String, String]
|
||||
msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => true, 'retry_queue' => 'retry' }
|
||||
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
||||
assert_raises RuntimeError do
|
||||
handler.call(worker, msg, 'default') do
|
||||
handler.call(worker, job("retry_queue" => 'retryx'), 'default') do
|
||||
raise "kerblammo!"
|
||||
end
|
||||
end
|
||||
assert_equal 'retry', msg["queue"]
|
||||
assert_equal 'kerblammo!', msg["error_message"]
|
||||
assert_equal 'RuntimeError', msg["error_class"]
|
||||
assert_equal 0, msg["retry_count"]
|
||||
refute msg["error_backtrace"]
|
||||
assert msg["failed_at"]
|
||||
@redis.verify
|
||||
assert_equal 'retryx', job["queue"]
|
||||
assert_equal 'kerblammo!', job["error_message"]
|
||||
assert_equal 'RuntimeError', job["error_class"]
|
||||
assert_equal 0, job["retry_count"]
|
||||
refute job["error_backtrace"]
|
||||
assert job["failed_at"]
|
||||
end
|
||||
|
||||
it 'handles a recurring failed message' do
|
||||
@redis.expect :zadd, 1, ['retry', String, String]
|
||||
now = Time.now.to_f
|
||||
msg = {"class"=>"Bob", "args"=>[1, 2, "foo"], 'retry' => true, "queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "failed_at"=>now, "retry_count"=>10}
|
||||
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
||||
msg = {"queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "failed_at"=>now, "retry_count"=>10}
|
||||
assert_raises RuntimeError do
|
||||
handler.call(worker, msg, 'default') do
|
||||
handler.call(worker, job(msg), 'default') do
|
||||
raise "kerblammo!"
|
||||
end
|
||||
end
|
||||
assert_equal 'default', msg["queue"]
|
||||
assert_equal 'kerblammo!', msg["error_message"]
|
||||
assert_equal 'RuntimeError', msg["error_class"]
|
||||
assert_equal 11, msg["retry_count"]
|
||||
assert msg["failed_at"]
|
||||
@redis.verify
|
||||
end
|
||||
|
||||
it 'handles a recurring failed message before reaching user-specifed max' do
|
||||
@redis.expect :zadd, 1, ['retry', String, String]
|
||||
now = Time.now.to_f
|
||||
msg = {"class"=>"Bob", "args"=>[1, 2, "foo"], 'retry' => 10, "queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "failed_at"=>now, "retry_count"=>8}
|
||||
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
||||
assert_raises RuntimeError do
|
||||
handler.call(worker, msg, 'default') do
|
||||
raise "kerblammo!"
|
||||
end
|
||||
end
|
||||
assert_equal 'default', msg["queue"]
|
||||
assert_equal 'kerblammo!', msg["error_message"]
|
||||
assert_equal 'RuntimeError', msg["error_class"]
|
||||
assert_equal 9, msg["retry_count"]
|
||||
assert msg["failed_at"]
|
||||
@redis.verify
|
||||
assert_equal 'default', job["queue"]
|
||||
assert_equal 'kerblammo!', job["error_message"]
|
||||
assert_equal 'RuntimeError', job["error_class"]
|
||||
assert_equal 11, job["retry_count"]
|
||||
assert job["failed_at"]
|
||||
end
|
||||
|
||||
it 'throws away old messages after too many retries (using the default)' do
|
||||
q = Sidekiq::Queue.new
|
||||
rs = Sidekiq::RetrySet.new
|
||||
ds = Sidekiq::DeadSet.new
|
||||
assert_equal 0, q.size
|
||||
assert_equal 0, rs.size
|
||||
assert_equal 0, ds.size
|
||||
now = Time.now.to_f
|
||||
msg = {"class"=>"Bob", "args"=>[1, 2, "foo"], "queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "failed_at"=>now, "retry"=>true, "retry_count"=>25}
|
||||
@redis.expect :zadd, 1, ['dead', Float, String]
|
||||
@redis.expect :zremrangebyscore, 0, ['dead', String, Float]
|
||||
@redis.expect :zremrangebyrank, 0, ['dead', Numeric, Numeric]
|
||||
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
||||
msg = {"queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "failed_at"=>now, "retry_count"=>25}
|
||||
assert_raises RuntimeError do
|
||||
handler.call(worker, msg, 'default') do
|
||||
handler.call(worker, job(msg), 'default') do
|
||||
raise "kerblammo!"
|
||||
end
|
||||
end
|
||||
@redis.verify
|
||||
end
|
||||
|
||||
it 'throws away old messages after too many retries (using user-specified max)' do
|
||||
now = Time.now.to_f
|
||||
msg = {"class"=>"Bob", "args"=>[1, 2, "foo"], "queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "failed_at"=>now, "retry"=>3, "retry_count"=>3}
|
||||
@redis.expect :zadd, 1, ['dead', Float, String]
|
||||
@redis.expect :zremrangebyscore, 0, ['dead', String, Float]
|
||||
@redis.expect :zremrangebyrank, 0, ['dead', Numeric, Numeric]
|
||||
handler = Sidekiq::Middleware::Server::RetryJobs.new
|
||||
assert_raises RuntimeError do
|
||||
handler.call(worker, msg, 'default') do
|
||||
raise "kerblammo!"
|
||||
end
|
||||
end
|
||||
@redis.verify
|
||||
assert_equal 0, q.size
|
||||
assert_equal 0, rs.size
|
||||
assert_equal 1, ds.size
|
||||
end
|
||||
|
||||
describe "custom retry delay" do
|
||||
|
@ -309,38 +229,32 @@ class TestRetry < Sidekiq::Test
|
|||
File.unlink @tmp_log_path if File.exist?(@tmp_log_path)
|
||||
end
|
||||
|
||||
let(:custom_worker) do
|
||||
Class.new do
|
||||
include ::Sidekiq::Worker
|
||||
class CustomWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_retry_in do |count|
|
||||
count * 2
|
||||
end
|
||||
sidekiq_retry_in do |count|
|
||||
count * 2
|
||||
end
|
||||
end
|
||||
|
||||
let(:error_worker) do
|
||||
Class.new do
|
||||
include ::Sidekiq::Worker
|
||||
class ErrorWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_retry_in do |count|
|
||||
count / 0
|
||||
end
|
||||
sidekiq_retry_in do |count|
|
||||
count / 0
|
||||
end
|
||||
end
|
||||
|
||||
let(:handler) { Sidekiq::Middleware::Server::RetryJobs.new }
|
||||
|
||||
it "retries with a default delay" do
|
||||
refute_equal 4, handler.__send__(:delay_for, worker, 2)
|
||||
end
|
||||
|
||||
it "retries with a custom delay" do
|
||||
assert_equal 4, handler.__send__(:delay_for, custom_worker, 2)
|
||||
assert_equal 4, handler.__send__(:delay_for, CustomWorker, 2)
|
||||
end
|
||||
|
||||
it "falls back to the default retry on exception" do
|
||||
refute_equal 4, handler.__send__(:delay_for, error_worker, 2)
|
||||
refute_equal 4, handler.__send__(:delay_for, ErrorWorker, 2)
|
||||
assert_match(/Failure scheduling retry using the defined `sidekiq_retry_in`/,
|
||||
File.read(@tmp_log_path), 'Log entry missing for sidekiq_retry_in')
|
||||
end
|
||||
|
|
|
@ -10,11 +10,7 @@ class TestScheduled < Sidekiq::Test
|
|||
|
||||
describe 'poller' do
|
||||
before do
|
||||
Sidekiq.redis = REDIS
|
||||
Sidekiq.redis do |conn|
|
||||
conn.flushdb
|
||||
end
|
||||
|
||||
Sidekiq.redis{|c| c.flushdb}
|
||||
@error_1 = { 'class' => ScheduledWorker.name, 'args' => [0], 'queue' => 'queue_1' }
|
||||
@error_2 = { 'class' => ScheduledWorker.name, 'args' => [1], 'queue' => 'queue_2' }
|
||||
@error_3 = { 'class' => ScheduledWorker.name, 'args' => [2], 'queue' => 'queue_3' }
|
||||
|
@ -28,8 +24,8 @@ class TestScheduled < Sidekiq::Test
|
|||
end
|
||||
|
||||
class Stopper
|
||||
def call(worker_class, message, queue, r)
|
||||
yield if message['args'].first.odd?
|
||||
def call(worker_class, job, queue, r)
|
||||
yield if job['args'].first.odd?
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -43,12 +39,10 @@ class TestScheduled < Sidekiq::Test
|
|||
|
||||
@poller.poll
|
||||
|
||||
Sidekiq.redis do |conn|
|
||||
assert_equal 0, conn.llen("queue:queue_1")
|
||||
assert_equal 1, conn.llen("queue:queue_2")
|
||||
assert_equal 0, conn.llen("queue:queue_5")
|
||||
assert_equal 1, conn.llen("queue:queue_6")
|
||||
end
|
||||
assert_equal 0, Sidekiq::Queue.new("queue_1").size
|
||||
assert_equal 1, Sidekiq::Queue.new("queue_2").size
|
||||
assert_equal 0, Sidekiq::Queue.new("queue_5").size
|
||||
assert_equal 1, Sidekiq::Queue.new("queue_6").size
|
||||
ensure
|
||||
Sidekiq.client_middleware.remove Stopper
|
||||
end
|
||||
|
|
|
@ -3,20 +3,6 @@ require 'sidekiq/scheduled'
|
|||
|
||||
class TestScheduling < Sidekiq::Test
|
||||
describe 'middleware' do
|
||||
before do
|
||||
Sidekiq::Client.instance_variable_set(:@default, nil)
|
||||
@redis = Minitest::Mock.new
|
||||
# Ugh, this is terrible.
|
||||
Sidekiq.instance_variable_set(:@redis, @redis)
|
||||
def @redis.multi; [yield] * 2 if block_given?; end
|
||||
def @redis.with; yield self; end
|
||||
end
|
||||
|
||||
after do
|
||||
Sidekiq::Client.instance_variable_set(:@default, nil)
|
||||
Sidekiq.instance_variable_set(:@redis, REDIS)
|
||||
end
|
||||
|
||||
class ScheduledWorker
|
||||
include Sidekiq::Worker
|
||||
sidekiq_options :queue => :custom_queue
|
||||
|
@ -24,47 +10,37 @@ class TestScheduling < Sidekiq::Test
|
|||
end
|
||||
end
|
||||
|
||||
it 'schedules a job via interval' do
|
||||
@redis.expect :zadd, true, ['schedule', Array]
|
||||
it 'schedules jobs' do
|
||||
ss = Sidekiq::ScheduledSet.new
|
||||
ss.clear
|
||||
|
||||
assert_equal 0, ss.size
|
||||
|
||||
assert ScheduledWorker.perform_in(600, 'mike')
|
||||
@redis.verify
|
||||
end
|
||||
assert_equal 1, ss.size
|
||||
|
||||
it 'schedules a job in one month' do
|
||||
@redis.expect :zadd, true do |key, args|
|
||||
assert_equal 'schedule', key
|
||||
assert_in_delta 1.month.since.to_f, args[0][0].to_f, 1
|
||||
end
|
||||
assert ScheduledWorker.perform_in(1.month, 'mike')
|
||||
@redis.verify
|
||||
end
|
||||
assert_equal 2, ss.size
|
||||
|
||||
it 'schedules a job via timestamp' do
|
||||
@redis.expect :zadd, true, ['schedule', Array]
|
||||
assert ScheduledWorker.perform_in(5.days.from_now, 'mike')
|
||||
@redis.verify
|
||||
end
|
||||
assert_equal 3, ss.size
|
||||
|
||||
it 'schedules job right away on negative timestamp/interval' do
|
||||
@redis.expect :sadd, true, ['queues', 'custom_queue']
|
||||
@redis.expect :lpush, true, ['queue:custom_queue', Array]
|
||||
assert ScheduledWorker.perform_in(-300, 'mike')
|
||||
@redis.verify
|
||||
end
|
||||
assert_equal 3, ss.size
|
||||
assert_equal 1, Sidekiq::Queue.new("custom_queue").size
|
||||
|
||||
it 'schedules multiple jobs at once' do
|
||||
@redis.expect :zadd, true, ['schedule', Array]
|
||||
assert Sidekiq::Client.push_bulk('class' => ScheduledWorker, 'args' => [['mike'], ['mike']], 'at' => 600)
|
||||
@redis.verify
|
||||
assert_equal 5, ss.size
|
||||
end
|
||||
|
||||
it 'removes the enqueued_at field when scheduling' do
|
||||
@redis.expect :zadd, true do |key, args|
|
||||
job = Sidekiq.load_json(args.first.last)
|
||||
job.key?('created_at') && !job.key?('enqueued_at')
|
||||
end
|
||||
ss = Sidekiq::ScheduledSet.new
|
||||
ss.clear
|
||||
|
||||
assert ScheduledWorker.perform_in(1.month, 'mike')
|
||||
@redis.verify
|
||||
job = ss.first
|
||||
assert job['created_at']
|
||||
refute job['enqueued_at']
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -3,24 +3,16 @@ require_relative 'helper'
|
|||
|
||||
class TestSidekiq < Sidekiq::Test
|
||||
describe 'json processing' do
|
||||
it 'loads json' do
|
||||
assert_equal ({"foo" => "bar"}), Sidekiq.load_json("{\"foo\":\"bar\"}")
|
||||
end
|
||||
|
||||
it 'dumps json' do
|
||||
it 'handles json' do
|
||||
assert_equal({"foo" => "bar"}, Sidekiq.load_json("{\"foo\":\"bar\"}"))
|
||||
assert_equal "{\"foo\":\"bar\"}", Sidekiq.dump_json({ "foo" => "bar" })
|
||||
end
|
||||
end
|
||||
|
||||
describe "redis connection" do
|
||||
it "returns error without creating a connection if block is not given" do
|
||||
mock = Minitest::Mock.new
|
||||
mock.expect :create, nil #Sidekiq::RedisConnection, create
|
||||
assert_raises(ArgumentError) {
|
||||
assert_raises(ArgumentError) do
|
||||
Sidekiq.redis
|
||||
}
|
||||
assert_raises(MockExpectationError, "create should not be called") do
|
||||
mock.verify
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -56,14 +48,14 @@ class TestSidekiq < Sidekiq::Test
|
|||
end
|
||||
|
||||
describe 'default_worker_options' do
|
||||
before do
|
||||
it 'stringifies keys' do
|
||||
@old_options = Sidekiq.default_worker_options
|
||||
end
|
||||
after { Sidekiq.default_worker_options = @old_options }
|
||||
|
||||
it 'stringify keys' do
|
||||
Sidekiq.default_worker_options = { queue: 'cat'}
|
||||
assert_equal 'cat', Sidekiq.default_worker_options['queue']
|
||||
begin
|
||||
Sidekiq.default_worker_options = { queue: 'cat'}
|
||||
assert_equal 'cat', Sidekiq.default_worker_options['queue']
|
||||
ensure
|
||||
Sidekiq.default_worker_options = @old_options
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
require_relative 'helper'
|
||||
require 'sidekiq'
|
||||
require 'sidekiq/worker'
|
||||
|
||||
require 'active_record'
|
||||
require 'action_mailer'
|
||||
require 'sidekiq/rails'
|
||||
|
@ -13,7 +12,7 @@ class TestTesting < Sidekiq::Test
|
|||
describe 'sidekiq testing' do
|
||||
describe 'require/load sidekiq/testing.rb' do
|
||||
before do
|
||||
require 'sidekiq/testing.rb'
|
||||
require 'sidekiq/testing'
|
||||
end
|
||||
|
||||
after do
|
||||
|
@ -22,37 +21,43 @@ class TestTesting < Sidekiq::Test
|
|||
|
||||
it 'enables fake testing' do
|
||||
Sidekiq::Testing.fake!
|
||||
assert_equal true, Sidekiq::Testing.enabled?
|
||||
assert_equal true, Sidekiq::Testing.fake?
|
||||
assert Sidekiq::Testing.enabled?
|
||||
assert Sidekiq::Testing.fake?
|
||||
refute Sidekiq::Testing.inline?
|
||||
end
|
||||
|
||||
it 'enables fake testing in a block' do
|
||||
Sidekiq::Testing.disable!
|
||||
assert_equal true, Sidekiq::Testing.disabled?
|
||||
assert Sidekiq::Testing.disabled?
|
||||
refute Sidekiq::Testing.fake?
|
||||
|
||||
Sidekiq::Testing.fake! do
|
||||
assert_equal true, Sidekiq::Testing.enabled?
|
||||
assert_equal true, Sidekiq::Testing.fake?
|
||||
assert Sidekiq::Testing.enabled?
|
||||
assert Sidekiq::Testing.fake?
|
||||
refute Sidekiq::Testing.inline?
|
||||
end
|
||||
|
||||
assert_equal false, Sidekiq::Testing.enabled?
|
||||
assert_equal false, Sidekiq::Testing.fake?
|
||||
refute Sidekiq::Testing.enabled?
|
||||
refute Sidekiq::Testing.fake?
|
||||
end
|
||||
|
||||
it 'disables testing in a block' do
|
||||
Sidekiq::Testing.fake!
|
||||
assert Sidekiq::Testing.fake?
|
||||
|
||||
Sidekiq::Testing.disable! do
|
||||
assert_equal true, Sidekiq::Testing.disabled?
|
||||
refute Sidekiq::Testing.fake?
|
||||
assert Sidekiq::Testing.disabled?
|
||||
end
|
||||
|
||||
assert_equal true, Sidekiq::Testing.enabled?
|
||||
assert Sidekiq::Testing.fake?
|
||||
assert Sidekiq::Testing.enabled?
|
||||
end
|
||||
end
|
||||
|
||||
describe 'require/load sidekiq/testing/inline.rb' do
|
||||
before do
|
||||
require 'sidekiq/testing/inline.rb'
|
||||
require 'sidekiq/testing/inline'
|
||||
end
|
||||
|
||||
after do
|
||||
|
@ -61,22 +66,77 @@ class TestTesting < Sidekiq::Test
|
|||
|
||||
it 'enables inline testing' do
|
||||
Sidekiq::Testing.inline!
|
||||
assert_equal true, Sidekiq::Testing.enabled?
|
||||
assert_equal true, Sidekiq::Testing.inline?
|
||||
assert Sidekiq::Testing.enabled?
|
||||
assert Sidekiq::Testing.inline?
|
||||
refute Sidekiq::Testing.fake?
|
||||
end
|
||||
|
||||
it 'enables inline testing in a block' do
|
||||
Sidekiq::Testing.disable!
|
||||
assert_equal true, Sidekiq::Testing.disabled?
|
||||
assert Sidekiq::Testing.disabled?
|
||||
refute Sidekiq::Testing.fake?
|
||||
|
||||
Sidekiq::Testing.inline! do
|
||||
assert_equal true, Sidekiq::Testing.enabled?
|
||||
assert_equal true, Sidekiq::Testing.inline?
|
||||
assert Sidekiq::Testing.enabled?
|
||||
assert Sidekiq::Testing.inline?
|
||||
end
|
||||
|
||||
assert_equal false, Sidekiq::Testing.enabled?
|
||||
assert_equal false, Sidekiq::Testing.inline?
|
||||
refute Sidekiq::Testing.enabled?
|
||||
refute Sidekiq::Testing.inline?
|
||||
refute Sidekiq::Testing.fake?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with middleware' do
|
||||
before do
|
||||
require 'sidekiq/testing'
|
||||
end
|
||||
|
||||
after do
|
||||
Sidekiq::Testing.disable!
|
||||
end
|
||||
|
||||
class AttributeWorker
|
||||
include Sidekiq::Worker
|
||||
class_attribute :count
|
||||
self.count = 0
|
||||
attr_accessor :foo
|
||||
|
||||
def perform
|
||||
self.class.count += 1 if foo == :bar
|
||||
end
|
||||
end
|
||||
|
||||
class AttributeMiddleware
|
||||
def call(worker, msg, queue)
|
||||
worker.foo = :bar if worker.respond_to?(:foo=)
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
it 'wraps the inlined worker with middleware' do
|
||||
Sidekiq::Testing.server_middleware do |chain|
|
||||
chain.add AttributeMiddleware
|
||||
end
|
||||
|
||||
begin
|
||||
Sidekiq::Testing.fake! do
|
||||
AttributeWorker.perform_async
|
||||
assert_equal 0, AttributeWorker.count
|
||||
end
|
||||
|
||||
AttributeWorker.perform_one
|
||||
assert_equal 1, AttributeWorker.count
|
||||
|
||||
Sidekiq::Testing.inline! do
|
||||
AttributeWorker.perform_async
|
||||
assert_equal 2, AttributeWorker.count
|
||||
end
|
||||
ensure
|
||||
Sidekiq::Testing.server_middleware.clear
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
require_relative 'helper'
|
||||
require 'sidekiq'
|
||||
require 'sidekiq/worker'
|
||||
|
||||
require 'active_record'
|
||||
require 'action_mailer'
|
||||
require 'sidekiq/rails'
|
||||
|
@ -47,7 +46,7 @@ class TestTesting < Sidekiq::Test
|
|||
end
|
||||
|
||||
before do
|
||||
require 'sidekiq/testing.rb'
|
||||
require 'sidekiq/testing'
|
||||
Sidekiq::Testing.fake!
|
||||
EnqueuedWorker.jobs.clear
|
||||
DirectWorker.jobs.clear
|
||||
|
@ -106,7 +105,6 @@ class TestTesting < Sidekiq::Test
|
|||
StoredWorker.drain
|
||||
end
|
||||
assert_equal 0, StoredWorker.jobs.size
|
||||
|
||||
end
|
||||
|
||||
class SpecificJidWorker
|
||||
|
@ -263,47 +261,8 @@ class TestTesting < Sidekiq::Test
|
|||
end
|
||||
|
||||
it 'can execute a job' do
|
||||
worker = Minitest::Mock.new
|
||||
worker.expect(:perform, nil, [1, 2, 3])
|
||||
DirectWorker.execute_job(worker, [1, 2, 3])
|
||||
DirectWorker.execute_job(DirectWorker.new, [2, 3])
|
||||
end
|
||||
|
||||
describe 'with middleware' do
|
||||
class AttributeWorker
|
||||
include Sidekiq::Worker
|
||||
class_attribute :count
|
||||
self.count = 0
|
||||
attr_accessor :foo
|
||||
|
||||
def perform
|
||||
self.class.count += 1 if foo == :bar
|
||||
end
|
||||
end
|
||||
|
||||
class AttributeMiddleware
|
||||
def call(worker, msg, queue)
|
||||
worker.foo = :bar if worker.respond_to?(:foo=)
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
before do
|
||||
Sidekiq::Testing.server_middleware do |chain|
|
||||
chain.add AttributeMiddleware
|
||||
end
|
||||
end
|
||||
|
||||
after do
|
||||
Sidekiq::Testing.server_middleware do |chain|
|
||||
chain.clear
|
||||
end
|
||||
end
|
||||
|
||||
it 'wraps the inlined worker with middleware' do
|
||||
AttributeWorker.perform_async
|
||||
AttributeWorker.perform_one
|
||||
assert_equal 1, AttributeWorker.count
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
require_relative 'helper'
|
||||
require 'sidekiq'
|
||||
require 'sidekiq/worker'
|
||||
|
||||
require 'active_record'
|
||||
require 'action_mailer'
|
||||
require 'sidekiq/rails'
|
||||
|
@ -42,7 +41,7 @@ class TestInline < Sidekiq::Test
|
|||
end
|
||||
|
||||
before do
|
||||
require 'sidekiq/testing/inline.rb'
|
||||
require 'sidekiq/testing/inline'
|
||||
Sidekiq::Testing.inline!
|
||||
end
|
||||
|
||||
|
@ -90,41 +89,5 @@ class TestInline < Sidekiq::Test
|
|||
assert Sidekiq::Client.enqueue(InlineWorkerWithTimeParam, Time.now)
|
||||
end
|
||||
|
||||
describe 'with middleware' do
|
||||
class AttributeWorker
|
||||
include Sidekiq::Worker
|
||||
class_attribute :count
|
||||
self.count = 0
|
||||
attr_accessor :foo
|
||||
|
||||
def perform
|
||||
self.class.count += 1 if foo == :bar
|
||||
end
|
||||
end
|
||||
|
||||
class AttributeMiddleware
|
||||
def call(worker, msg, queue)
|
||||
worker.foo = :bar if worker.respond_to?(:foo=)
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
before do
|
||||
Sidekiq::Testing.server_middleware do |chain|
|
||||
chain.add AttributeMiddleware
|
||||
end
|
||||
end
|
||||
|
||||
after do
|
||||
Sidekiq::Testing.server_middleware do |chain|
|
||||
chain.clear
|
||||
end
|
||||
end
|
||||
|
||||
it 'wraps the inlined worker with middleware' do
|
||||
AttributeWorker.perform_async
|
||||
assert_equal 1, AttributeWorker.count
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
require_relative 'helper'
|
||||
require 'sidekiq'
|
||||
require 'sidekiq/web_helpers'
|
||||
|
||||
class TestUtil < Sidekiq::Test
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# encoding: utf-8
|
||||
require_relative 'helper'
|
||||
require 'sidekiq'
|
||||
require 'sidekiq/web'
|
||||
require 'rack/test'
|
||||
require 'tilt/erubis'
|
||||
|
@ -19,7 +18,6 @@ class TestWeb < Sidekiq::Test
|
|||
end
|
||||
|
||||
before do
|
||||
Sidekiq.redis = REDIS
|
||||
Sidekiq.redis {|c| c.flushdb }
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
require_relative 'helper'
|
||||
require 'sidekiq'
|
||||
require 'sidekiq/web_helpers'
|
||||
|
||||
class TestWebHelpers < Sidekiq::Test
|
||||
|
||||
|
|
Loading…
Reference in a new issue