-
Notifications
You must be signed in to change notification settings - Fork 128
/
worker_spec.rb
62 lines (50 loc) · 1.44 KB
/
worker_spec.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
require 'spec_helper'
describe "worker" do
before(:all) do
@worker = Redmon::Worker.new
end
def mock_timer
double EM::PeriodicTimer
end
describe "#run!" do
it "should poll and record stats"
end
describe "#record_stats" do
it "should record a new stats entry in a redis sorted set" do
redis = mock_redis
redis.should_receive(:zadd).with(Redmon::Redis.stats_key, 'ts', 'stats')
@worker.stub(:stats).and_return(['ts', 'stats'])
@worker.record_stats
end
end
describe "#stats" do
it "should fetch info, dbsize and slowlog from redis" do
pending
redis = mock_redis
redis.should_receive(:info).with(no_args()).and_return({})
redis.should_receive(:dbsize).with(no_args()).and_return(0)
redis.should_receive(:slowlog).with(:get).and_return({})
@worker.stub(:entires).and_return([{}])
@worker.stats
end
end
describe "#entries" do
let (:slowlog) { [[1, 2, 3, ['cmd', 'args']]] }
it "should parse the sortlog into hashes" do
entries = @worker.entries slowlog
entries.length.should == 1
entry = entries.shift
entry.should == {
:id => 1,
:timestamp => 2000,
:process_time => 3,
:command => 'cmd args'
}
end
end
describe "#interval" do
it "should return the configured poll interval" do
@worker.interval.should == Redmon.config.poll_interval
end
end
end