Sha256: fef1de6a27ed9d31cf51d25838bd02988fb758bd0c8d4cc9862b0c9b4471306e

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 KB

Contents

require 'spec_helper'
require 'observed/observer_helpers/timer'
require 'observed/observer'

describe Observed::ObserverHelpers::Timer do

  include Observed::SpecHelpers

  before {
    class ExampleTimerPlugin < Observed::Observer
      include Observed::ObserverHelpers::Timer

      attribute :timeout_in_milliseconds
      attribute :time_to_sleep

      def observe
        time_and_report(timeout_in_seconds: self.timeout_in_milliseconds / 1000.0) do
          sleep(time_to_sleep)
          time_to_sleep
        end
      end

      def self.plugin_name
        'timer'
      end
    end
  }

  subject {
    input = ExampleTimerPlugin.new
    input.configure system: system, tag: 'foo.timed', time_to_sleep: 0.001, timeout_in_milliseconds: 1000
    input
  }

  let(:system) {
    m = mock('system')
    m.stubs(:now).returns(1.0)
      .then.returns(2.0)
      .then.returns(3.0)
      .then.returns(5.0)
      .then.returns(6.0)
      .then.returns(9.0)
    m
  }

  it 'should report results with elapsed times' do
    system.expects(:report).with('foo.timed.success', status: :success, elapsed_time: 1.0, result: 0.001)
    system.expects(:report).with('foo.timed.success', status: :success, elapsed_time: 2.0, result: 0.001)
    system.expects(:report).with('foo.timed.success', status: :success, elapsed_time: 3.0, result: 0.001)
    subject.observe
    subject.observe
    subject.observe
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
observed-0.2.0 spec/input_helpers/timer_spec.rb
observed-0.2.0.rc2 spec/input_helpers/timer_spec.rb
observed-0.2.0.rc1 spec/input_helpers/timer_spec.rb
observed-0.1.1 spec/input_helpers/timer_spec.rb