newrelic_rpm 3.4.1 → 3.4.2.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 (81) hide show
  1. data/CHANGELOG +7 -0
  2. data/ReleaseNotes.md +638 -0
  3. data/lib/new_relic/agent/agent.rb +44 -56
  4. data/lib/new_relic/agent/beacon_configuration.rb +1 -1
  5. data/lib/new_relic/agent/browser_monitoring.rb +80 -42
  6. data/lib/new_relic/agent/configuration/defaults.rb +75 -0
  7. data/lib/new_relic/agent/configuration/environment_source.rb +42 -0
  8. data/lib/new_relic/agent/configuration/manager.rb +100 -0
  9. data/lib/new_relic/agent/configuration/server_source.rb +24 -0
  10. data/lib/new_relic/agent/configuration/yaml_source.rb +61 -0
  11. data/lib/new_relic/agent/configuration.rb +48 -0
  12. data/lib/new_relic/agent/error_collector.rb +10 -14
  13. data/lib/new_relic/agent/instrumentation/active_record.rb +1 -5
  14. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +20 -4
  15. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -1
  16. data/lib/new_relic/agent/instrumentation/memcache.rb +2 -2
  17. data/lib/new_relic/agent/instrumentation/metric_frame.rb +1 -1
  18. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +3 -3
  19. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +2 -2
  20. data/lib/new_relic/agent/instrumentation/resque.rb +1 -1
  21. data/lib/new_relic/agent/method_tracer.rb +1 -1
  22. data/lib/new_relic/agent/new_relic_service.rb +18 -9
  23. data/lib/new_relic/agent/pipe_channel_manager.rb +5 -6
  24. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +2 -5
  25. data/lib/new_relic/agent/sql_sampler.rb +11 -35
  26. data/lib/new_relic/agent/stats_engine/transactions.rb +2 -2
  27. data/lib/new_relic/agent/transaction_info.rb +24 -4
  28. data/lib/new_relic/agent/transaction_sample_builder.rb +2 -3
  29. data/lib/new_relic/agent/transaction_sampler.rb +9 -16
  30. data/lib/new_relic/agent.rb +4 -1
  31. data/lib/new_relic/collection_helper.rb +1 -1
  32. data/lib/new_relic/commands/deployments.rb +5 -3
  33. data/lib/new_relic/control/class_methods.rb +2 -3
  34. data/lib/new_relic/control/frameworks/rails.rb +8 -8
  35. data/lib/new_relic/control/frameworks/ruby.rb +2 -2
  36. data/lib/new_relic/control/instance_methods.rb +26 -32
  37. data/lib/new_relic/control/logging_methods.rb +5 -23
  38. data/lib/new_relic/control/server_methods.rb +11 -18
  39. data/lib/new_relic/control.rb +0 -1
  40. data/lib/new_relic/delayed_job_injection.rb +1 -1
  41. data/lib/new_relic/language_support.rb +8 -0
  42. data/lib/new_relic/noticed_error.rb +1 -1
  43. data/lib/new_relic/rack/browser_monitoring.rb +18 -6
  44. data/lib/new_relic/version.rb +2 -2
  45. data/newrelic.yml +0 -4
  46. data/newrelic_rpm.gemspec +16 -6
  47. data/test/config/newrelic.yml +3 -2
  48. data/test/new_relic/agent/agent/connect_test.rb +88 -83
  49. data/test/new_relic/agent/agent/start_test.rb +75 -80
  50. data/test/new_relic/agent/agent/start_worker_thread_test.rb +18 -18
  51. data/test/new_relic/agent/beacon_configuration_test.rb +13 -11
  52. data/test/new_relic/agent/browser_monitoring_test.rb +69 -14
  53. data/test/new_relic/agent/configuration/environment_source_test.rb +58 -0
  54. data/test/new_relic/agent/configuration/manager_test.rb +120 -0
  55. data/test/new_relic/agent/configuration/server_source_test.rb +28 -0
  56. data/test/new_relic/agent/configuration/yaml_source_test.rb +56 -0
  57. data/test/new_relic/agent/error_collector/notice_error_test.rb +63 -50
  58. data/test/new_relic/agent/error_collector_test.rb +10 -12
  59. data/test/new_relic/agent/new_relic_service_test.rb +11 -3
  60. data/test/new_relic/agent/pipe_channel_manager_test.rb +19 -16
  61. data/test/new_relic/agent/rpm_agent_test.rb +21 -19
  62. data/test/new_relic/agent/sql_sampler_test.rb +55 -56
  63. data/test/new_relic/agent/transaction_info_test.rb +45 -4
  64. data/test/new_relic/agent/transaction_sampler_test.rb +48 -44
  65. data/test/new_relic/agent_test.rb +68 -41
  66. data/test/new_relic/collection_helper_test.rb +7 -8
  67. data/test/new_relic/command/deployments_test.rb +12 -1
  68. data/test/new_relic/control/frameworks/rails_test.rb +26 -0
  69. data/test/new_relic/control/logging_methods_test.rb +77 -52
  70. data/test/new_relic/control_test.rb +103 -126
  71. data/test/new_relic/local_environment_test.rb +4 -6
  72. data/test/new_relic/rack/browser_monitoring_test.rb +4 -4
  73. data/test/new_relic/rack/developer_mode_test.rb +13 -7
  74. data/test/new_relic/transaction_sample_test.rb +8 -2
  75. data/test/script/build_test_gem.sh +9 -3
  76. data/test/script/ci.sh +13 -3
  77. data/test/test_helper.rb +9 -2
  78. data/ui/helpers/developer_mode_helper.rb +2 -7
  79. metadata +26 -11
  80. data/lib/new_relic/control/configuration.rb +0 -206
  81. data/test/new_relic/control/configuration_test.rb +0 -77
@@ -3,11 +3,52 @@ require 'ostruct'
3
3
 
4
4
  class NewRelic::Agent::TransactionInfoTest < Test::Unit::TestCase
5
5
  def setup
6
- @request = OpenStruct.new(:cookies => {'NRAGENT' => 'tk=1234<tag>evil</tag>5678'})
6
+ @request = OpenStruct.new(:cookies => {'NRAGENT' => 'tk=12345678'})
7
+ @request_with_embedded_tag = OpenStruct.new(:cookies => {'NRAGENT' => 'tk=1234<tag>evil</tag>5678'})
8
+ @request_with_embedded_utf8_encoded_js = OpenStruct.new(:cookies => {'NRAGENT' => "tk=1234&#34&#93&#41&#595678"})
9
+ @request_with_double_quotes = OpenStruct.new(:cookies => {'NRAGENT' => 'tk="""deadbeef"""'})
10
+ @request_with_single_quotes = OpenStruct.new(:cookies => {'NRAGENT' => "tk='''deadbeef'''"})
11
+ @request_with_multi_lt = OpenStruct.new(:cookies => {'NRAGENT' => 'tk=<<<deadbeef'})
12
+ @request_with_multi_gt = OpenStruct.new(:cookies => {'NRAGENT' => 'tk=>>>deadbeef'})
13
+ @request_with_bare_token = OpenStruct.new(:cookies => {'NRAGENT' => 0xdeadbeef})
14
+ @request_with_nil_token = OpenStruct.new(:cookies => {'NRAGENT' => nil})
7
15
  end
8
16
 
9
- def test_get_token_gets_sanitized_token_from_cookie
10
- assert_equal('1234&lt;tag&gt;evil&lt;/tag&gt;5678',
11
- NewRelic::Agent::TransactionInfo.get_token(@request))
17
+ def test_get_token_safe_token_returned_untouched
18
+ assert_equal("12345678", NewRelic::Agent::TransactionInfo.get_token(@request))
12
19
  end
20
+
21
+ def test_get_token_with_embedded_tags_sanitized
22
+ assert_equal("",NewRelic::Agent::TransactionInfo.get_token(@request_with_embedded_tag))
23
+ end
24
+
25
+ def test_get_token_with_embedded_utf8_js_sanitized
26
+ assert_equal("1234&amp;#34&amp;#93&amp;#41&amp;#595678",
27
+ NewRelic::Agent::TransactionInfo.get_token(@request_with_embedded_utf8_encoded_js))
28
+ end
29
+
30
+ def test_get_token_replaces_double_quoted_token_with_empty_string
31
+ assert_equal("", NewRelic::Agent::TransactionInfo.get_token(@request_with_double_quotes))
32
+ end
33
+
34
+ def test_get_token_replaces_single_quoted_toket_with_empty_string
35
+ assert_equal("", NewRelic::Agent::TransactionInfo.get_token(@request_with_single_quotes))
36
+ end
37
+
38
+ def test_get_token_replaces_token_started_with_multiple_Lt_with_empty_string
39
+ assert_equal("", NewRelic::Agent::TransactionInfo.get_token(@request_with_multi_lt))
40
+ end
41
+
42
+ def test_get_token_replaces_token_started_with_multiple_gt_with_empty_string
43
+ assert_equal("", NewRelic::Agent::TransactionInfo.get_token(@request_with_multi_gt))
44
+ end
45
+
46
+ def test_get_token_bare_value_replaced_with_nil
47
+ assert_equal(nil,NewRelic::Agent::TransactionInfo.get_token(@request_with_bare_token))
48
+ end
49
+
50
+ def test_get_token_nil_token_returns_nil_token
51
+ assert_equal(nil,NewRelic::Agent::TransactionInfo.get_token(@request_with_ni_token))
52
+ end
53
+
13
54
  end
@@ -27,11 +27,15 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
27
27
  agent.stubs(:stats_engine).returns(stats_engine)
28
28
  @sampler = NewRelic::Agent::TransactionSampler.new
29
29
  stats_engine.transaction_sampler = @sampler
30
+ @test_config = { 'developer_mode' => true }
31
+ NewRelic::Agent.config.apply_config(@test_config)
32
+ @sampler.configure!
30
33
  end
31
34
 
32
35
  def teardown
33
36
  super
34
37
  Thread.current[:transaction_sample_builder] = nil
38
+ NewRelic::Agent.config.remove_config(@test_config)
35
39
  end
36
40
 
37
41
  def test_initialize
@@ -58,12 +62,17 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
58
62
  end
59
63
 
60
64
  def test_configure
61
- control = NewRelic::Control.instance
62
- control.merge_options('transaction_tracer' => {'stack_trace_threshold' => 5.0, 'limit_segments' => 20, 'explain_threshold' => 4.0})
63
- @sampler.configure!
64
- assert_equal 20, @sampler.instance_variable_get('@segment_limit')
65
- assert_equal 5.0, @sampler.instance_variable_get('@stack_trace_threshold')
66
- assert_equal 4.0, @sampler.instance_variable_get('@explain_threshold')
65
+ test_config = {
66
+ 'transaction_tracer.stack_trace_threshold' => 5.0,
67
+ 'transaction_tracer.limit_segments' => 20,
68
+ 'transaction_tracer.explain_threshold' => 4.0
69
+ }
70
+ with_config(test_config) do
71
+ @sampler.configure!
72
+ assert_equal 20, @sampler.instance_variable_get('@segment_limit')
73
+ assert_equal 5.0, @sampler.instance_variable_get('@stack_trace_threshold')
74
+ assert_equal 4.0, @sampler.instance_variable_get('@explain_threshold')
75
+ end
67
76
  end
68
77
 
69
78
  def test_current_sample_id_default
@@ -124,17 +133,15 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
124
133
  end
125
134
 
126
135
  def test_notice_push_scope_with_builder
127
- NewRelic::Control.instance.expects(:developer_mode?).returns(false)
128
- builder = mock('builder')
129
- builder.expects(:trace_entry).with('a scope', 100.0)
130
- @sampler.expects(:builder).returns(builder).twice
131
-
132
- @sampler.notice_push_scope('a scope', Time.at(100))
136
+ with_config(:developer_mode => false) do
137
+ builder = mock('builder')
138
+ builder.expects(:trace_entry).with('a scope', 100.0)
139
+ @sampler.expects(:builder).returns(builder).twice
140
+ @sampler.notice_push_scope('a scope', Time.at(100))
141
+ end
133
142
  end
134
143
 
135
144
  def test_notice_push_scope_in_dev_mode
136
- NewRelic::Control.instance.expects(:developer_mode?).returns(true)
137
-
138
145
  builder = mock('builder')
139
146
  builder.expects(:trace_entry).with('a scope', 100.0)
140
147
  @sampler.expects(:builder).returns(builder).twice
@@ -239,7 +246,6 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
239
246
  end
240
247
 
241
248
  def test_store_sample_for_developer_mode_in_dev_mode
242
- NewRelic::Control.instance.expects(:developer_mode?).returns(true)
243
249
  sample = mock('sample')
244
250
  @sampler.expects(:truncate_samples)
245
251
  @sampler.store_sample_for_developer_mode(sample)
@@ -247,11 +253,12 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
247
253
  end
248
254
 
249
255
  def test_store_sample_for_developer_mode_no_dev
250
- NewRelic::Control.instance.stubs(:developer_mode?).returns(false)
251
- @sampler.configure!
252
- sample = mock('sample')
253
- @sampler.store_sample_for_developer_mode(sample)
254
- assert_equal([], @sampler.instance_variable_get('@samples'))
256
+ with_config(:developer_mode => false) do
257
+ @sampler.configure!
258
+ sample = mock('sample')
259
+ @sampler.store_sample_for_developer_mode(sample)
260
+ assert_equal([], @sampler.instance_variable_get('@samples'))
261
+ end
255
262
  end
256
263
 
257
264
  def test_store_slowest_sample_new_is_slowest
@@ -917,38 +924,35 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
917
924
 
918
925
  def test_param_capture
919
926
  [true, false].each do |capture|
920
- NewRelic::Control.instance.stubs(:capture_params).returns(capture)
921
- @sampler.notice_first_scope_push Time.now.to_f
922
- @sampler.notice_transaction('/path', nil, {:param => 'hi'})
923
- @sampler.notice_scope_empty
927
+ with_config(:capture_params => capture) do
928
+ @sampler.notice_first_scope_push Time.now.to_f
929
+ @sampler.notice_transaction('/path', nil, {:param => 'hi'})
930
+ @sampler.notice_scope_empty
924
931
 
925
- tt = @sampler.harvest(nil,0)[0]
932
+ tt = @sampler.harvest(nil,0)[0]
926
933
 
927
- assert_equal (capture) ? 1 : 0, tt.params[:request_params].length
934
+ assert_equal (capture) ? 1 : 0, tt.params[:request_params].length
935
+ end
928
936
  end
929
937
  end
930
-
938
+
931
939
  def test_should_not_collect_segments_beyond_limit
932
- NewRelic::Control.instance.merge_options('transaction_tracer' => {
933
- 'limit_segments' => 3,
934
- })
935
- @sampler.configure!
936
- run_sample_trace do
937
- @sampler.notice_push_scope 'a1'
938
- @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'hallah'", nil, 0)
939
- @sampler.notice_push_scope 'a11'
940
- @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'semolina'", nil, 0)
941
- @sampler.notice_pop_scope "a11"
942
- @sampler.notice_pop_scope "a1"
940
+ with_config(:'transaction_tracer.limit_segments' => 3) do
941
+ @sampler.configure!
942
+ run_sample_trace do
943
+ @sampler.notice_push_scope 'a1'
944
+ @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'hallah'", nil, 0)
945
+ @sampler.notice_push_scope 'a11'
946
+ @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'semolina'", nil, 0)
947
+ @sampler.notice_pop_scope "a11"
948
+ @sampler.notice_pop_scope "a1"
949
+ end
950
+ assert_equal 3, @sampler.samples[0].count_segments
943
951
  end
944
- assert_equal 3, @sampler.samples[0].count_segments
945
- NewRelic::Control.instance.merge_options('transaction_tracer' => {
946
- 'limit_segments' => 4000,
947
- })
948
952
  end
949
-
953
+
950
954
  private
951
-
955
+
952
956
  def run_sample_trace
953
957
  @sampler.notice_first_scope_push Time.now.to_f
954
958
  @sampler.notice_transaction '/path', nil, {}
@@ -3,7 +3,7 @@ require 'ostruct'
3
3
 
4
4
  module NewRelic
5
5
  class MainAgentTest < Test::Unit::TestCase
6
-
6
+
7
7
  # mostly this module just passes through to the active agent
8
8
  # through the agent method or the control instance through
9
9
  # NewRelic::Control.instance . But it's nice to make sure.
@@ -12,13 +12,42 @@ module NewRelic
12
12
  super
13
13
  Thread.current[:newrelic_untraced] = nil
14
14
  end
15
-
15
+
16
16
  def test_shutdown
17
17
  mock_agent = mocked_agent
18
18
  mock_agent.expects(:shutdown).with({})
19
19
  NewRelic::Agent.shutdown
20
20
  end
21
21
 
22
+ def test_shutdown_removes_manual_startup_config
23
+ NewRelic::Agent.manual_start(:some_absurd_setting => true)
24
+ assert NewRelic::Agent.config[:some_absurd_setting]
25
+ NewRelic::Agent.shutdown
26
+ assert !NewRelic::Agent.config[:some_absurd_setting]
27
+ end
28
+
29
+ def test_shutdown_removes_server_config
30
+ NewRelic::Agent.manual_start
31
+ NewRelic::Agent.instance.finish_setup('listen_to_server_config' => true,
32
+ :some_absurd_setting => true)
33
+ assert NewRelic::Agent.config[:some_absurd_setting]
34
+ NewRelic::Agent.shutdown
35
+ assert !NewRelic::Agent.config[:some_absurd_setting]
36
+ end
37
+
38
+ def test_finish_setup_applied_server_side_config
39
+ with_config({:'transction_tracer.enabled' => true, 'error_collector.enabled' => true,
40
+ :log_level => 'info'}, 2) do
41
+ NewRelic::Agent.instance.finish_setup('listen_to_server_config' => true,
42
+ 'transaction_tracer.enabled' => false,
43
+ 'collect_errors' => false,
44
+ 'log_level' => 'debug')
45
+ assert !NewRelic::Agent.config[:'transaction_tracer.enabled']
46
+ assert !NewRelic::Agent.config[:'error_collector.enabled']
47
+ assert_equal 'debug', NewRelic::Agent.config[:log_level]
48
+ end
49
+ end
50
+
22
51
  def test_after_fork
23
52
  mock_agent = mocked_agent
24
53
  mock_agent.expects(:after_fork).with({})
@@ -32,43 +61,41 @@ module NewRelic
32
61
 
33
62
  assert agent.forked?
34
63
  end
35
-
36
64
 
37
65
  if NewRelic::LanguageSupport.can_fork? &&
38
66
  !NewRelic::LanguageSupport.using_version?('1.9.1')
39
67
  def test_timeslice_harvest_with_after_fork_report_to_channel
40
- NewRelic::Control.instance.stubs(:agent_enabled?).returns(true)
41
- NewRelic::Control.instance.stubs(:monitor_mode?).returns(true)
42
-
43
- NewRelic::Agent::Agent.instance.service = NewRelic::FakeService.new
44
- NewRelic::Agent.shutdown # make sure the agent is not already started
45
- NewRelic::Agent.manual_start(:license_key => ('1234567890' * 4),
46
- :start_channel_listener => true)
47
-
48
- metric = 'Custom/test/method'
49
- NewRelic::Agent.instance.stats_engine.get_stats_no_scope(metric) \
50
- .record_data_point(1.0)
51
-
52
- # ensure that cached metric ids don't interfere with metric merging
53
- NewRelic::Agent.agent.instance_variable_set(:@metric_ids,
54
- {NewRelic::MetricSpec.new('Instance/Busy') => 1})
55
-
56
- NewRelic::Agent::PipeChannelManager.listener.close_all_pipes
57
- NewRelic::Agent.register_report_channel(:agent_test) # before fork
58
- pid = Process.fork do
59
- NewRelic::Agent.after_fork(:report_to_channel => :agent_test)
60
- NewRelic::Agent.agent.stats_engine.get_stats_no_scope(metric) \
61
- .record_data_point(2.0)
68
+ with_config(:agent_enabled => true, :monitor_mode => true) do
69
+ NewRelic::Agent::Agent.instance.service = NewRelic::FakeService.new
70
+ NewRelic::Agent.shutdown # make sure the agent is not already started
71
+ NewRelic::Agent.manual_start(:license_key => ('1234567890' * 4),
72
+ :start_channel_listener => true)
73
+
74
+ metric = 'Custom/test/method'
75
+ NewRelic::Agent.instance.stats_engine.get_stats_no_scope(metric) \
76
+ .record_data_point(1.0)
77
+
78
+ # ensure that cached metric ids don't interfere with metric merging
79
+ NewRelic::Agent.agent.instance_variable_set(:@metric_ids,
80
+ { NewRelic::MetricSpec.new('Instance/Busy') => 1 })
81
+
82
+ NewRelic::Agent::PipeChannelManager.listener.close_all_pipes
83
+ NewRelic::Agent.register_report_channel(:agent_test) # before fork
84
+ pid = Process.fork do
85
+ NewRelic::Agent.after_fork(:report_to_channel => :agent_test)
86
+ NewRelic::Agent.agent.stats_engine.get_stats_no_scope(metric) \
87
+ .record_data_point(2.0)
88
+ end
89
+ Process.wait(pid)
90
+ NewRelic::Agent::PipeChannelManager.listener.stop
91
+
92
+ engine = NewRelic::Agent.agent.stats_engine
93
+ assert_equal(3.0, engine.lookup_stats(metric).total_call_time)
94
+ assert_equal(2, engine.lookup_stats(metric).call_count)
62
95
  end
63
- Process.wait(pid)
64
- NewRelic::Agent::PipeChannelManager.listener.stop
65
-
66
- engine = NewRelic::Agent.agent.stats_engine
67
- assert_equal(3.0, engine.lookup_stats(metric).total_call_time)
68
- assert_equal(2, engine.lookup_stats(metric).call_count)
69
96
  end
70
97
  end
71
-
98
+
72
99
  def test_reset_stats
73
100
  mock_agent = mocked_agent
74
101
  mock_agent.expects(:reset_stats)
@@ -80,7 +107,7 @@ module NewRelic
80
107
  mock_control.expects(:init_plugin).with({:agent_enabled => true, :sync_startup => true})
81
108
  NewRelic::Agent.manual_start
82
109
  end
83
-
110
+
84
111
  def test_manual_start_with_opts
85
112
  mock_control = mocked_control
86
113
  mock_control.expects(:init_plugin).with({:agent_enabled => true, :sync_startup => false})
@@ -121,7 +148,7 @@ module NewRelic
121
148
  mock_stats_engine.expects(:get_stats).with('Custom/test/metric', false)
122
149
  NewRelic::Agent.get_stats('Custom/test/metric')
123
150
  end
124
-
151
+
125
152
  # note that this is the same as get_stats above, they're just aliases
126
153
  def test_get_stats_no_scope
127
154
  agent = mocked_agent
@@ -166,7 +193,7 @@ module NewRelic
166
193
  Thread.current[:record_tt] = false
167
194
  assert_equal(false, NewRelic::Agent.is_transaction_traced?, 'should be false since the thread local is false')
168
195
  end
169
-
196
+
170
197
  def test_is_sql_recorded_true
171
198
  Thread.current[:record_sql] = true
172
199
  assert_equal(true, NewRelic::Agent.is_sql_recorded?, 'should be true since the thread local is set')
@@ -181,7 +208,7 @@ module NewRelic
181
208
  Thread.current[:record_sql] = false
182
209
  assert_equal(false, NewRelic::Agent.is_sql_recorded?, 'should be false since the thread local is false')
183
210
  end
184
-
211
+
185
212
  def test_is_execution_traced_true
186
213
  Thread.current[:newrelic_untraced] = [true, true]
187
214
  assert_equal(true, NewRelic::Agent.is_execution_traced?, 'should be true since the thread local is set')
@@ -201,18 +228,18 @@ module NewRelic
201
228
  Thread.current[:newrelic_untraced] = [true, false]
202
229
  assert_equal(false, NewRelic::Agent.is_execution_traced?, 'should be false since the thread local stack has the last element false')
203
230
  end
204
-
231
+
205
232
  def test_instance
206
233
  assert_equal(NewRelic::Agent.agent, NewRelic::Agent.instance, "should return the same agent for both identical methods")
207
234
  end
208
-
235
+
209
236
  def test_register_report_channel
210
237
  NewRelic::Agent.register_report_channel(:channel_id)
211
238
  assert NewRelic::Agent::PipeChannelManager.channels[:channel_id] \
212
239
  .kind_of?(NewRelic::Agent::PipeChannelManager::Pipe)
213
240
  NewRelic::Agent::PipeChannelManager.listener.close_all_pipes
214
241
  end
215
-
242
+
216
243
  private
217
244
 
218
245
  def mocked_agent
@@ -220,7 +247,7 @@ module NewRelic
220
247
  NewRelic::Agent.stubs(:agent).returns(agent)
221
248
  agent
222
249
  end
223
-
250
+
224
251
  def mocked_control
225
252
  server = NewRelic::Control::Server.new('localhost', 3000)
226
253
  control = OpenStruct.new(:license_key => 'abcdef',
@@ -229,7 +256,7 @@ module NewRelic
229
256
  def [](key)
230
257
  nil
231
258
  end
232
-
259
+
233
260
  def fetch(k,d)
234
261
  nil
235
262
  end
@@ -24,7 +24,7 @@ class NewRelic::CollectionHelperTest < Test::Unit::TestCase
24
24
  assert_equal '1000', new_array[0]
25
25
  end
26
26
  def test_boolean
27
- np = normalize_params(NewRelic::Control.instance.settings)
27
+ np = normalize_params('monitor_mode' => false)
28
28
  assert_equal false, np['monitor_mode']
29
29
  end
30
30
  def test_string__singleton
@@ -118,14 +118,13 @@ class NewRelic::CollectionHelperTest < Test::Unit::TestCase
118
118
  end
119
119
 
120
120
  def test_disabled_strip_backtrace
121
- NewRelic::Control.instance['disable_backtrace_cleanup'] = true
122
- clean_trace = strip_nr_from_backtrace(mock_backtrace)
123
- assert_equal(1, clean_trace.grep(/new_relic/).size,
124
- "should not remove instances of new relic from backtrace but got: #{clean_trace.join("\n")}")
125
- assert_equal(1, clean_trace.grep(/_trace/).size,
121
+ with_config(:disable_backtrace_cleanup => true) do
122
+ clean_trace = strip_nr_from_backtrace(mock_backtrace)
123
+ assert_equal(1, clean_trace.grep(/new_relic/).size,
124
+ "should not remove instances of new relic from backtrace but got: #{clean_trace.join("\n")}")
125
+ assert_equal(1, clean_trace.grep(/_trace/).size,
126
126
  "should not remove trace method tags from method names but got: #{clean_trace.join("\n")}")
127
- # assert (clean_trace.grep(/find/).size >= 3), "should see at least three frames with 'find' in them (#{e}): \n#{clean_trace.join("\n")}"
128
- NewRelic::Control.instance['disable_backtrace_cleanup'] = false
127
+ end
129
128
  end
130
129
 
131
130
  private
@@ -56,7 +56,19 @@ class NewRelic::Command::DeploymentsTest < Test::Unit::TestCase
56
56
 
57
57
  @deployment = nil
58
58
  end
59
+
60
+ def test_error_if_no_license_key
61
+ config = { 'license_key' => nil }
62
+ NewRelic::Agent.config.apply_config(config)
63
+ assert_raise NewRelic::Command::CommandFailure do
64
+ deployment = NewRelic::Command::Deployments.new(%w[-a APP -r 3838 --user=Bill] << "Some lengthy description")
65
+ deployment.run
66
+ end
67
+ NewRelic::Agent.config.remove_config(config)
68
+ end
69
+
59
70
  private
71
+
60
72
  def mock_the_connection
61
73
  mock_connection = mock()
62
74
  @mock_response = mock()
@@ -64,5 +76,4 @@ class NewRelic::Command::DeploymentsTest < Test::Unit::TestCase
64
76
  mock_connection.expects(:request).returns(@mock_response)
65
77
  NewRelic::Control.instance.stubs(:http_connection).returns(mock_connection)
66
78
  end
67
-
68
79
  end