# 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. class KeyTransactionsTest < Test::Unit::TestCase class TestWidget include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation def key_txn sleep 0.05 end add_transaction_tracer :key_txn def other_txn sleep 0.05 end add_transaction_tracer :other_txn end def setup $collector ||= NewRelic::FakeCollector.new $collector.reset key_apdex_config = { 'Controller/KeyTransactionsTest::TestWidget/key_txn' => 0.01 } $collector.mock['connect'] = [200, {'return_value' => { "agent_run_id" => 666, 'web_transactions_apdex' => key_apdex_config, 'apdex_t' => 0.1 }}] $collector.run NewRelic::Agent.manual_start(:sync_startup => true, :force_reconnect => true) end def teardown NewRelic::Agent.shutdown end SATISFYING = 0 TOLERATING = 1 FAILING = 2 def test_applied_correct_apdex_t_to_key_txn TestWidget.new.key_txn NewRelic::Agent.instance.send(:harvest_and_send_timeslice_data) stats = $collector.reported_stats_for_metric('Apdex')[0] assert_equal 1.0, stats[FAILING] end def test_applied_correct_apdex_t_to_regular_txn TestWidget.new.other_txn NewRelic::Agent.instance.send(:harvest_and_send_timeslice_data) stats = $collector.reported_stats_for_metric('Apdex')[0] assert_equal 1.0, stats[SATISFYING] end def test_applied_correct_tt_theshold TestWidget.new.key_txn TestWidget.new.other_txn NewRelic::Agent.instance.send(:harvest_and_send_slowest_sample) traces = $collector.calls_for('transaction_sample_data') assert_equal 1, traces.size assert_equal('Controller/KeyTransactionsTest::TestWidget/key_txn', traces[0].metric_name) end end