newrelic_rpm 2.13.4 → 2.13.5.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.
- data/CHANGELOG +9 -0
- data/lib/new_relic/agent.rb +2 -1
- data/lib/new_relic/agent/agent.rb +393 -204
- data/lib/new_relic/agent/error_collector.rb +113 -43
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +14 -16
- data/lib/new_relic/agent/instrumentation/queue_time.rb +201 -0
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sequel.rb +95 -0
- data/lib/new_relic/agent/method_tracer.rb +391 -313
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +43 -41
- data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +2 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +122 -120
- data/lib/new_relic/agent/samplers/object_sampler.rb +2 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +0 -1
- data/lib/new_relic/agent/stats_engine/samplers.rb +20 -14
- data/lib/new_relic/agent/stats_engine/transactions.rb +35 -7
- data/lib/new_relic/control.rb +12 -17
- data/lib/new_relic/control/configuration.rb +1 -0
- data/lib/new_relic/control/frameworks/rails.rb +7 -4
- data/lib/new_relic/control/frameworks/rails3.rb +1 -1
- data/lib/new_relic/control/instrumentation.rb +2 -18
- data/lib/new_relic/local_environment.rb +117 -59
- data/lib/new_relic/rack/developer_mode.rb +212 -207
- data/lib/new_relic/recipes.rb +0 -9
- data/lib/new_relic/stats.rb +87 -81
- data/lib/new_relic/transaction_analysis.rb +1 -1
- data/lib/new_relic/version.rb +2 -2
- data/lib/newrelic_rpm.rb +2 -3
- data/lib/tasks/tests.rake +5 -1
- data/newrelic_rpm.gemspec +14 -5
- data/test/config/test_control.rb +14 -2
- data/test/new_relic/agent/active_record_instrumentation_test.rb +342 -119
- data/test/new_relic/agent/add_method_tracer_test.rb +158 -0
- data/test/new_relic/agent/agent_connect_test.rb +295 -0
- data/test/new_relic/agent/agent_controller_test.rb +86 -18
- data/test/new_relic/agent/agent_start_test.rb +326 -0
- data/test/new_relic/agent/agent_start_worker_thread_test.rb +157 -0
- data/test/new_relic/agent/apdex_from_server_test.rb +9 -0
- data/test/new_relic/agent/collection_helper_test.rb +3 -1
- data/test/new_relic/agent/error_collector_notice_error_test.rb +255 -0
- data/test/new_relic/agent/error_collector_test.rb +6 -0
- data/test/new_relic/agent/method_tracer_test.rb +2 -2
- data/test/new_relic/agent/method_tracer_trace_execution_scoped_test.rb +233 -0
- data/test/new_relic/agent/net_instrumentation_test.rb +17 -12
- data/test/new_relic/agent/queue_time_test.rb +333 -0
- data/test/new_relic/agent/rpm_agent_test.rb +4 -2
- data/test/new_relic/agent/stats_engine/samplers_test.rb +27 -1
- data/test/new_relic/agent/transaction_sample_subtest_test.rb +56 -0
- data/test/new_relic/agent/transaction_sample_test.rb +103 -174
- data/test/new_relic/agent/transaction_sampler_test.rb +9 -2
- data/test/new_relic/control_test.rb +7 -2
- data/test/new_relic/metric_spec_test.rb +1 -1
- data/test/new_relic/stats_test.rb +112 -15
- data/test/test_helper.rb +79 -16
- data/ui/helpers/developer_mode_helper.rb +2 -0
- metadata +19 -7
- data/lib/new_relic_api.rb +0 -276
@@ -1,5 +1,5 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
-
|
2
|
+
require 'action_controller/test_case'
|
3
3
|
class AgentControllerTest < ActionController::TestCase
|
4
4
|
require 'action_controller/base'
|
5
5
|
require 'new_relic/agent/agent_test_controller'
|
@@ -22,8 +22,12 @@ class AgentControllerTest < ActionController::TestCase
|
|
22
22
|
ActionController::Routing::Routes.draw do | map |
|
23
23
|
map.connect '/:controller/:action.:format'
|
24
24
|
map.connect '/:controller/:action'
|
25
|
-
|
25
|
+
end
|
26
26
|
end
|
27
|
+
|
28
|
+
if defined?(Rails) && Rails.respond_to?(:application) && Rails.application.respond_to?(:routes)
|
29
|
+
@routes = Rails.application.routes
|
30
|
+
end
|
27
31
|
|
28
32
|
Thread.current[:newrelic_ignore_controller] = nil
|
29
33
|
NewRelic::Agent.manual_start
|
@@ -57,7 +61,6 @@ class AgentControllerTest < ActionController::TestCase
|
|
57
61
|
|
58
62
|
def test_heroku_queue
|
59
63
|
engine.clear_stats
|
60
|
-
NewRelic::Control.instance.local_env.stubs(:mongrel).returns( stub('mongrel', :workers => stub('workers', :list => stub('list', :length => '10'))))
|
61
64
|
NewRelic::Agent::AgentTestController.set_some_headers 'HTTP_X_HEROKU_QUEUE_DEPTH'=>'15'
|
62
65
|
get :index
|
63
66
|
assert_equal 1, stats('HttpDispatcher').call_count
|
@@ -65,6 +68,48 @@ class AgentControllerTest < ActionController::TestCase
|
|
65
68
|
assert_equal 15, engine.get_stats_no_scope('Mongrel/Queue Length').total_call_time
|
66
69
|
assert_equal 0, engine.get_stats_no_scope('WebFrontend/Mongrel/Average Queue Time').call_count
|
67
70
|
end
|
71
|
+
|
72
|
+
def test_new_queue_integration
|
73
|
+
engine.clear_stats
|
74
|
+
start = ((Time.now - 1).to_f * 1_000_000).to_i
|
75
|
+
NewRelic::Agent::AgentTestController.set_some_headers 'HTTP_X_QUEUE_START'=> "t=#{start}"
|
76
|
+
get :index
|
77
|
+
|
78
|
+
check_metric_time('WebFrontend/QueueTime', 1, 0.1)
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
def test_new_middleware_integration
|
83
|
+
engine.clear_stats
|
84
|
+
start = ((Time.now - 1).to_f * 1_000_000).to_i
|
85
|
+
NewRelic::Agent::AgentTestController.set_some_headers 'HTTP_X_MIDDLEWARE_START'=> "t=#{start}"
|
86
|
+
get :index
|
87
|
+
|
88
|
+
check_metric_time('Middleware/all', 1, 0.1)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_new_server_time_integration
|
92
|
+
engine.clear_stats
|
93
|
+
start = ((Time.now - 1).to_f * 1_000_000).to_i
|
94
|
+
NewRelic::Agent::AgentTestController.set_some_headers 'HTTP_X_REQUEST_START'=> "t=#{start}"
|
95
|
+
get :index
|
96
|
+
|
97
|
+
check_metric_time('WebFrontend/WebServer/all', 1, 0.1)
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_new_frontend_work_integration
|
101
|
+
engine.clear_stats
|
102
|
+
times = [Time.now - 3, Time.now - 2, Time.now - 1]
|
103
|
+
times.map! {|t| (t.to_f * 1_000_000).to_i }
|
104
|
+
NewRelic::Agent::AgentTestController.set_some_headers({
|
105
|
+
'HTTP_X_REQUEST_START'=> "t=#{times[0]}", 'HTTP_X_QUEUE_START' => "t=#{times[1]}", 'HTTP_X_MIDDLEWARE_START' => "t=#{times[2]}"})
|
106
|
+
get :index
|
107
|
+
|
108
|
+
|
109
|
+
check_metric_time('WebFrontend/WebServer/all', 1, 0.1)
|
110
|
+
check_metric_time('Middleware/all', 1, 0.1)
|
111
|
+
check_metric_time('WebFrontend/QueueTime', 1, 0.1)
|
112
|
+
end
|
68
113
|
|
69
114
|
def test_render_inline
|
70
115
|
engine.clear_stats
|
@@ -88,7 +133,10 @@ class AgentControllerTest < ActionController::TestCase
|
|
88
133
|
'Apdex/new_relic/agent/agent_test/action_with_error',
|
89
134
|
'HttpDispatcher',
|
90
135
|
'Controller/new_relic/agent/agent_test/action_with_error',
|
91
|
-
'Errors/all'
|
136
|
+
'Errors/all',
|
137
|
+
'Middleware/all',
|
138
|
+
'WebFrontend/WebServer/all',
|
139
|
+
'WebFrontend/QueueTime']
|
92
140
|
|
93
141
|
compare_metrics metrics, engine.metrics.reject{|m| m.index('Response')==0 || m.index('CPU')==0}
|
94
142
|
assert_equal 1, engine.get_stats_no_scope("Controller/new_relic/agent/agent_test/action_with_error").call_count
|
@@ -109,7 +157,10 @@ class AgentControllerTest < ActionController::TestCase
|
|
109
157
|
'Apdex/new_relic/agent/agent_test/action_with_error',
|
110
158
|
'HttpDispatcher',
|
111
159
|
'Controller/new_relic/agent/agent_test/action_with_error',
|
112
|
-
'Errors/all'
|
160
|
+
'Errors/all',
|
161
|
+
'WebFrontend/QueueTime',
|
162
|
+
'Middleware/all',
|
163
|
+
'WebFrontend/WebServer/all']
|
113
164
|
|
114
165
|
compare_metrics metrics, engine.metrics.reject{|m| m.index('Response')==0 || m.index('CPU')==0}
|
115
166
|
assert_equal 1, engine.get_stats_no_scope("Controller/new_relic/agent/agent_test/action_with_error").call_count
|
@@ -130,7 +181,10 @@ class AgentControllerTest < ActionController::TestCase
|
|
130
181
|
'Apdex/new_relic/agent/agent_test/action_with_before_filter_error',
|
131
182
|
'HttpDispatcher',
|
132
183
|
'Controller/new_relic/agent/agent_test/action_with_before_filter_error',
|
133
|
-
'Errors/all'
|
184
|
+
'Errors/all',
|
185
|
+
'WebFrontend/QueueTime',
|
186
|
+
'Middleware/all',
|
187
|
+
'WebFrontend/WebServer/all']
|
134
188
|
|
135
189
|
compare_metrics metrics, engine.metrics.reject{|m| m.index('Response')==0 || m.index('CPU')==0}
|
136
190
|
assert_equal 1, engine.get_stats_no_scope("Controller/new_relic/agent/agent_test/action_with_before_filter_error").call_count
|
@@ -220,7 +274,7 @@ class AgentControllerTest < ActionController::TestCase
|
|
220
274
|
assert_equal 1, stats('Instance/Busy').call_count
|
221
275
|
assert_equal 1, stats('HttpDispatcher').call_count
|
222
276
|
# We are probably busy about 99% of the time, but lets make sure it's at least 50
|
223
|
-
assert stats('Instance/Busy').total_call_time > 0.5, stats('Instance/Busy')
|
277
|
+
assert stats('Instance/Busy').total_call_time > 0.5, stats('Instance/Busy').inspect
|
224
278
|
assert_equal 0, stats('WebFrontend/Mongrel/Average Queue Time').call_count
|
225
279
|
end
|
226
280
|
|
@@ -233,47 +287,61 @@ class AgentControllerTest < ActionController::TestCase
|
|
233
287
|
assert_equal 1, bucket_stats.call_count
|
234
288
|
end
|
235
289
|
|
236
|
-
def
|
290
|
+
def test_queue_headers_no_header
|
237
291
|
engine.clear_stats
|
238
292
|
queue_length_stat = stats('Mongrel/Queue Length')
|
239
|
-
queue_time_stat = stats('WebFrontend/
|
293
|
+
queue_time_stat = stats('WebFrontend/QueueTime')
|
240
294
|
|
241
295
|
# no request start header
|
242
296
|
get 'index'
|
243
297
|
assert_equal 0, queue_length_stat.call_count
|
298
|
+
end
|
299
|
+
|
300
|
+
def test_queue_headers_apache
|
244
301
|
|
302
|
+
engine.clear_stats
|
303
|
+
queue_length_stat = stats('Mongrel/Queue Length')
|
304
|
+
queue_time_stat = stats('WebFrontend/QueueTime')
|
305
|
+
|
245
306
|
# apache version of header
|
246
|
-
request_start = ((Time.now.to_f - 0.
|
247
|
-
NewRelic::Agent::AgentTestController.set_some_headers({'
|
307
|
+
request_start = ((Time.now.to_f - 0.5) * 1e6).to_i.to_s
|
308
|
+
NewRelic::Agent::AgentTestController.set_some_headers({'HTTP_X_QUEUE_START' => "t=#{request_start}"})
|
248
309
|
get :index
|
249
310
|
assert_equal(0, queue_length_stat.call_count, 'We should not be seeing a queue length yet')
|
250
311
|
assert_equal(1, queue_time_stat.call_count, 'We should have seen the queue header once')
|
251
312
|
assert(queue_time_stat.total_call_time > 0.1, "Queue time should be longer than 100ms")
|
252
|
-
assert(queue_time_stat.total_call_time < 10, "Queue time should be under 10 seconds (sanity check)")
|
313
|
+
assert(queue_time_stat.total_call_time < 10, "Queue time should be under 10 seconds (sanity check)")
|
314
|
+
|
315
|
+
end
|
316
|
+
def test_queue_headers_heroku
|
253
317
|
|
254
318
|
engine.clear_stats
|
255
319
|
NewRelic::Agent::AgentTestController.clear_headers
|
256
320
|
|
257
321
|
queue_length_stat = stats('Mongrel/Queue Length')
|
258
|
-
queue_time_stat = stats('WebFrontend/
|
322
|
+
queue_time_stat = stats('WebFrontend/QueueTime')
|
259
323
|
|
260
324
|
# heroku version
|
261
|
-
request_start = ((Time.now.to_f - 0.
|
262
|
-
NewRelic::Agent::AgentTestController.set_some_headers({'
|
325
|
+
request_start = ((Time.now.to_f - 0.5) * 1e6).to_i.to_s
|
326
|
+
NewRelic::Agent::AgentTestController.set_some_headers({'HTTP_X_QUEUE_START' => "t=#{request_start}", 'HTTP_X_HEROKU_QUEUE_DEPTH' => '0'})
|
263
327
|
get :index
|
264
328
|
assert_equal(0, queue_length_stat.total_call_time, 'queue should be empty')
|
265
329
|
assert_equal(1, queue_time_stat.call_count, 'should have seen the queue header once')
|
266
330
|
assert(queue_time_stat.total_call_time > 0.1, "Queue time should be longer than 100ms")
|
267
331
|
assert(queue_time_stat.total_call_time < 10, "Queue time should be under 10 seconds (sanity check)")
|
332
|
+
end
|
333
|
+
|
334
|
+
def test_queue_headers_heroku_queue_length
|
335
|
+
|
268
336
|
engine.clear_stats
|
269
337
|
NewRelic::Agent::AgentTestController.clear_headers
|
270
338
|
|
271
339
|
queue_length_stat = stats('Mongrel/Queue Length')
|
272
|
-
queue_time_stat = stats('WebFrontend/
|
340
|
+
queue_time_stat = stats('WebFrontend/QueueTime')
|
273
341
|
|
274
342
|
# heroku version with queue length > 0
|
275
|
-
request_start = ((Time.now.to_f - 0.
|
276
|
-
NewRelic::Agent::AgentTestController.set_some_headers({'
|
343
|
+
request_start = ((Time.now.to_f - 0.5) * 1e6).to_i.to_s
|
344
|
+
NewRelic::Agent::AgentTestController.set_some_headers({'HTTP_X_QUEUE_START' => "t=#{request_start}", 'HTTP_X_HEROKU_QUEUE_DEPTH' => '3'})
|
277
345
|
get :index
|
278
346
|
|
279
347
|
assert_equal(1, queue_length_stat.call_count, 'queue should have been seen once')
|
@@ -0,0 +1,326 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
+
class NewRelic::Agent::AgentStartTest < Test::Unit::TestCase
|
3
|
+
require 'new_relic/agent/agent'
|
4
|
+
include NewRelic::Agent::Agent::Start
|
5
|
+
|
6
|
+
def test_already_started_positive
|
7
|
+
control = mocked_control
|
8
|
+
control.expects(:log!).with("Agent Started Already!", :error)
|
9
|
+
self.expects(:started?).returns(true)
|
10
|
+
assert already_started?, "should have already started"
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_already_started_negative
|
14
|
+
self.expects(:started?).returns(false)
|
15
|
+
assert !already_started?
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_disabled_positive
|
19
|
+
control = mocked_control
|
20
|
+
control.expects(:agent_enabled?).returns(false)
|
21
|
+
assert disabled?
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_disabled_negative
|
25
|
+
control = mocked_control
|
26
|
+
control.expects(:agent_enabled?).returns(true)
|
27
|
+
assert !disabled?
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_log_dispatcher_positive
|
31
|
+
control = mocked_control
|
32
|
+
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
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_log_dispatcher_negative
|
39
|
+
control = mocked_control
|
40
|
+
log = mocked_log
|
41
|
+
control.expects(:dispatcher).returns('')
|
42
|
+
log.expects(:info).with("No dispatcher detected.")
|
43
|
+
log_dispatcher
|
44
|
+
end
|
45
|
+
|
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
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_apdex_f
|
55
|
+
NewRelic::Control.instance.expects(:apdex_t).returns(10)
|
56
|
+
assert_equal 40, apdex_f
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_apdex_f_threshold_positive
|
60
|
+
self.expects(:sampler_config).returns({'transaction_threshold' => 'apdex_f'})
|
61
|
+
assert apdex_f_threshold?
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_apdex_f_threshold_negative
|
65
|
+
self.expects(:sampler_config).returns({'transaction_threshold' => 'WHEE'})
|
66
|
+
assert !apdex_f_threshold?
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_set_sql_recording_default
|
70
|
+
self.expects(:sampler_config).returns({})
|
71
|
+
self.expects(:log_sql_transmission_warning?)
|
72
|
+
set_sql_recording!
|
73
|
+
assert_equal :obfuscated, @record_sql, " should default to :obfuscated, was #{@record_sql}"
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_set_sql_recording_none
|
77
|
+
self.expects(:sampler_config).returns({'record_sql' => 'none'})
|
78
|
+
self.expects(:log_sql_transmission_warning?)
|
79
|
+
set_sql_recording!
|
80
|
+
assert_equal :none, @record_sql, "should be set to :none, was #{@record_sql}"
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_set_sql_recording_raw
|
84
|
+
self.expects(:sampler_config).returns({'record_sql' => 'raw'})
|
85
|
+
self.expects(:log_sql_transmission_warning?)
|
86
|
+
set_sql_recording!
|
87
|
+
assert_equal :raw, @record_sql, "should be set to :raw, was #{@record_sql}"
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_log_sql_transmission_warning_negative
|
91
|
+
log = mocked_log
|
92
|
+
@record_sql = :obfuscated
|
93
|
+
log.expects(:warn).never
|
94
|
+
log_sql_transmission_warning?
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_log_sql_transmission_warning_positive
|
98
|
+
log = mocked_log
|
99
|
+
@record_sql = :raw
|
100
|
+
log.expects(:send).with(:warn, 'Agent is configured to send raw SQL to RPM service')
|
101
|
+
log_sql_transmission_warning?
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_sampler_config
|
105
|
+
control = mocked_control
|
106
|
+
control.expects(:fetch).with('transaction_tracer', {})
|
107
|
+
sampler_config
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_config_transaction_tracer
|
111
|
+
fake_sampler_config = mock('sampler config')
|
112
|
+
self.expects(:sampler_config).times(5).returns(fake_sampler_config)
|
113
|
+
fake_sampler_config.expects(:fetch).with('enabled', true)
|
114
|
+
fake_sampler_config.expects(:fetch).with('random_sample', false)
|
115
|
+
fake_sampler_config.expects(:fetch).with('explain_threshold', 0.5)
|
116
|
+
fake_sampler_config.expects(:fetch).with('explain_enabled', true)
|
117
|
+
self.expects(:set_sql_recording!)
|
118
|
+
|
119
|
+
fake_sampler_config.expects(:fetch).with('transaction_threshold', 2.0)
|
120
|
+
self.expects(:apdex_f_threshold?).returns(true)
|
121
|
+
self.expects(:apdex_f)
|
122
|
+
config_transaction_tracer
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_check_config_and_start_agent_disabled
|
126
|
+
self.expects(:monitoring?).returns(false)
|
127
|
+
check_config_and_start_agent
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_check_config_and_start_agent_incorrect_key
|
131
|
+
self.expects(:monitoring?).returns(true)
|
132
|
+
self.expects(:has_correct_license_key?).returns(false)
|
133
|
+
check_config_and_start_agent
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_check_config_and_start_agent_forking
|
137
|
+
self.expects(:monitoring?).returns(true)
|
138
|
+
self.expects(:has_correct_license_key?).returns(true)
|
139
|
+
self.expects(:using_forking_dispatcher?).returns(true)
|
140
|
+
check_config_and_start_agent
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_check_config_and_start_agent_normal
|
144
|
+
self.expects(:monitoring?).returns(true)
|
145
|
+
self.expects(:has_correct_license_key?).returns(true)
|
146
|
+
self.expects(:using_forking_dispatcher?).returns(false)
|
147
|
+
control = mocked_control
|
148
|
+
control.expects(:sync_startup).returns(false)
|
149
|
+
self.expects(:start_worker_thread)
|
150
|
+
self.expects(:install_exit_handler)
|
151
|
+
check_config_and_start_agent
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_check_config_and_start_agent_sync
|
155
|
+
self.expects(:monitoring?).returns(true)
|
156
|
+
self.expects(:has_correct_license_key?).returns(true)
|
157
|
+
self.expects(:using_forking_dispatcher?).returns(false)
|
158
|
+
control = mocked_control
|
159
|
+
control.expects(:sync_startup).returns(true)
|
160
|
+
self.expects(:connect_in_foreground)
|
161
|
+
self.expects(:start_worker_thread)
|
162
|
+
self.expects(:install_exit_handler)
|
163
|
+
check_config_and_start_agent
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_connect_in_foreground
|
167
|
+
self.expects(:connect).with({:keep_retrying => false })
|
168
|
+
connect_in_foreground
|
169
|
+
end
|
170
|
+
|
171
|
+
def at_exit
|
172
|
+
yield
|
173
|
+
end
|
174
|
+
private :at_exit
|
175
|
+
|
176
|
+
def test_install_exit_handler_positive
|
177
|
+
control = mocked_control
|
178
|
+
control.expects(:send_data_on_exit).returns(true)
|
179
|
+
self.expects(:using_rubinius?).returns(false)
|
180
|
+
self.expects(:using_jruby?).returns(false)
|
181
|
+
self.expects(:using_sinatra?).returns(false)
|
182
|
+
# we are overriding at_exit above, to immediately return, so we can
|
183
|
+
# test the shutdown logic. It's somewhat unfortunate, but we can't
|
184
|
+
# kill the interpreter during a test.
|
185
|
+
self.expects(:shutdown)
|
186
|
+
install_exit_handler
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_install_exit_handler_negative
|
190
|
+
control = mocked_control
|
191
|
+
control.expects(:send_data_on_exit).returns(false)
|
192
|
+
install_exit_handler
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_install_exit_handler_weird_ruby
|
196
|
+
control = mocked_control
|
197
|
+
control.expects(:send_data_on_exit).times(3).returns(true)
|
198
|
+
self.expects(:using_rubinius?).returns(false)
|
199
|
+
self.expects(:using_jruby?).returns(false)
|
200
|
+
self.expects(:using_sinatra?).returns(true)
|
201
|
+
install_exit_handler
|
202
|
+
self.expects(:using_rubinius?).returns(false)
|
203
|
+
self.expects(:using_jruby?).returns(true)
|
204
|
+
install_exit_handler
|
205
|
+
self.expects(:using_rubinius?).returns(true)
|
206
|
+
install_exit_handler
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_notify_log_file_location_positive
|
210
|
+
log = mocked_log
|
211
|
+
NewRelic::Control.instance.expects(:log_file).returns('CHUD CHUD CHUD')
|
212
|
+
log.expects(:send).with(:info, "Agent Log found in CHUD CHUD CHUD")
|
213
|
+
notify_log_file_location
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_notify_log_file_location_negative
|
217
|
+
log = mocked_log
|
218
|
+
NewRelic::Control.instance.expects(:log_file).returns(nil)
|
219
|
+
notify_log_file_location
|
220
|
+
end
|
221
|
+
|
222
|
+
def test_monitoring_positive
|
223
|
+
control = mocked_control
|
224
|
+
control.expects(:monitor_mode?).returns(true)
|
225
|
+
log = mocked_log
|
226
|
+
assert monitoring?
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_monitoring_negative
|
230
|
+
control = mocked_control
|
231
|
+
log = mocked_log
|
232
|
+
control.expects(:monitor_mode?).returns(false)
|
233
|
+
log.expects(:send).with(:warn, "Agent configured not to send data in this environment - edit newrelic.yml to change this")
|
234
|
+
assert !monitoring?
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_has_license_key_positive
|
238
|
+
control = mocked_control
|
239
|
+
control.expects(:license_key).returns("a" * 40)
|
240
|
+
assert has_license_key?
|
241
|
+
end
|
242
|
+
|
243
|
+
def test_has_license_key_negative
|
244
|
+
control = mocked_control
|
245
|
+
control.expects(:license_key).returns(nil)
|
246
|
+
log = mocked_log
|
247
|
+
log.expects(:send).with(:error, 'No license key found. Please edit your newrelic.yml file and insert your license key.')
|
248
|
+
assert !has_license_key?
|
249
|
+
end
|
250
|
+
|
251
|
+
def test_has_correct_license_key_positive
|
252
|
+
self.expects(:has_license_key?).returns(true)
|
253
|
+
self.expects(:correct_license_length).returns(true)
|
254
|
+
assert has_correct_license_key?
|
255
|
+
end
|
256
|
+
|
257
|
+
def test_has_correct_license_key_negative
|
258
|
+
self.expects(:has_license_key?).returns(false)
|
259
|
+
assert !has_correct_license_key?
|
260
|
+
end
|
261
|
+
|
262
|
+
def test_correct_license_length_positive
|
263
|
+
control = mocked_control
|
264
|
+
control.expects(:license_key).returns("a" * 40)
|
265
|
+
assert correct_license_length
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_correct_license_length_negative
|
269
|
+
control = mocked_control
|
270
|
+
log = mocked_log
|
271
|
+
control.expects(:license_key).returns("a"*30)
|
272
|
+
log.expects(:send).with(:error, "Invalid license key: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
|
273
|
+
assert !correct_license_length
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_using_forking_dispatcher_positive
|
277
|
+
control = mocked_control
|
278
|
+
control.expects(:dispatcher).returns(:passenger)
|
279
|
+
log = mocked_log
|
280
|
+
log.expects(:send).with(:info, "Connecting workers after forking.")
|
281
|
+
assert using_forking_dispatcher?
|
282
|
+
end
|
283
|
+
|
284
|
+
def test_using_forking_dispatcher_negative
|
285
|
+
control = mocked_control
|
286
|
+
control.expects(:dispatcher).returns(:frobnitz)
|
287
|
+
assert !using_forking_dispatcher?
|
288
|
+
end
|
289
|
+
|
290
|
+
def test_log_unless_positive
|
291
|
+
# should not log
|
292
|
+
assert log_unless(true, :warn, "DURRR")
|
293
|
+
end
|
294
|
+
def test_log_unless_negative
|
295
|
+
# should log
|
296
|
+
log = mocked_log
|
297
|
+
log.expects(:send).with(:warn, "DURRR")
|
298
|
+
assert !log_unless(false, :warn, "DURRR")
|
299
|
+
end
|
300
|
+
|
301
|
+
def test_log_if_positive
|
302
|
+
log = mocked_log
|
303
|
+
log.expects(:send).with(:warn, "WHEE")
|
304
|
+
assert log_if(true, :warn, "WHEE")
|
305
|
+
end
|
306
|
+
|
307
|
+
def test_log_if_negative
|
308
|
+
assert !log_if(false, :warn, "WHEE")
|
309
|
+
end
|
310
|
+
|
311
|
+
private
|
312
|
+
|
313
|
+
def mocked_log
|
314
|
+
fake_log = mock('log')
|
315
|
+
self.stubs(:log).returns(fake_log)
|
316
|
+
fake_log
|
317
|
+
end
|
318
|
+
|
319
|
+
|
320
|
+
def mocked_control
|
321
|
+
fake_control = mock('control')
|
322
|
+
self.stubs(:control).returns(fake_control)
|
323
|
+
fake_control
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|