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
@@ -44,25 +44,37 @@ module NewRelic::Rack
44
44
  footer = NewRelic::Agent.browser_timing_footer
45
45
  header = NewRelic::Agent.browser_timing_header
46
46
 
47
- head_pos = if beginning_of_source.include?('X-UA-Compatible')
48
- # put at end of header if UA-Compatible meta tag found
47
+ x_ua_compatible_found = beginning_of_source.include?('X-UA-Compatible')
48
+
49
+ head_pos = if x_ua_compatible_found
50
+ # put at end of header if X-UA-Compatible meta tag found
51
+ NewRelic::Agent.logger.debug "Detected X-UA-Compatible meta tag. Attempting to insert RUM header at end of head."
49
52
  beginning_of_source.index("</head>")
50
- elsif head_open = beginning_of_source.index("<head")
53
+ elsif head_open = beginning_of_source.index("<head")
54
+ NewRelic::Agent.logger.debug "Attempting to insert RUM header at beginning of head."
51
55
  # put at the beginning of the header
52
56
  beginning_of_source.index(">", head_open) + 1
57
+ else
58
+ NewRelic::Agent.logger.debug "Failed to detect head tag. Attempting to insert RUM header at above body tag."
59
+ # otherwise put the header right above body start
60
+ body_start
53
61
  end
54
- # otherwise put the header right above body start
55
- head_pos ||= body_start
56
62
 
57
63
  # check that head_pos is less than body close. If it's not something
58
64
  # is really weird and we should punt.
59
- if head_pos < body_close
65
+ if head_pos && (head_pos < body_close)
60
66
  # rebuild the source
61
67
  source = source[0..(head_pos-1)] <<
62
68
  header <<
63
69
  source[head_pos..(body_close-1)] <<
64
70
  footer <<
65
71
  source[body_close..-1]
72
+ else
73
+ if head_pos
74
+ NewRelic::Agent.logger.debug "Skipping RUM instrumentation. Failed to detect head tags."
75
+ else
76
+ NewRelic::Agent.logger.debug "Skipping RUM instrumentation. Detected head is after detected body close."
77
+ end
66
78
  end
67
79
  end
68
80
  headers['Content-Length'] = source.length.to_s if headers['Content-Length']
@@ -3,8 +3,8 @@ module NewRelic
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 3
5
5
  MINOR = 4
6
- TINY = 1
7
- BUILD = nil # Set to nil for a release, 'beta1', 'alpha', etc for prerelease builds
6
+ TINY = 2
7
+ BUILD = 'beta1' # Set to nil for a release, 'beta1', 'alpha', etc for prerelease builds
8
8
  STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
9
9
  end
10
10
 
data/newrelic.yml CHANGED
@@ -209,10 +209,6 @@ common: &default_settings
209
209
  # overhead slightly on every memcached call, and can have security
210
210
  # implications if your memcached keys are sensitive
211
211
  # capture_memcache_keys: true
212
-
213
- # Certain types of instrumentation such as GC stats will not work if
214
- # you are running multi-threaded. Please let us know.
215
- # multi_threaded = false
216
212
 
217
213
  # Application Environments
218
214
  # ------------------------------------------
data/newrelic_rpm.gemspec CHANGED
@@ -5,13 +5,13 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "newrelic_rpm"
8
- s.version = "3.4.1"
8
+ s.version = "3.4.2.beta1"
9
9
 
10
- s.authors = ["Bill Kayser", "Jon Guymon", "Justin George", "Darin Swanson"]
11
- s.date = "2012-07-26"
10
+ s.authors = ["Bill Kayser", "Jon Guymon", "Justin George", "Darin Swanson", "Rob Saul"]
11
+ s.date = "2012-08-31"
12
12
  s.description = "New Relic is a performance management system, developed by New Relic,\nInc (http://www.newrelic.com). New Relic provides you with deep\ninformation about the performance of your web application as it runs\nin production. The New Relic Ruby Agent is dual-purposed as a either a\nGem or plugin, hosted on\nhttp://github.com/newrelic/rpm/\n"
13
13
  s.email = "support@newrelic.com"
14
- s.executables = ["mongrel_rpm", "newrelic_cmd", "newrelic"]
14
+ s.executables = ["newrelic", "mongrel_rpm", "newrelic_cmd"]
15
15
  s.extra_rdoc_files = [
16
16
  "CHANGELOG",
17
17
  "LICENSE",
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
  "CHANGELOG",
23
23
  "LICENSE",
24
24
  "README.rdoc",
25
+ "ReleaseNotes.md",
25
26
  "bin/mongrel_rpm",
26
27
  "bin/newrelic",
27
28
  "bin/newrelic_cmd",
@@ -37,6 +38,12 @@ Gem::Specification.new do |s|
37
38
  "lib/new_relic/agent/browser_monitoring.rb",
38
39
  "lib/new_relic/agent/busy_calculator.rb",
39
40
  "lib/new_relic/agent/chained_call.rb",
41
+ "lib/new_relic/agent/configuration.rb",
42
+ "lib/new_relic/agent/configuration/defaults.rb",
43
+ "lib/new_relic/agent/configuration/environment_source.rb",
44
+ "lib/new_relic/agent/configuration/manager.rb",
45
+ "lib/new_relic/agent/configuration/server_source.rb",
46
+ "lib/new_relic/agent/configuration/yaml_source.rb",
40
47
  "lib/new_relic/agent/database.rb",
41
48
  "lib/new_relic/agent/error_collector.rb",
42
49
  "lib/new_relic/agent/instrumentation.rb",
@@ -91,7 +98,6 @@ Gem::Specification.new do |s|
91
98
  "lib/new_relic/commands/install.rb",
92
99
  "lib/new_relic/control.rb",
93
100
  "lib/new_relic/control/class_methods.rb",
94
- "lib/new_relic/control/configuration.rb",
95
101
  "lib/new_relic/control/frameworks.rb",
96
102
  "lib/new_relic/control/frameworks/external.rb",
97
103
  "lib/new_relic/control/frameworks/merb.rb",
@@ -148,6 +154,10 @@ Gem::Specification.new do |s|
148
154
  "test/new_relic/agent/beacon_configuration_test.rb",
149
155
  "test/new_relic/agent/browser_monitoring_test.rb",
150
156
  "test/new_relic/agent/busy_calculator_test.rb",
157
+ "test/new_relic/agent/configuration/environment_source_test.rb",
158
+ "test/new_relic/agent/configuration/manager_test.rb",
159
+ "test/new_relic/agent/configuration/server_source_test.rb",
160
+ "test/new_relic/agent/configuration/yaml_source_test.rb",
151
161
  "test/new_relic/agent/database_test.rb",
152
162
  "test/new_relic/agent/error_collector/notice_error_test.rb",
153
163
  "test/new_relic/agent/error_collector_test.rb",
@@ -184,7 +194,7 @@ Gem::Specification.new do |s|
184
194
  "test/new_relic/collection_helper_test.rb",
185
195
  "test/new_relic/command/deployments_test.rb",
186
196
  "test/new_relic/control/class_methods_test.rb",
187
- "test/new_relic/control/configuration_test.rb",
197
+ "test/new_relic/control/frameworks/rails_test.rb",
188
198
  "test/new_relic/control/logging_methods_test.rb",
189
199
  "test/new_relic/control_test.rb",
190
200
  "test/new_relic/delayed_job_injection_test.rb",
@@ -44,5 +44,6 @@ test:
44
44
  error_collector:
45
45
  enabled: true
46
46
  capture_source: true
47
-
48
-
47
+
48
+ development:
49
+ host: the.wrong.host
@@ -4,7 +4,7 @@ require 'ostruct'
4
4
 
5
5
  class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
6
6
  include NewRelic::Agent::Agent::Connect
7
-
7
+
8
8
  def setup
9
9
  @connected = nil
10
10
  @keep_retrying = nil
@@ -14,6 +14,7 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
14
14
  @sql_sampler = NewRelic::Agent::SqlSampler.new
15
15
  server = NewRelic::Control::Server.new('localhost', 30303)
16
16
  @service = NewRelic::Agent::NewRelicService.new('abcdef', server)
17
+ log.stubs(:warn)
17
18
  end
18
19
 
19
20
  def control
@@ -120,55 +121,44 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
120
121
  end
121
122
 
122
123
  def test_log_seed_token
123
- fake_control = mocked_control
124
- fake_control.expects(:validate_seed).times(2).returns("many seeds")
125
- fake_control.expects(:validate_token).once.returns("a token, man")
126
- log.expects(:debug).with("Connecting with validation seed/token: many seeds/a token, man").once
127
- log_seed_token
124
+ with_config(:validate_seed => 'many seeds', :validate_token => 'a token, man') do
125
+ log.expects(:debug).with("Connecting with validation seed/token: many seeds/a token, man").once
126
+ log_seed_token
127
+ end
128
128
  end
129
129
 
130
130
  def test_no_seed_token
131
- fake_control = mocked_control
132
- fake_control.expects(:validate_seed).once.returns(nil)
133
- log.expects(:debug).never
134
- log_seed_token
131
+ with_config(:validate_seed => false) do
132
+ log.expects(:debug).never
133
+ log_seed_token
134
+ end
135
135
  end
136
136
 
137
- def mocks_for_positive_environment_for_connect(value_for_control)
138
- control = mocked_control
139
- control.expects(:'[]').with('send_environment_info').once.returns(value_for_control)
137
+ def test_environment_for_connect_positive
140
138
  fake_env = mock('local_env')
141
139
  fake_env.expects(:snapshot).once.returns("snapshot")
142
- control.expects(:local_env).once.returns(fake_env)
143
- end
144
-
145
- def test_environment_for_connect_nil
146
- mocks_for_positive_environment_for_connect(nil)
147
- assert_equal 'snapshot', environment_for_connect
148
- end
149
-
150
- def test_environment_for_connect_positive
151
- mocks_for_positive_environment_for_connect(true)
152
- assert_equal 'snapshot', environment_for_connect
140
+ NewRelic::Control.instance.expects(:local_env).once.returns(fake_env)
141
+ with_config(:send_environment_info => true) do
142
+ assert_equal 'snapshot', environment_for_connect
143
+ end
153
144
  end
154
145
 
155
146
  def test_environment_for_connect_negative
156
- control = mocked_control
157
- control.expects(:'[]').with('send_environment_info').once.returns(false)
158
- assert_equal [], environment_for_connect
147
+ with_config(:send_environment_info => false) do
148
+ assert_equal [], environment_for_connect
149
+ end
159
150
  end
160
151
 
161
152
  def test_validate_settings
162
- control = mocked_control
163
- control.expects(:validate_seed).once
164
- control.expects(:validate_token).once
165
- assert_equal({:seed => nil, :token => nil}, validate_settings)
153
+ with_config(:validate_seed => 'seed', :validate_token => 'token') do
154
+ assert_equal 'seed', NewRelic::Agent.instance.validate_settings[:seed]
155
+ assert_equal 'token', NewRelic::Agent.instance.validate_settings[:token]
156
+ end
166
157
  end
167
158
 
168
159
  def test_connect_settings
169
160
  control = mocked_control
170
- control.expects(:app_names)
171
- control.expects(:settings)
161
+ NewRelic::Agent.config.expects(:app_names)
172
162
  self.expects(:validate_settings)
173
163
  self.expects(:environment_for_connect)
174
164
  keys = %w(pid host app_name language agent_version environment settings validate)
@@ -224,19 +214,18 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
224
214
  end
225
215
 
226
216
  def test_config_transaction_tracer
227
- NewRelic::Control.instance.settings['transaction_tracer'] = {
228
- 'enabled' => true,
229
- 'random_sample' => false,
230
- 'explain_threshold' => 0.75,
231
- 'explain_enabled' => true
217
+ test_config = {
218
+ 'transaction_tracer.enabled' => true,
219
+ 'transaction_tracer.random_sampler' => false,
220
+ 'transaction_tracer.explain_threshold' => 0.75,
221
+ 'transaction_tracer.explain_enabled' => true
232
222
  }
233
-
234
- config_transaction_tracer
235
-
236
- assert @transaction_sampler.enabled?
237
- assert_equal 0.75, @transaction_sampler.explain_threshold
238
- assert @transaction_sampler.explain_enabled
239
- # assert_equal 1.5, @transaction_sampler.transaction_threshold
223
+ with_config(test_config) do
224
+ config_transaction_tracer
225
+ assert @transaction_sampler.enabled?
226
+ assert_equal 0.75, @transaction_sampler.explain_threshold
227
+ assert @transaction_sampler.explain_enabled
228
+ end
240
229
  end
241
230
 
242
231
  def test_configure_transaction_tracer_with_random_sampling
@@ -274,53 +263,49 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
274
263
  end
275
264
 
276
265
  def test_apdex_f
277
- NewRelic::Control.instance.expects(:apdex_t).returns(10)
278
- assert_equal 40, apdex_f
279
- end
280
-
281
- def test_apdex_f_threshold_positive
282
- NewRelic::Control.instance.settings['transaction_tracer'] = { 'transaction_threshold' => 'apdex_f' }
283
- assert apdex_f_threshold?
284
- end
285
-
286
- def test_apdex_f_threshold_negative
287
- NewRelic::Control.instance.settings['transaction_tracer'] = { 'transaction_threshold' => 'WHEE' }
288
- assert !apdex_f_threshold?
266
+ with_config(:apdex_t => 10) do
267
+ assert_equal 40, apdex_f
268
+ end
289
269
  end
290
270
 
291
271
  def test_set_sql_recording_default
292
- NewRelic::Control.instance.settings['transaction_tracer'] = { }
293
- self.expects(:log_sql_transmission_warning?)
294
- set_sql_recording!
295
- assert_equal :obfuscated, @record_sql, " should default to :obfuscated, was #{@record_sql}"
272
+ with_config(:'transaction_tracer.record_sql' => 'obfuscated') do
273
+ self.expects(:log_sql_transmission_warning?)
274
+ set_sql_recording!
275
+ assert_equal :obfuscated, @record_sql, " should default to :obfuscated, was #{@record_sql}"
276
+ end
296
277
  end
297
278
 
298
279
  def test_set_sql_recording_off
299
- NewRelic::Control.instance.settings['transaction_tracer'] = {'record_sql' => 'off'}
300
- self.expects(:log_sql_transmission_warning?)
301
- set_sql_recording!
302
- assert_equal :off, @record_sql, "should be set to :off, was #{@record_sql}"
280
+ with_config(:'transaction_tracer.record_sql' => 'off') do
281
+ self.expects(:log_sql_transmission_warning?)
282
+ set_sql_recording!
283
+ assert_equal :off, @record_sql, "should be set to :off, was #{@record_sql}"
284
+ end
303
285
  end
304
286
 
305
287
  def test_set_sql_recording_none
306
- NewRelic::Control.instance.settings['transaction_tracer'] = {'record_sql' => 'none'}
307
- self.expects(:log_sql_transmission_warning?)
308
- set_sql_recording!
309
- assert_equal :off, @record_sql, "should be set to :off, was #{@record_sql}"
288
+ with_config(:'transaction_tracer.record_sql' => 'none') do
289
+ self.expects(:log_sql_transmission_warning?)
290
+ set_sql_recording!
291
+ assert_equal :off, @record_sql, "should be set to :off, was #{@record_sql}"
292
+ end
310
293
  end
311
294
 
312
295
  def test_set_sql_recording_raw
313
- NewRelic::Control.instance.settings['transaction_tracer'] = {'record_sql' => 'raw'}
314
- self.expects(:log_sql_transmission_warning?)
315
- set_sql_recording!
316
- assert_equal :raw, @record_sql, "should be set to :raw, was #{@record_sql}"
296
+ with_config(:'transaction_tracer.record_sql' => 'raw') do
297
+ self.expects(:log_sql_transmission_warning?)
298
+ set_sql_recording!
299
+ assert_equal :raw, @record_sql, "should be set to :raw, was #{@record_sql}"
300
+ end
317
301
  end
318
302
 
319
303
  def test_set_sql_recording_falsy
320
- NewRelic::Control.instance.settings['transaction_tracer'] = {'record_sql' => false}
321
- self.expects(:log_sql_transmission_warning?)
322
- set_sql_recording!
323
- assert_equal :off, @record_sql, "should be set to :off, was #{@record_sql}"
304
+ with_config(:'transaction_tracer.record_sql' => false) do
305
+ self.expects(:log_sql_transmission_warning?)
306
+ set_sql_recording!
307
+ assert_equal :off, @record_sql, "should be set to :off, was #{@record_sql}"
308
+ end
324
309
  end
325
310
 
326
311
  def test_log_sql_transmission_warning_negative
@@ -366,17 +351,18 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
366
351
  'collect_errors' => true,
367
352
  'sample_rate' => 10
368
353
  }
369
- NewRelic::Control.instance.settings['transaction_tracer'] = {'enabled' => true}
370
354
  self.expects(:log_connection!).with(config)
371
355
  self.expects(:configure_transaction_tracer!).with(true, 10)
372
356
  self.expects(:configure_error_collector!).with(true)
373
357
  @transaction_sampler = stub('transaction sampler', :configure! => true,
374
358
  :config => {})
375
- @sql_sampler = stub('sql sampler', :configure! => true)
376
- finish_setup(config)
377
- assert_equal 'fishsticks', @service.agent_id
378
- assert_equal 'pasta sauce', @report_period
379
- assert_equal 'tamales', @url_rules
359
+ @sql_sampler = stub('sql sampler', :configure! => true)
360
+ with_config(:'transaction_tracer.enabled' => true) do
361
+ finish_setup(config)
362
+ assert_equal 'fishsticks', @service.agent_id
363
+ assert_equal 'pasta sauce', @report_period
364
+ assert_equal 'tamales', @url_rules
365
+ end
380
366
  end
381
367
 
382
368
  def test_finish_setup_without_config
@@ -385,6 +371,25 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
385
371
  assert_equal 'blah', @service.agent_id
386
372
  end
387
373
 
374
+ # no idea why this test leaks in Rails 2.0
375
+ # will be moved to a multiverse test eventually anyway
376
+ if !Rails::VERSION::STRING =~ /2\.0.*/
377
+ def test_set_apdex_t_from_server
378
+ service = NewRelic::FakeService.new
379
+ NewRelic::Agent::Agent.instance.service = service
380
+ service.mock['connect'] = {
381
+ 'apdex_t' => 0.5,
382
+ 'listen_to_server_config' => true
383
+ }
384
+ with_config(:sync_startup => true, :monitor_mode => true,
385
+ :license_key => 'a' * 40) do
386
+ NewRelic::Agent.manual_start
387
+ assert_equal 0.5, NewRelic::Agent.config[:apdex_t]
388
+ NewRelic::Agent.shutdown
389
+ end
390
+ end
391
+ end
392
+
388
393
  private
389
394
 
390
395
  def mocked_control
@@ -16,39 +16,39 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
16
16
  end
17
17
 
18
18
  def test_disabled_positive
19
- control = mocked_control
20
- control.expects(:agent_enabled?).returns(false)
21
- assert disabled?
19
+ with_config(:agent_enabled => false) do
20
+ assert disabled?
21
+ end
22
22
  end
23
23
 
24
24
  def test_disabled_negative
25
- control = mocked_control
26
- control.expects(:agent_enabled?).returns(true)
27
- assert !disabled?
25
+ with_config(:agent_enabled => true) do
26
+ assert !disabled?
27
+ end
28
28
  end
29
29
 
30
30
  def test_log_dispatcher_positive
31
- control = mocked_control
32
31
  log = mocked_log
33
- control.expects(:dispatcher).returns('Y U NO SERVE WEBPAGE')
34
- log.expects(:info).with("Dispatcher: Y U NO SERVE WEBPAGE")
35
- log_dispatcher
32
+ with_config(:dispatcher => 'Y U NO SERVE WEBPAGE') do
33
+ log.expects(:info).with("Dispatcher: Y U NO SERVE WEBPAGE")
34
+ log_dispatcher
35
+ end
36
36
  end
37
37
 
38
38
  def test_log_dispatcher_negative
39
- control = mocked_control
40
39
  log = mocked_log
41
- control.expects(:dispatcher).returns('')
42
- log.expects(:info).with("No dispatcher detected.")
43
- log_dispatcher
40
+ with_config(:dispatcher => '') do
41
+ log.expects(:info).with("No dispatcher detected.")
42
+ log_dispatcher
43
+ end
44
44
  end
45
45
 
46
46
  def test_log_app_names
47
- control = mocked_control
48
- log = mocked_log
49
- control.expects(:app_names).returns(%w(zam zam zabam))
50
- log.expects(:info).with("Application: zam, zam, zabam")
51
- log_app_names
47
+ with_config(:app_name => 'zam;zam;zabam') do
48
+ log = mocked_log
49
+ log.expects(:info).with("Application: zam, zam, zabam")
50
+ log_app_names
51
+ end
52
52
  end
53
53
 
54
54
  def test_check_config_and_start_agent_disabled
@@ -70,26 +70,20 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
70
70
  end
71
71
 
72
72
  def test_check_config_and_start_agent_normal
73
- self.expects(:monitoring?).returns(true)
74
- self.expects(:has_correct_license_key?).returns(true)
75
- self.expects(:using_forking_dispatcher?).returns(false)
76
- control = mocked_control
77
- control.expects(:sync_startup).returns(false)
78
73
  self.expects(:start_worker_thread)
79
74
  self.expects(:install_exit_handler)
80
- check_config_and_start_agent
75
+ with_config(:sync_startup => false, :monitor_mode => true, :license_key => 'a' * 40) do
76
+ check_config_and_start_agent
77
+ end
81
78
  end
82
79
 
83
80
  def test_check_config_and_start_agent_sync
84
- self.expects(:monitoring?).returns(true)
85
- self.expects(:has_correct_license_key?).returns(true)
86
- self.expects(:using_forking_dispatcher?).returns(false)
87
- control = mocked_control
88
- control.expects(:sync_startup).returns(true)
89
81
  self.expects(:connect_in_foreground)
90
82
  self.expects(:start_worker_thread)
91
83
  self.expects(:install_exit_handler)
92
- check_config_and_start_agent
84
+ with_config(:sync_startup => true, :monitor_mode => true, :license_key => 'a' * 40) do
85
+ check_config_and_start_agent
86
+ end
93
87
  end
94
88
 
95
89
  def test_connect_in_foreground
@@ -103,8 +97,6 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
103
97
  private :at_exit
104
98
 
105
99
  def test_install_exit_handler_positive
106
- control = mocked_control
107
- control.expects(:send_data_on_exit).returns(true)
108
100
  NewRelic::LanguageSupport.expects(:using_engine?).with('rbx').returns(false)
109
101
  NewRelic::LanguageSupport.expects(:using_engine?).with('jruby').returns(false)
110
102
  self.expects(:using_sinatra?).returns(false)
@@ -112,27 +104,30 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
112
104
  # test the shutdown logic. It's somewhat unfortunate, but we can't
113
105
  # kill the interpreter during a test.
114
106
  self.expects(:shutdown)
115
- install_exit_handler
107
+ with_config(:send_data_on_exit => true) do
108
+ install_exit_handler
109
+ end
116
110
  end
117
111
 
118
112
  def test_install_exit_handler_negative
119
- control = mocked_control
120
- control.expects(:send_data_on_exit).returns(false)
121
- install_exit_handler
113
+ with_config(:send_data_on_exit => false) do
114
+ install_exit_handler
115
+ end
116
+ # should not raise excpetion
122
117
  end
123
118
 
124
119
  def test_install_exit_handler_weird_ruby
125
- control = mocked_control
126
- control.expects(:send_data_on_exit).times(3).returns(true)
127
- NewRelic::LanguageSupport.expects(:using_engine?).with('rbx').returns(false)
128
- NewRelic::LanguageSupport.expects(:using_engine?).with('jruby').returns(false)
129
- self.expects(:using_sinatra?).returns(true)
130
- install_exit_handler
131
- NewRelic::LanguageSupport.expects(:using_engine?).with('rbx').returns(false)
132
- NewRelic::LanguageSupport.expects(:using_engine?).with('jruby').returns(true)
133
- install_exit_handler
134
- NewRelic::LanguageSupport.expects(:using_engine?).with('rbx').returns(true)
135
- install_exit_handler
120
+ with_config(:send_data_one_exit => true) do
121
+ NewRelic::LanguageSupport.expects(:using_engine?).with('rbx').returns(false)
122
+ NewRelic::LanguageSupport.expects(:using_engine?).with('jruby').returns(false)
123
+ self.expects(:using_sinatra?).returns(true)
124
+ install_exit_handler
125
+ NewRelic::LanguageSupport.expects(:using_engine?).with('rbx').returns(false)
126
+ NewRelic::LanguageSupport.expects(:using_engine?).with('jruby').returns(true)
127
+ install_exit_handler
128
+ NewRelic::LanguageSupport.expects(:using_engine?).with('rbx').returns(true)
129
+ install_exit_handler
130
+ end
136
131
  end
137
132
 
138
133
  def test_notify_log_file_location_positive
@@ -149,32 +144,32 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
149
144
  end
150
145
 
151
146
  def test_monitoring_positive
152
- control = mocked_control
153
- control.expects(:monitor_mode?).returns(true)
154
- log = mocked_log
155
- assert monitoring?
147
+ with_config(:monitor_mode => true) do
148
+ log = mocked_log
149
+ assert monitoring?
150
+ end
156
151
  end
157
152
 
158
153
  def test_monitoring_negative
159
- control = mocked_control
160
154
  log = mocked_log
161
- control.expects(:monitor_mode?).returns(false)
162
- log.expects(:send).with(:warn, "Agent configured not to send data in this environment - edit newrelic.yml to change this")
163
- assert !monitoring?
155
+ with_config(:monitor_mode => false) do
156
+ log.expects(:send).with(:warn, "Agent configured not to send data in this environment - edit newrelic.yml to change this")
157
+ assert !monitoring?
158
+ end
164
159
  end
165
160
 
166
161
  def test_has_license_key_positive
167
- control = mocked_control
168
- control.expects(:license_key).returns("a" * 40)
169
- assert has_license_key?
162
+ with_config(:license_key => 'a' * 40) do
163
+ assert has_license_key?
164
+ end
170
165
  end
171
166
 
172
167
  def test_has_license_key_negative
173
- control = mocked_control
174
- control.expects(:license_key).returns(nil)
175
- log = mocked_log
176
- log.expects(:send).with(:error, 'No license key found. Please edit your newrelic.yml file and insert your license key.')
177
- assert !has_license_key?
168
+ with_config(:license_key => false) do
169
+ log = mocked_log
170
+ log.expects(:send).with(:error, 'No license key found. Please edit your newrelic.yml file and insert your license key.')
171
+ assert !has_license_key?
172
+ end
178
173
  end
179
174
 
180
175
  def test_has_correct_license_key_positive
@@ -189,31 +184,31 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
189
184
  end
190
185
 
191
186
  def test_correct_license_length_positive
192
- control = mocked_control
193
- control.expects(:license_key).returns("a" * 40)
194
- assert correct_license_length
187
+ with_config(:license_key => 'a' * 40) do
188
+ assert correct_license_length
189
+ end
195
190
  end
196
191
 
197
192
  def test_correct_license_length_negative
198
- control = mocked_control
199
- log = mocked_log
200
- control.expects(:license_key).returns("a"*30)
201
- log.expects(:send).with(:error, "Invalid license key: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
202
- assert !correct_license_length
193
+ with_config(:license_key => 'a' * 30) do
194
+ log = mocked_log
195
+ log.expects(:send).with(:error, "Invalid license key: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
196
+ assert !correct_license_length
197
+ end
203
198
  end
204
199
 
205
200
  def test_using_forking_dispatcher_positive
206
- control = mocked_control
207
- control.expects(:dispatcher).returns(:passenger)
208
- log = mocked_log
209
- log.expects(:send).with(:info, "Connecting workers after forking.")
210
- assert using_forking_dispatcher?
201
+ with_config(:dispatcher => :passenger) do
202
+ log = mocked_log
203
+ log.expects(:send).with(:info, "Connecting workers after forking.")
204
+ assert using_forking_dispatcher?
205
+ end
211
206
  end
212
207
 
213
208
  def test_using_forking_dispatcher_negative
214
- control = mocked_control
215
- control.expects(:dispatcher).returns(:frobnitz)
216
- assert !using_forking_dispatcher?
209
+ with_config(:dispatcher => :frobnitz) do
210
+ assert !using_forking_dispatcher?
211
+ end
217
212
  end
218
213
 
219
214
  def test_log_unless_positive