Sha256: f79427135a0d9993dd6d101f68868acbe47fea5e89a9106cfc91c8358d0f9abe

Contents?: true

Size: 1.59 KB

Versions: 13

Compression:

Stored size: 1.59 KB

Contents

require_relative '../test_helper'

class MetricTest < Minitest::Test
  def setup
    @metric = Scout::Realtime::MetricExample.new
    @collector_stub = stub(:run => { :metric => :value })
    @metric.instance_variable_set(:@collector, @collector_stub)
    @metric.stubs(:update_historical_metrics) # do nothing unless specifically being tested
  end

  def test_saves_latest_run
    @metric.run!
    assert_equal({ :metric => :value }, @metric.latest_run)
  end

  def test_metadata
    assert_equal({ 'units' => '%', 'precision' => 1, 'label' => 'tester' }, Scout::Realtime::MetricExample.metadata[:test_field])
  end

  def test_metadata_creates_missing_labels
    assert_equal 'Empty field', Scout::Realtime::MetricExample.metadata[:empty_field]['label']
  end

  def test_metadata_defaults_units_to_blank_string
    assert_equal '', Scout::Realtime::MetricExample.metadata[:empty_field]['units']
  end

  def test_metadata_defaults_precision_to_one
    assert_equal 1, Scout::Realtime::MetricExample.metadata[:empty_field]['precision']
  end

  def test_rescues_noent_exceptions
    # these errors bubble up from Sys::ProcTable occasionally. Timing issues? Could be investigated further.
    @collector_stub.stubs(:run).raises(Errno::ENOENT)
    @metric.run!
    assert_equal({}, @metric.latest_run)
  end

  def test_determines_short_name
    assert_equal 'metricexample', Scout::Realtime::MetricExample.short_name
  end
end

class Scout::Realtime::MetricExample < Scout::Realtime::Metric
  FIELDS = { :test_field => { 'units' => '%', 'precision' => 1, 'label' => 'tester' },
             :empty_field => {}
           }
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
scout_realtime-1.0.5 test/lib/metric_test.rb
scout_realtime-1.0.4 test/lib/metric_test.rb
scout_realtime-1.0.3 test/lib/metric_test.rb
scout_realtime-1.0.3.pre test/lib/metric_test.rb
scout_realtime-1.0.2 test/lib/metric_test.rb
scout_realtime-1.0.1 test/lib/metric_test.rb
scout_realtime-1.0.0 test/lib/metric_test.rb
scout_realtime-0.5.5 test/lib/metric_test.rb
scout_realtime-0.5.5.pre test/lib/metric_test.rb
scout_realtime-0.5.4 test/lib/metric_test.rb
scout_realtime-0.5.3 test/lib/metric_test.rb
scout_realtime-0.5.2 test/lib/metric_test.rb
scout_realtime-0.5.1 test/lib/metric_test.rb