diff options
author | Nash Kaminski <Nash.Kaminski@gs.com> | 2018-05-01 11:55:49 -0500 |
---|---|---|
committer | Nash Kaminski <Nash.Kaminski@gs.com> | 2018-05-07 13:49:26 -0500 |
commit | d76c544d500e2ba14e5541192529cb898fd5835d (patch) | |
tree | b707df298448964357012f3694fc5ceb1546959b | |
parent | b61a6aeef7baccd24f260f13b6618f14a8bd37ae (diff) |
Add counters to correctly track the number of runs, successes and failures.
-rw-r--r-- | lib/oxidized/node/stats.rb | 7 | ||||
-rw-r--r-- | spec/node_spec.rb | 22 | ||||
-rw-r--r-- | spec/spec_helper.rb | 9 |
3 files changed, 38 insertions, 0 deletions
diff --git a/lib/oxidized/node/stats.rb b/lib/oxidized/node/stats.rb index 2c04a60..17b9a13 100644 --- a/lib/oxidized/node/stats.rb +++ b/lib/oxidized/node/stats.rb @@ -14,6 +14,11 @@ module Oxidized @stats[job.status] ||= [] @stats[job.status].shift if @stats[job.status].size > MAX_STAT @stats[job.status].push stat + if job.status.equal? :success + @stats[:success_count] += 1 + else + @stats[:failure_count] += 1 + end end # @param [Symbol] status stats for specific status @@ -26,6 +31,8 @@ module Oxidized def initialize @stats = {} + @stats[:success_count] = 0 + @stats[:failure_count] = 0 end end end diff --git a/spec/node_spec.rb b/spec/node_spec.rb index f769751..ba5b515 100644 --- a/spec/node_spec.rb +++ b/spec/node_spec.rb @@ -41,6 +41,28 @@ describe Oxidized::Node do status, = @node.run status.must_equal :success end + it 'should record the success' do + stub_oxidized_ssh + + before_successes = @node.stats.get(:success_count) + j = Oxidized::Job.new @node + j.join + @node.stats.add j + after_successes = @node.stats.get(:success_count) + successes = after_successes - before_successes + successes.must_equal 1 + end + it 'should record a failure' do + stub_oxidized_ssh_fail + + before_fails = @node.stats.get(:failure_count) + j = Oxidized::Job.new @node + j.join + @node.stats.add j + after_fails = @node.stats.get(:failure_count) + fails = after_fails - before_fails + fails.must_equal 1 + end end describe '#repo' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fc5167f..00f46e5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -20,3 +20,12 @@ def stub_oxidized_ssh Oxidized::SSH.any_instance.stubs(:disconnect).returns(true) Oxidized::SSH.any_instance.stubs(:disconnect_cli).returns(true) end + +def stub_oxidized_ssh_fail + Oxidized::SSH.any_instance.stubs(:connect).returns(false) + Oxidized::SSH.any_instance.stubs(:node).returns(@node) + Oxidized::SSH.any_instance.expects(:cmd).never + Oxidized::SSH.any_instance.stubs(:connect_cli).returns(false) + Oxidized::SSH.any_instance.stubs(:disconnect).returns(false) + Oxidized::SSH.any_instance.stubs(:disconnect_cli).returns(false) +end |