newrelic_rpm 2.13.5.beta4 → 2.13.6.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of newrelic_rpm might be problematic. Click here for more details.

Files changed (60) hide show
  1. data/CHANGELOG +8 -0
  2. data/cert/cacert.pem +21 -0
  3. data/lib/conditional_vendored_dependency_detection.rb +3 -0
  4. data/lib/new_relic/agent/agent.rb +14 -1
  5. data/lib/new_relic/agent/instrumentation/active_merchant.rb +15 -12
  6. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +38 -21
  7. data/lib/new_relic/agent/instrumentation/authlogic.rb +9 -4
  8. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +364 -364
  9. data/lib/new_relic/agent/instrumentation/data_mapper.rb +142 -121
  10. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +17 -16
  11. data/lib/new_relic/agent/instrumentation/memcache.rb +40 -26
  12. data/lib/new_relic/agent/instrumentation/net.rb +19 -13
  13. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +27 -15
  14. data/lib/new_relic/agent/instrumentation/rails/active_record_instrumentation.rb +80 -71
  15. data/lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb +84 -72
  16. data/lib/new_relic/agent/instrumentation/sequel.rb +84 -70
  17. data/lib/new_relic/agent/instrumentation/sinatra.rb +44 -37
  18. data/lib/new_relic/agent/instrumentation/sunspot.rb +18 -12
  19. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +13 -7
  20. data/lib/new_relic/agent/method_tracer.rb +1 -1
  21. data/lib/new_relic/agent/samplers/cpu_sampler.rb +2 -0
  22. data/lib/new_relic/agent/stats_engine/metric_stats.rb +1 -1
  23. data/lib/new_relic/control.rb +1 -0
  24. data/lib/new_relic/control/instrumentation.rb +1 -0
  25. data/lib/new_relic/delayed_job_injection.rb +23 -14
  26. data/lib/new_relic/version.rb +2 -2
  27. data/lib/newrelic_rpm.rb +5 -0
  28. data/newrelic_rpm.gemspec +25 -23
  29. data/test/new_relic/agent/{agent_connect_test.rb → agent/connect_test.rb} +2 -2
  30. data/test/new_relic/agent/{agent_start_test.rb → agent/start_test.rb} +17 -3
  31. data/test/new_relic/agent/{agent_start_worker_thread_test.rb → agent/start_worker_thread_test.rb} +2 -2
  32. data/test/new_relic/agent/{agent_controller_test.rb → agent_test_controller_test.rb} +6 -3
  33. data/test/new_relic/agent/{error_collector_notice_error_test.rb → error_collector/notice_error_test.rb} +2 -2
  34. data/test/new_relic/agent/{active_record_instrumentation_test.rb → instrumentation/active_record_instrumentation_test.rb} +2 -2
  35. data/test/new_relic/agent/{metric_frame_test.rb → instrumentation/metric_frame_test.rb} +2 -3
  36. data/test/new_relic/agent/{net_instrumentation_test.rb → instrumentation/net_instrumentation_test.rb} +4 -4
  37. data/test/new_relic/agent/{queue_time_test.rb → instrumentation/queue_time_test.rb} +1 -1
  38. data/test/new_relic/agent/{task_instrumentation_test.rb → instrumentation/task_instrumentation_test.rb} +29 -32
  39. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +165 -0
  40. data/test/new_relic/agent/{method_tracer_trace_execution_scoped_test.rb → method_tracer/instance_methods/trace_execution_scoped_test.rb} +2 -2
  41. data/test/new_relic/agent/method_tracer_test.rb +31 -3
  42. data/test/new_relic/agent/rpm_agent_test.rb +8 -3
  43. data/test/new_relic/{agent/collection_helper_test.rb → collection_helper_test.rb} +4 -4
  44. data/test/new_relic/{deployments_api_test.rb → command/deployments_test.rb} +3 -5
  45. data/test/new_relic/control_test.rb +3 -3
  46. data/test/new_relic/{environment_test.rb → local_environment_test.rb} +2 -5
  47. data/test/new_relic/metric_spec_test.rb +32 -122
  48. data/test/new_relic/stats_test.rb +0 -1
  49. data/test/new_relic/{agent/transaction_sample_subtest_test.rb → transaction_sample_subtest_test.rb} +0 -0
  50. data/test/new_relic/{agent/transaction_sample_test.rb → transaction_sample_test.rb} +1 -2
  51. data/test/test_helper.rb +1 -0
  52. data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +19 -0
  53. data/vendor/gems/dependency_detection-0.0.1.build/README +0 -0
  54. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +57 -0
  55. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection/version.rb +3 -0
  56. metadata +29 -27
  57. data/test/new_relic/agent/add_method_tracer_test.rb +0 -158
  58. data/test/new_relic/agent/metric_data_test.rb +0 -53
  59. data/test/new_relic/agent/testable_agent.rb +0 -13
  60. data/test/new_relic/shim_agent_test.rb +0 -9
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
2
  require 'action_controller/test_case'
3
- class AgentControllerTest < ActionController::TestCase
3
+ class NewRelic::Agent::AgentTestControllerTest < ActionController::TestCase
4
4
  require 'action_controller/base'
5
5
  require 'new_relic/agent/agent_test_controller'
6
6
 
@@ -43,12 +43,13 @@ class AgentControllerTest < ActionController::TestCase
43
43
 
44
44
  def teardown
45
45
  Thread.current[:newrelic_ignore_controller] = nil
46
- super
47
46
  NewRelic::Agent.shutdown
48
47
  NewRelic::Agent::AgentTestController.clear_headers
48
+ super
49
49
  end
50
50
 
51
51
  def test_mongrel_queue
52
+ NewRelic::Agent::AgentTestController.clear_headers
52
53
  engine.clear_stats
53
54
  NewRelic::Control.instance.local_env.stubs(:mongrel).returns( stub('mongrel', :workers => stub('workers', :list => stub('list', :length => '10'))))
54
55
 
@@ -70,6 +71,7 @@ class AgentControllerTest < ActionController::TestCase
70
71
  end
71
72
 
72
73
  def test_new_queue_integration
74
+ NewRelic::Agent::AgentTestController.clear_headers
73
75
  engine.clear_stats
74
76
  start = ((Time.now - 1).to_f * 1_000_000).to_i
75
77
  NewRelic::Agent::AgentTestController.set_some_headers 'HTTP_X_QUEUE_START'=> "t=#{start}"
@@ -89,6 +91,7 @@ class AgentControllerTest < ActionController::TestCase
89
91
  end
90
92
 
91
93
  def test_new_server_time_integration
94
+ NewRelic::Agent::AgentTestController.clear_headers
92
95
  engine.clear_stats
93
96
  start = ((Time.now - 1).to_f * 1_000_000).to_i
94
97
  NewRelic::Agent::AgentTestController.set_some_headers 'HTTP_X_REQUEST_START'=> "t=#{start}"
@@ -298,7 +301,7 @@ class AgentControllerTest < ActionController::TestCase
298
301
  end
299
302
 
300
303
  def test_queue_headers_apache
301
-
304
+ NewRelic::Agent::AgentTestController.clear_headers
302
305
  engine.clear_stats
303
306
  queue_length_stat = stats('Mongrel/Queue Length')
304
307
  queue_time_stat = stats('WebFrontend/QueueTime')
@@ -1,5 +1,5 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
- class NewRelic::Agent::ErrorCollectorNoticeErrorTest < Test::Unit::TestCase
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
2
+ class NewRelic::Agent::ErrorCollector::NoticeErrorTest < Test::Unit::TestCase
3
3
  require 'new_relic/agent/error_collector'
4
4
  include NewRelic::Agent::ErrorCollector::NoticeError
5
5
 
@@ -1,5 +1,5 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
- class ActiveRecordInstrumentationTest < Test::Unit::TestCase
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
2
+ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::Unit::TestCase
3
3
  require 'active_record_fixtures'
4
4
  include NewRelic::Agent::Instrumentation::ControllerInstrumentation
5
5
  def setup
@@ -1,7 +1,6 @@
1
- require 'test/unit'
2
- require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
3
2
 
4
- class NewRelic::Agent::MetricFrameTest < Test::Unit::TestCase
3
+ class NewRelic::Agent::Instrumentation::MetricFrameTest < Test::Unit::TestCase
5
4
 
6
5
  attr_reader :f
7
6
  def setup
@@ -1,6 +1,6 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
2
2
 
3
- class NewRelic::Agent::NetInstrumentationTest < Test::Unit::TestCase
3
+ class NewRelic::Agent::Instrumentation::NetInstrumentationTest < Test::Unit::TestCase
4
4
  include NewRelic::Agent::Instrumentation::ControllerInstrumentation
5
5
  def setup
6
6
  NewRelic::Agent.manual_start
@@ -33,7 +33,7 @@ class NewRelic::Agent::NetInstrumentationTest < Test::Unit::TestCase
33
33
  assert_match /<head>/, res.body
34
34
  end
35
35
  assert_equal %w[External/www.google.com/Net::HTTP/GET External/allOther External/www.google.com/all
36
- External/www.google.com/Net::HTTP/GET:OtherTransaction/Background/NewRelic::Agent::NetInstrumentationTest/task].sort, metrics_without_gc.select{|m| m =~ /^External/}.sort
36
+ External/www.google.com/Net::HTTP/GET:OtherTransaction/Background/NewRelic::Agent::Instrumentation::NetInstrumentationTest/task].sort, metrics_without_gc.select{|m| m =~ /^External/}.sort
37
37
  end
38
38
 
39
39
  def test_transactional
@@ -45,7 +45,7 @@ class NewRelic::Agent::NetInstrumentationTest < Test::Unit::TestCase
45
45
  assert_match /<head>/, res.body
46
46
  end
47
47
  assert_equal %w[External/www.google.com/Net::HTTP/GET External/allWeb External/www.google.com/all
48
- External/www.google.com/Net::HTTP/GET:Controller/NewRelic::Agent::NetInstrumentationTest/task].sort, metrics_without_gc.select{|m| m =~ /^External/}.sort
48
+ External/www.google.com/Net::HTTP/GET:Controller/NewRelic::Agent::Instrumentation::NetInstrumentationTest/task].sort, metrics_without_gc.select{|m| m =~ /^External/}.sort
49
49
  end
50
50
  def test_get__simple
51
51
  Net::HTTP.get URI.parse('http://www.google.com/index.html')
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper'))
2
2
  class NewRelic::Agent::Instrumentation::QueueTimeTest < Test::Unit::TestCase
3
3
  require 'new_relic/agent/instrumentation/queue_time'
4
4
  include NewRelic::Agent::Instrumentation::QueueTime
@@ -1,9 +1,6 @@
1
- # Run faster standalone
2
- ENV['SKIP_RAILS'] = 'true'
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper'))
3
2
 
4
- require File.expand_path('../../../test_helper', __FILE__)
5
-
6
- class TaskInstrumentationTest < Test::Unit::TestCase
3
+ class NewRelic::Agent::Instrumentation::TaskInstrumentationTest < Test::Unit::TestCase
7
4
  include NewRelic::Agent::Instrumentation::ControllerInstrumentation
8
5
  extend TestContexts
9
6
  attr_accessor :agent
@@ -12,33 +9,33 @@ class TaskInstrumentationTest < Test::Unit::TestCase
12
9
 
13
10
  should "run" do
14
11
  run_task_inner 0
15
- stat_names = %w[Controller/TaskInstrumentationTest/inner_task_0
12
+ stat_names = %w[Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0
16
13
  HttpDispatcher
17
- Apdex Apdex/TaskInstrumentationTest/inner_task_0].sort
14
+ Apdex Apdex/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0].sort
18
15
  expected_but_missing = stat_names - @agent.stats_engine.metrics
19
16
  assert_equal 0, expected_but_missing.size, @agent.stats_engine.metrics.map { |n|
20
17
  stat = @agent.stats_engine.get_stats_no_scope(n)
21
18
  "#{'%-26s' % n}: #{stat.call_count} calls @ #{stat.average_call_time} sec/call"
22
19
  }.join("\n ") + "\nmissing: #{expected_but_missing.inspect}"
23
20
  assert_equal 0, @agent.stats_engine.get_stats_no_scope('Controller').call_count
24
- assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/inner_task_0').call_count
21
+ assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0').call_count
25
22
  end
26
23
 
27
24
  should "run_recursive" do
28
25
  run_task_inner(3)
29
26
  assert_equal 1, @agent.stats_engine.lookup_stats(
30
- 'Controller/TaskInstrumentationTest/inner_task_0',
31
- 'Controller/TaskInstrumentationTest/inner_task_1').call_count
27
+ 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0',
28
+ 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_1').call_count
32
29
  assert_equal 1, @agent.stats_engine.lookup_stats(
33
- 'Controller/TaskInstrumentationTest/inner_task_1',
34
- 'Controller/TaskInstrumentationTest/inner_task_2').call_count
30
+ 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_1',
31
+ 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_2').call_count
35
32
  assert_equal 1, @agent.stats_engine.lookup_stats(
36
- 'Controller/TaskInstrumentationTest/inner_task_2',
37
- 'Controller/TaskInstrumentationTest/inner_task_3').call_count
38
- assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/inner_task_0').call_count
39
- assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/inner_task_1').call_count
40
- assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/inner_task_2').call_count
41
- assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/inner_task_3').call_count
33
+ 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_2',
34
+ 'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_3').call_count
35
+ assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0').call_count
36
+ assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_1').call_count
37
+ assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_2').call_count
38
+ assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_3').call_count
42
39
  assert_equal 0, @agent.stats_engine.get_stats_no_scope('Controller').call_count
43
40
  end
44
41
 
@@ -48,19 +45,19 @@ class TaskInstrumentationTest < Test::Unit::TestCase
48
45
  stat = @agent.stats_engine.get_stats_no_scope(n)
49
46
  # puts "#{'%-26s' % n}: #{stat.call_count} calls @ #{stat.average_call_time} sec/call"
50
47
  end
51
- assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/outer_task').call_count
52
- assert_equal 2, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/inner_task_0').call_count
48
+ assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/outer_task').call_count
49
+ assert_equal 2, @agent.stats_engine.get_stats_no_scope('Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0').call_count
53
50
  end
54
51
 
55
52
  should "reentrancy" do
56
53
  assert_equal 0, NewRelic::Agent::BusyCalculator.busy_count
57
54
  run_task_inner(1)
58
- assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/inner_task_0').call_count
59
- assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/inner_task_1').call_count
55
+ assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0').call_count
56
+ assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_1').call_count
60
57
  compare_metrics %w[
61
- Controller/TaskInstrumentationTest/inner_task_0:Controller/TaskInstrumentationTest/inner_task_1
62
- Controller/TaskInstrumentationTest/inner_task_0
63
- Controller/TaskInstrumentationTest/inner_task_1
58
+ Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0:Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_1
59
+ Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0
60
+ Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_1
64
61
  ], @agent.stats_engine.metrics.grep(/^Controller/)
65
62
  end
66
63
 
@@ -74,9 +71,9 @@ class TaskInstrumentationTest < Test::Unit::TestCase
74
71
  stat = @agent.stats_engine.get_stats_no_scope(n)
75
72
  # puts "#{'%-26s' % n}: #{stat.call_count} calls @ #{stat.average_call_time} sec/call"
76
73
  end
77
- assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/outer_task').call_count
74
+ assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/outer_task').call_count
78
75
  assert_equal 0, @agent.stats_engine.get_stats_no_scope('Controller').call_count
79
- assert_equal 2, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/inner_task_0').call_count
76
+ assert_equal 2, @agent.stats_engine.get_stats_no_scope('Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0').call_count
80
77
  assert_equal 0, @agent.transaction_sampler.scope_depth, "existing unfinished sample"
81
78
  sample = @agent.transaction_sampler.last_sample
82
79
  assert_not_nil sample
@@ -92,7 +89,7 @@ class TaskInstrumentationTest < Test::Unit::TestCase
92
89
  NewRelic::Agent.abort_transaction!
93
90
  end
94
91
  # We record the controller metric still, but abort any transaction recording.
95
- assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/hello').call_count
92
+ assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/hello').call_count
96
93
  assert_nil @agent.transaction_sampler.last_sample
97
94
  end
98
95
  should "block" do
@@ -106,7 +103,7 @@ class TaskInstrumentationTest < Test::Unit::TestCase
106
103
  #puts "#{'%-26s' % n}: #{stat.call_count} calls @ #{stat.average_call_time} sec/call"
107
104
  end
108
105
  assert_equal @agent, NewRelic::Agent.instance
109
- assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/hello').call_count
106
+ assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/hello').call_count
110
107
  sample = @agent.transaction_sampler.last_sample
111
108
  assert_not_nil sample
112
109
  assert_equal 'Redrocks', sample.params[:request_params][:account]
@@ -134,14 +131,14 @@ class TaskInstrumentationTest < Test::Unit::TestCase
134
131
  errors = @agent.error_collector.harvest_errors([])
135
132
  assert_equal 1, errors.size
136
133
  error = errors.first
137
- assert_equal "Controller/TaskInstrumentationTest/run_task_exception", error.path
134
+ assert_equal "Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/run_task_exception", error.path
138
135
  assert_not_nil error.params[:stack_trace]
139
136
  assert_not_nil error.params[:custom_params]
140
137
  end
141
138
 
142
139
  should "instrument_bg" do
143
140
  run_background_job
144
- stat_names = %w[OtherTransaction/Background/TaskInstrumentationTest/run_background_job
141
+ stat_names = %w[OtherTransaction/Background/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/run_background_job
145
142
  OtherTransaction/Background/all
146
143
  OtherTransaction/all].sort
147
144
 
@@ -185,4 +182,4 @@ class TaskInstrumentationTest < Test::Unit::TestCase
185
182
  add_transaction_tracer :run_task_outer, :name => 'outer_task', :params => '{ :level => args[0] }'
186
183
  # Eventually we need th change this to :category => :task
187
184
  add_transaction_tracer :run_background_job, :category => 'OtherTransaction/Background'
188
- end
185
+ end
@@ -0,0 +1,165 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','..','test_helper'))
2
+
3
+ require 'set'
4
+ module NewRelic
5
+ module Agent
6
+ class Agent
7
+ module MethodTracer
8
+ module ClassMethods
9
+ class AddMethodTracerTest < Test::Unit::TestCase
10
+ # require 'new_relic/agent/method_tracer'
11
+ include NewRelic::Agent::MethodTracer::ClassMethods::AddMethodTracer
12
+
13
+ def test_validate_options_nonhash
14
+ assert_raise(TypeError) do
15
+ validate_options([])
16
+ end
17
+ end
18
+
19
+ def test_validate_options_defaults
20
+ self.expects(:check_for_illegal_keys!)
21
+ self.expects(:set_deduct_call_time_based_on_metric).with(DEFAULT_SETTINGS)
22
+ self.expects(:check_for_push_scope_and_metric)
23
+ validate_options({})
24
+ end
25
+
26
+ def test_validate_options_override
27
+ opts = {:push_scope => false, :metric => false, :force => true}
28
+ self.expects(:check_for_illegal_keys!)
29
+ self.expects(:check_for_push_scope_and_metric)
30
+ val = validate_options(opts)
31
+ assert val.is_a?(Hash)
32
+ assert (val[:push_scope] == false), val.inspect
33
+ assert (val[:metric] == false), val.inspect
34
+ assert (val[:force] == true), val.inspect
35
+ end
36
+
37
+ def test_default_metric_name_code
38
+ self.expects(:name).returns("TEST_CLASS")
39
+ assert_equal 'Custom/TEST_CLASS/test_method', default_metric_name_code('test_method')
40
+ end
41
+
42
+ def test_method_exists_positive
43
+ self.expects(:method_defined?).returns(true)
44
+ assert method_exists?('test_method')
45
+ end
46
+
47
+ def test_method_exists_negative
48
+ self.expects(:method_defined?).returns(false)
49
+ self.expects(:private_method_defined?).returns(false)
50
+ self.expects(:name).returns('TEST_CLASS')
51
+ fake_log = mock('log')
52
+ self.expects(:log).returns(fake_log)
53
+ fake_log.expects(:warn).with("Did not trace TEST_CLASS#test_method because that method does not exist")
54
+ assert !method_exists?('test_method')
55
+ end
56
+
57
+ def test_set_deduct_call_time_based_on_metric_positive
58
+ opts = {:metric => true}
59
+ val = set_deduct_call_time_based_on_metric(opts)
60
+ assert val.is_a?(Hash)
61
+ assert val[:deduct_call_time_from_parent]
62
+ end
63
+
64
+ def test_set_deduct_call_time_based_on_metric_negative
65
+ opts = {:metric => false}
66
+ val = set_deduct_call_time_based_on_metric(opts)
67
+ assert val.is_a?(Hash)
68
+ assert !val[:deduct_call_time_from_parent]
69
+ end
70
+
71
+ def test_set_deduct_call_time_based_on_metric_non_nil
72
+ opts = {:deduct_call_time_from_parent => true, :metric => false}
73
+ val = set_deduct_call_time_based_on_metric(opts)
74
+ assert val.is_a?(Hash)
75
+ assert val[:deduct_call_time_from_parent]
76
+ end
77
+
78
+ def test_set_deduct_call_time_based_on_metric_opposite
79
+ opts = {:deduct_call_time_from_parent => false, :metric => true}
80
+ val = set_deduct_call_time_based_on_metric(opts)
81
+ assert val.is_a?(Hash)
82
+ assert !val[:deduct_call_time_from_parent]
83
+ end
84
+
85
+ def test_unrecognized_keys_positive
86
+ assert_equal [:unrecognized, :keys].to_set, unrecognized_keys([:hello, :world], {:unrecognized => nil, :keys => nil}).to_set
87
+ end
88
+
89
+ def test_unrecognized_keys_negative
90
+ assert_equal [], unrecognized_keys([:hello, :world], {:hello => nil, :world => nil})
91
+ end
92
+
93
+ def test_any_unrecognized_keys_positive
94
+ assert any_unrecognized_keys?([:one], {:one => nil, :two => nil})
95
+ end
96
+
97
+ def test_any_unrecognized_keys_negative
98
+ assert !any_unrecognized_keys?([:one], {:one => nil})
99
+ end
100
+
101
+ def test_check_for_illegal_keys_positive
102
+ assert_raise(RuntimeError) do
103
+ check_for_illegal_keys!({:unknown_key => nil})
104
+ end
105
+ end
106
+
107
+ def test_check_for_illegal_keys_negative
108
+ test_keys = Hash[ALLOWED_KEYS.map {|x| [x, nil]}]
109
+ check_for_illegal_keys!(test_keys)
110
+ end
111
+
112
+ def test_traced_method_exists_positive
113
+ self.expects(:_traced_method_name)
114
+ self.expects(:method_defined?).returns(true)
115
+ fake_log = mock('log')
116
+ self.expects(:log).returns(fake_log)
117
+ fake_log.expects(:warn).with('Attempt to trace a method twice with the same metric: Method = test_method, Metric Name = Custom/Test/test_method')
118
+ assert traced_method_exists?('test_method', 'Custom/Test/test_method')
119
+ end
120
+
121
+ def test_traced_method_exists_negative
122
+ self.expects(:_traced_method_name)
123
+ self.expects(:method_defined?).returns(false)
124
+ assert !traced_method_exists?(nil, nil)
125
+ end
126
+
127
+ def test_assemble_code_header_forced
128
+ opts = {:force => true, :code_header => 'CODE HEADER'}
129
+ assert_equal "CODE HEADER", assemble_code_header('test_method', 'Custom/Test/test_method', opts)
130
+ end
131
+
132
+ def test_assemble_code_header_unforced
133
+ self.expects(:_untraced_method_name).returns("method_name_without_tracing")
134
+ opts = {:force => false, :code_header => 'CODE HEADER'}
135
+ assert_equal "return method_name_without_tracing(*args, &block) unless NewRelic::Agent.is_execution_traced?\nCODE HEADER", assemble_code_header('test_method', 'Custom/Test/test_method', opts)
136
+ end
137
+
138
+ def test_check_for_push_scope_and_metric_positive
139
+ check_for_push_scope_and_metric({:push_scope => true})
140
+ check_for_push_scope_and_metric({:metric => true})
141
+ end
142
+
143
+ def test_check_for_push_scope_and_metric_negative
144
+ assert_raise(RuntimeError) do
145
+ check_for_push_scope_and_metric({:push_scope => false, :metric => false})
146
+ end
147
+ end
148
+
149
+ def test_code_to_eval_scoped
150
+ self.expects(:validate_options).returns({:push_scope => true})
151
+ self.expects(:method_with_push_scope).with('test_method', 'Custom/Test/test_method', {:push_scope => true})
152
+ code_to_eval('test_method', 'Custom/Test/test_method', {})
153
+ end
154
+
155
+ def test_code_to_eval_unscoped
156
+ self.expects(:validate_options).returns({:push_scope => false})
157
+ self.expects(:method_without_push_scope).with('test', 'Custom/Test/test', {:push_scope => false})
158
+ code_to_eval('test', 'Custom/Test/test', {})
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end
164
+ end
165
+ end
@@ -1,5 +1,5 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
- class NewRelic::Agent::MethodTracer::TraceExecutionScopedTest < Test::Unit::TestCase
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','..','test_helper'))
2
+ class NewRelic::Agent::MethodTracer::InstanceMethods::TraceExecutionScopedTest < Test::Unit::TestCase
3
3
  require 'new_relic/agent/method_tracer'
4
4
  include NewRelic::Agent::MethodTracer::InstanceMethods::TraceExecutionScoped
5
5
 
@@ -45,19 +45,24 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
45
45
  attr_reader :stats_engine
46
46
 
47
47
  def setup
48
- super
49
48
  NewRelic::Agent.manual_start
50
49
  @stats_engine = NewRelic::Agent.instance.stats_engine
51
50
  @stats_engine.clear_stats
52
51
  @scope_listener = NewRelic::Agent::MockScopeListener.new
53
52
  @old_sampler = NewRelic::Agent.instance.transaction_sampler
54
53
  @stats_engine.transaction_sampler = @scope_listener
54
+ super
55
55
  end
56
56
 
57
57
  def teardown
58
58
  @stats_engine.transaction_sampler = @old_sampler
59
59
  @stats_engine.clear_stats
60
- self.class.remove_method_tracer :method_to_be_traced, @metric_name if @metric_name
60
+ begin
61
+ self.class.remove_method_tracer :method_to_be_traced, @metric_name if @metric_name
62
+ rescue RuntimeError
63
+ # ignore 'no tracer' errors from remove method tracer
64
+ end
65
+
61
66
  @metric_name = nil
62
67
  super
63
68
  end
@@ -98,6 +103,13 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
98
103
  t1 = Time.now
99
104
  method_to_be_traced 1,2,3,true,METRIC
100
105
  elapsed = Time.now - t1
106
+
107
+ begin
108
+ self.class.remove_method_tracer :method_to_be_traced, METRIC
109
+ rescue RuntimeError
110
+ # ignore 'no tracer' errors from remove method tracer
111
+ end
112
+
101
113
 
102
114
  stats = @stats_engine.get_stats(METRIC)
103
115
  check_time stats.total_call_time, elapsed
@@ -122,13 +134,17 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
122
134
 
123
135
  stats = @stats_engine.get_stats("Custom/#{self.class.name}/simple_method")
124
136
  assert stats.call_count == 1
125
-
126
137
  end
127
138
 
128
139
  def test_method_traced?
129
140
  assert !self.class.method_traced?(:method_to_be_traced, METRIC)
130
141
  self.class.add_method_tracer :method_to_be_traced, METRIC
131
142
  assert self.class.method_traced?(:method_to_be_traced, METRIC)
143
+ begin
144
+ self.class.remove_method_tracer :method_to_be_traced, METRIC
145
+ rescue RuntimeError
146
+ # ignore 'no tracer' errors from remove method tracer
147
+ end
132
148
  end
133
149
 
134
150
  def test_tt_only
@@ -172,6 +188,12 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
172
188
  method_to_be_traced 1,2,3,true,METRIC
173
189
  elapsed = Time.now - t1
174
190
 
191
+ begin
192
+ self.class.remove_method_tracer :method_to_be_traced, METRIC
193
+ rescue RuntimeError
194
+ # ignore 'no tracer' errors from remove method tracer
195
+ end
196
+
175
197
  stats = @stats_engine.get_stats(METRIC)
176
198
  check_time stats.total_call_time, elapsed
177
199
  assert stats.call_count == 1
@@ -186,6 +208,12 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
186
208
  t1 = Time.now
187
209
  method_to_be_traced 1,2,3,true,expected_metric
188
210
  elapsed = Time.now - t1
211
+
212
+ begin
213
+ self.class.remove_method_tracer :method_to_be_traced, metric_code
214
+ rescue RuntimeError
215
+ # ignore 'no tracer' errors from remove method tracer
216
+ end
189
217
 
190
218
  stats = @stats_engine.get_stats(expected_metric)
191
219
  check_time stats.total_call_time, elapsed