forked from sidekiq/sidekiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_stats.rb
68 lines (52 loc) · 1.82 KB
/
test_stats.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require 'helper'
require 'sidekiq'
require 'sidekiq/processor'
class TestStats < MiniTest::Unit::TestCase
describe 'with redis' do
before do
@redis = Sidekiq.redis = REDIS
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 = Sidekiq.dump_json({ 'class' => DumbWorker.to_s, 'args' => [""] })
boss = MiniTest::Mock.new
@redis.with do |conn|
set = conn.smembers('workers')
assert_equal 0, set.size
processor = Sidekiq::Processor.new(boss)
boss.expect(:processor_done!, nil, [processor])
boss.expect(:processor_done!, nil, [processor])
boss.expect(:processor_done!, nil, [processor])
assert_equal 0, conn.get('stat:failed').to_i
assert_equal 0, conn.get('stat:processed').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
end
end
it 'updates global stats in the error case' do
msg = Sidekiq.dump_json({ 'class' => DumbWorker.to_s, 'args' => [nil] })
boss = MiniTest::Mock.new
@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
processor = Sidekiq::Processor.new(boss)
pstr = processor.to_s
assert_raises RuntimeError do
processor.process(msg, 'xyzzy')
end
assert_equal 1, conn.get('stat:failed').to_i
assert_equal 1, conn.get('stat:processed').to_i
end
end
end
end