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_stats.rb

70 lines
1.9 KiB
Ruby
Raw Normal View History

require 'helper'
require 'sidekiq'
require 'sidekiq/processor'
class TestStats < MiniTest::Unit::TestCase
describe 'with redis' do
before do
@redis = Sidekiq.redis = REDIS
2012-03-28 22:16:54 -04:00
Sidekiq.redis {|c| c.flushdb }
end
class DumbWorker
include Sidekiq::Worker
def perform(arg)
raise 'bang' if arg == nil
end
end
it 'updates global stats in the success case' do
msg = { 'class' => DumbWorker.to_s, 'args' => [""] }
boss = MiniTest::Mock.new
2012-02-11 02:32:42 -05:00
@redis.with do |conn|
2012-02-11 02:32:42 -05:00
set = conn.smembers('workers')
assert_equal 0, set.size
processor = Sidekiq::Processor.new(boss)
boss.expect(:processor_done!, nil, [processor])
2012-02-11 02:32:42 -05:00
assert_equal 0, conn.get('stat:failed').to_i
assert_equal 0, conn.get('stat:processed').to_i
assert_equal 0, conn.get("stat:processed:#{processor}").to_i
processor.process(msg, 'xyzzy')
processor.process(msg, 'xyzzy')
processor.process(msg, 'xyzzy')
assert_equal 0, conn.get('stat:failed').to_i
assert_equal 3, conn.get('stat:processed').to_i
assert_equal 3, conn.get("stat:processed:#{processor}").to_i
end
end
it 'updates global stats in the error case' do
msg = { 'class' => DumbWorker.to_s, 'args' => [nil] }
boss = MiniTest::Mock.new
2012-04-03 23:00:20 -04:00
@redis.with do |conn|
assert_equal [], conn.smembers('workers')
assert_equal 0, conn.get('stat:failed').to_i
assert_equal 0, conn.get('stat:processed').to_i
2012-04-03 23:00:20 -04:00
processor = Sidekiq::Processor.new(boss)
2012-02-11 02:32:42 -05:00
2012-04-03 23:00:20 -04:00
pstr = processor.to_s
assert_raises RuntimeError do
processor.process(msg, 'xyzzy')
end
2012-04-03 23:00:20 -04:00
assert_equal 1, conn.get('stat:failed').to_i
assert_equal 1, conn.get('stat:processed').to_i
assert_equal nil, conn.get("stat:processed:#{pstr}")
end
end
end
end