Sha256: 768ce7ba85896439b19e70736644fc82cd28f3e4d054f309f5c3a01e9ecf36ec

Contents?: true

Size: 1.92 KB

Versions: 6

Compression:

Stored size: 1.92 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

require 'newrelic_rpm'
require 'multiverse_helpers'

class HarvestTimestampsTest < Minitest::Test
  include MultiverseHelpers

  setup_and_teardown_agent

  def test_resets_metric_data_timestamps_after_forking
    t0 = freeze_time

    t1 = advance_time 10
    NewRelic::Agent.after_fork

    t2 = advance_time 10
    trigger_metric_data_post

    metric_data_post = $collector.calls_for('metric_data').first
    start_ts, end_ts = metric_data_post[1..2]

    assert_equal(t1.to_f, start_ts)
    assert_equal(t2.to_f, end_ts)
  end

  def test_start_timestamp_maintained_on_harvest_failure
    t0 = freeze_time.to_f

    NewRelic::Agent.after_fork

    $collector.stub('metric_data', {}, 503)
    t1 = advance_time(10).to_f
    trigger_metric_data_post
    first_post = last_metric_data_post

    $collector.reset
    t2 = advance_time(10).to_f
    trigger_metric_data_post
    second_post = last_metric_data_post

    assert_equal([t0, t1], first_post[1..2])
    assert_equal([t0, t2], second_post[1..2])
  end

  def test_timestamps_updated_even_if_filling_metric_id_cache_fails
    t0 = freeze_time.to_f

    NewRelic::Agent.after_fork

    # Induce a failure in filling the metric ID cache by handing back a bogus
    # response to the first metric_data post.
    $collector.stub('metric_data', [[[[]]]], 200)
    t1 = advance_time(10).to_f
    trigger_metric_data_post
    first_post = last_metric_data_post

    $collector.reset
    t2 = advance_time(10).to_f
    trigger_metric_data_post
    second_post = last_metric_data_post

    assert_equal([t0, t1], first_post[1..2])
    assert_equal([t1, t2], second_post[1..2])
  end

  def trigger_metric_data_post
    NewRelic::Agent.agent.send(:transmit_data)
  end

  def last_metric_data_post
    $collector.calls_for('metric_data').last
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
newrelic_rpm-3.9.1.236 test/multiverse/suites/agent_only/harvest_timestamps_test.rb
newrelic_rpm-3.9.0.229 test/multiverse/suites/agent_only/harvest_timestamps_test.rb
newrelic_rpm-3.8.1.221 test/multiverse/suites/agent_only/harvest_timestamps_test.rb
newrelic_rpm-3.8.0.218 test/multiverse/suites/agent_only/harvest_timestamps_test.rb
newrelic_rpm-3.7.3.204 test/multiverse/suites/agent_only/harvest_timestamps_test.rb
newrelic_rpm-3.7.3.199 test/multiverse/suites/agent_only/harvest_timestamps_test.rb