/
activity_monitor_spec.rb
38 lines (31 loc) · 1.07 KB
/
activity_monitor_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
require 'spec_helper'
describe Goliath::Chimp::Plugin::ActivityMonitor do
let(:log_output) { StringIO.new }
let(:logger) { Logger.new log_output }
let(:example_time){ Time.new(2014, 1, 1, 3, 15) }
subject(:monitor) { described_class.new('localhost', 3467, {}, {}, logger) }
before(:each){ Time.stub(:now).and_return(example_time, example_time + 30) }
context '#run' do
it 'establishes a periodic latency monitor' do
EM.synchrony do
monitor.should_receive(:report).with(reactor: { latency: 30.0, ratio: 300.0 })
monitor.run(window: 0.1)
EM::Synchrony.add_timer(0.2){ EM.stop }
end
end
end
context '#latency' do
it 'returns the latency' do
monitor.latency.should eq(30.0)
end
it 'updates the previous snapshot' do
expect{ monitor.latency }.to change{ monitor.previous }.from(example_time.to_f).to((example_time + 30).to_f)
end
end
context '#report' do
it 'logs the metric' do
monitor.logger.should_receive(:debug).with('metrics')
monitor.report 'metrics'
end
end
end