Permalink
Browse files

activity_monitor specced

  • Loading branch information...
1 parent 7b4ff17 commit a47cbf65e75d9a0bc5685577bb6d1f788cf94077 @kornypoet kornypoet committed Feb 18, 2014
Showing with 38 additions and 0 deletions.
  1. +38 −0 spec/plugins/activity_monitor_spec.rb
@@ -0,0 +1,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

0 comments on commit a47cbf6

Please sign in to comment.