newrelic_rpm 3.6.0.83 → 3.6.1.85.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. data/CHANGELOG +27 -0
  2. data/Gemfile +2 -7
  3. data/README.md +1 -1
  4. data/lib/new_relic/agent/agent.rb +3 -2
  5. data/lib/new_relic/agent/autostart.rb +56 -0
  6. data/lib/new_relic/agent/browser_monitoring.rb +19 -14
  7. data/lib/new_relic/agent/configuration/defaults.rb +12 -2
  8. data/lib/new_relic/agent/configuration/environment_source.rb +4 -1
  9. data/lib/new_relic/agent/cross_app_monitor.rb +2 -1
  10. data/lib/new_relic/agent/cross_app_tracing.rb +19 -10
  11. data/lib/new_relic/agent/error_collector.rb +5 -4
  12. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +204 -0
  13. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +88 -0
  14. data/lib/new_relic/agent/instrumentation/active_record.rb +1 -1
  15. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +1 -1
  16. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +84 -0
  17. data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +3 -2
  18. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +104 -87
  19. data/lib/new_relic/agent/instrumentation/evented_subscriber.rb +91 -0
  20. data/lib/new_relic/agent/instrumentation/memcache.rb +4 -4
  21. data/lib/new_relic/agent/instrumentation/merb/errors.rb +4 -4
  22. data/lib/new_relic/agent/instrumentation/rack.rb +1 -1
  23. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +20 -20
  24. data/lib/new_relic/agent/instrumentation/rails/errors.rb +5 -5
  25. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +3 -3
  26. data/lib/new_relic/agent/instrumentation/rails4/action_controller.rb +3 -25
  27. data/lib/new_relic/agent/instrumentation/rails4/action_view.rb +2 -115
  28. data/lib/new_relic/agent/instrumentation/rails4/active_record.rb +2 -82
  29. data/lib/new_relic/agent/instrumentation/rails4/errors.rb +3 -4
  30. data/lib/new_relic/agent/method_tracer.rb +93 -56
  31. data/lib/new_relic/agent/null_logger.rb +6 -0
  32. data/lib/new_relic/agent/samplers/cpu_sampler.rb +9 -4
  33. data/lib/new_relic/agent/sql_sampler.rb +10 -6
  34. data/lib/new_relic/agent/stats_engine/metric_stats.rb +19 -3
  35. data/lib/new_relic/agent/stats_engine/transactions.rb +53 -34
  36. data/lib/new_relic/agent/system_info.rb +54 -0
  37. data/lib/new_relic/agent/thread.rb +2 -2
  38. data/lib/new_relic/agent/transaction/pop.rb +52 -0
  39. data/lib/new_relic/agent/transaction.rb +388 -0
  40. data/lib/new_relic/agent/transaction_info.rb +5 -13
  41. data/lib/new_relic/agent/transaction_sample_builder.rb +13 -20
  42. data/lib/new_relic/agent/transaction_sampler.rb +13 -15
  43. data/lib/new_relic/agent/uri_util.rb +35 -0
  44. data/lib/new_relic/agent.rb +54 -11
  45. data/lib/new_relic/build.rb +2 -2
  46. data/lib/new_relic/control/frameworks/rails.rb +0 -1
  47. data/lib/new_relic/control/frameworks/rails3.rb +2 -0
  48. data/lib/new_relic/control/frameworks/rails4.rb +0 -4
  49. data/lib/new_relic/control/instance_methods.rb +5 -19
  50. data/lib/new_relic/control/server_methods.rb +2 -0
  51. data/lib/new_relic/environment_report.rb +4 -34
  52. data/lib/new_relic/latest_changes.rb +1 -1
  53. data/lib/new_relic/local_environment.rb +0 -6
  54. data/lib/new_relic/metric_spec.rb +2 -2
  55. data/lib/new_relic/rack/error_collector.rb +6 -4
  56. data/lib/new_relic/transaction_sample.rb +7 -1
  57. data/lib/new_relic/version.rb +1 -1
  58. data/lib/newrelic_rpm.rb +2 -2
  59. data/newrelic.yml +20 -20
  60. data/test/config/test_control.rb +2 -2
  61. data/test/multiverse/suites/agent_only/audit_log_test.rb +1 -1
  62. data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +0 -2
  63. data/test/multiverse/suites/agent_only/logging_test.rb +1 -1
  64. data/test/multiverse/suites/agent_only/marshaling_test.rb +5 -3
  65. data/test/multiverse/suites/agent_only/rename_rule_test.rb +2 -0
  66. data/test/multiverse/suites/agent_only/set_transaction_name_test.rb +96 -0
  67. data/test/multiverse/suites/agent_only/testing_app.rb +1 -0
  68. data/test/multiverse/suites/rails/error_tracing_test.rb +17 -29
  69. data/test/multiverse/suites/rails/queue_time_test.rb +8 -2
  70. data/test/multiverse/suites/rails/view_instrumentation_test.rb +6 -3
  71. data/test/multiverse/suites/resque/instrumentation_test.rb +1 -1
  72. data/test/multiverse/suites/sinatra/sinatra_error_tracing_test.rb +8 -0
  73. data/test/new_relic/agent/agent/connect_test.rb +2 -1
  74. data/test/new_relic/agent/agent/start_test.rb +0 -10
  75. data/test/new_relic/agent/agent_logger_test.rb +15 -0
  76. data/test/new_relic/agent/agent_test_controller.rb +6 -2
  77. data/test/new_relic/agent/agent_test_controller_test.rb +20 -69
  78. data/test/new_relic/agent/autostart_test.rb +67 -0
  79. data/test/new_relic/agent/browser_monitoring_test.rb +60 -38
  80. data/test/new_relic/agent/configuration/environment_source_test.rb +19 -17
  81. data/test/new_relic/agent/cross_app_monitor_test.rb +8 -0
  82. data/test/new_relic/agent/error_collector/notice_error_test.rb +0 -5
  83. data/test/new_relic/agent/error_collector_test.rb +8 -9
  84. data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +228 -0
  85. data/test/new_relic/agent/instrumentation/action_view_subscriber_test.rb +18 -34
  86. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +5 -5
  87. data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +8 -9
  88. data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +1 -1
  89. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +24 -38
  90. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +126 -178
  91. data/test/new_relic/agent/instrumentation/rack_test.rb +1 -1
  92. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +135 -151
  93. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +153 -81
  94. data/test/new_relic/agent/method_tracer_test.rb +42 -33
  95. data/test/new_relic/agent/mock_scope_listener.rb +4 -4
  96. data/test/new_relic/agent/pipe_channel_manager_test.rb +4 -2
  97. data/test/new_relic/agent/rpm_agent_test.rb +86 -89
  98. data/test/new_relic/agent/sql_sampler_test.rb +18 -19
  99. data/test/new_relic/agent/stats_engine/gc_profiler_test.rb +5 -8
  100. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +20 -8
  101. data/test/new_relic/agent/stats_engine/samplers_test.rb +31 -14
  102. data/test/new_relic/agent/stats_engine_test.rb +53 -60
  103. data/test/new_relic/agent/thread_test.rb +7 -7
  104. data/test/new_relic/agent/transaction/pop_test.rb +96 -0
  105. data/test/new_relic/agent/transaction_info_test.rb +6 -17
  106. data/test/new_relic/agent/transaction_sample_builder_test.rb +10 -18
  107. data/test/new_relic/agent/transaction_sampler_test.rb +80 -75
  108. data/test/new_relic/agent/{instrumentation/metric_frame_test.rb → transaction_test.rb} +76 -42
  109. data/test/new_relic/agent/uri_util_test.rb +75 -0
  110. data/test/new_relic/agent_test.rb +115 -9
  111. data/test/test_helper.rb +138 -9
  112. data.tar.gz.sig +0 -0
  113. metadata +37 -74
  114. metadata.gz.sig +0 -0
  115. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +0 -84
  116. data/lib/new_relic/agent/instrumentation/metric_frame.rb +0 -353
  117. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +0 -175
  118. data/test/test_contexts.rb +0 -34
@@ -1,353 +0,0 @@
1
- # encoding: utf-8
2
- # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
-
5
- require 'new_relic/agent/instrumentation/metric_frame/pop'
6
-
7
- # A struct holding the information required to measure a controller
8
- # action. This is put on the thread local. Handles the issue of
9
- # re-entrancy, or nested action calls.
10
- #
11
- # This class is not part of the public API. Avoid making calls on it directly.
12
- #
13
- module NewRelic
14
- module Agent
15
- module Instrumentation
16
- class MetricFrame
17
- # helper module refactored out of the `pop` method
18
- include Pop
19
-
20
- attr_accessor :start # A Time instance for the start time, never nil
21
- attr_accessor :apdex_start # A Time instance used for calculating the apdex score, which
22
- # might end up being @start, or it might be further upstream if
23
- # we can find a request header for the queue entry time
24
- attr_accessor :exception,
25
- :filtered_params, :force_flag,
26
- :jruby_cpu_start, :process_cpu_start, :database_metric_name
27
-
28
- # Give the current metric frame a request context. Use this to
29
- # get the URI and referer. The request is interpreted loosely
30
- # as a Rack::Request or an ActionController::AbstractRequest.
31
- attr_accessor :request
32
-
33
-
34
- # Return the currently active metric frame, or nil. Call with +true+
35
- # to create a new metric frame if one is not already on the thread.
36
- def self.current(create_if_empty=nil)
37
- f = Thread.current[:newrelic_metric_frame]
38
- return f if f || !create_if_empty
39
- Thread.current[:newrelic_metric_frame] = new
40
- end
41
-
42
- # This is the name of the model currently assigned to database
43
- # measurements, overriding the default.
44
- def self.database_metric_name
45
- current && current.database_metric_name
46
- end
47
-
48
- def self.referer
49
- current && current.referer
50
- end
51
-
52
- def self.agent
53
- NewRelic::Agent.instance
54
- end
55
-
56
- @@java_classes_loaded = false
57
-
58
- if defined? JRuby
59
- begin
60
- require 'java'
61
- java_import 'java.lang.management.ManagementFactory'
62
- java_import 'com.sun.management.OperatingSystemMXBean'
63
- @@java_classes_loaded = true
64
- rescue => e
65
- end
66
- end
67
-
68
- attr_reader :depth
69
-
70
- def initialize
71
- @start = Time.now
72
- @path_stack = [] # stack of [controller, path] elements
73
- @jruby_cpu_start = jruby_cpu_time
74
- @process_cpu_start = process_cpu
75
- Thread.current[:last_metric_frame] = self
76
- end
77
-
78
- def agent
79
- NewRelic::Agent.instance
80
- end
81
-
82
- def transaction_sampler
83
- agent.transaction_sampler
84
- end
85
-
86
- def sql_sampler
87
- agent.sql_sampler
88
- end
89
-
90
- private :agent
91
- private :transaction_sampler
92
- private :sql_sampler
93
-
94
- # Indicate that we are entering a measured controller action or task.
95
- # Make sure you unwind every push with a pop call.
96
- def push(m)
97
- transaction_sampler.notice_first_scope_push(start)
98
- sql_sampler.notice_first_scope_push(start)
99
- @path_stack.push NewRelic::MetricParser::MetricParser.for_metric_named(m)
100
- end
101
-
102
- # Indicate that you don't want to keep the currently saved transaction
103
- # information
104
- def self.abort_transaction!
105
- current.abort_transaction! if current
106
- end
107
-
108
- # For the current web transaction, return the path of the URI minus the host part and query string, or nil.
109
- def uri
110
- @uri ||= self.class.uri_from_request(@request) unless @request.nil?
111
- end
112
-
113
- # For the current web transaction, return the full referer, minus the host string, or nil.
114
- def referer
115
- @referer ||= self.class.referer_from_request(@request)
116
- end
117
-
118
- # Call this to ensure that the current transaction is not saved
119
- def abort_transaction!
120
- transaction_sampler.ignore_transaction
121
- end
122
- # This needs to be called after entering the call to trace the
123
- # controller action, otherwise the controller action blames
124
- # itself. It gets reset in the normal #pop call.
125
- def start_transaction
126
- agent.stats_engine.start_transaction metric_name
127
- # Only push the transaction context info once, on entry:
128
- if @path_stack.size == 1
129
- transaction_sampler.notice_transaction(metric_name, uri, filtered_params)
130
- sql_sampler.notice_transaction(metric_name, uri, filtered_params)
131
- end
132
- end
133
-
134
- def current_metric
135
- @path_stack.last
136
- end
137
-
138
- # Return the path, the part of the metric after the category
139
- def path
140
- @path_stack.last.last
141
- end
142
-
143
- # Unwind one stack level. It knows if it's back at the outermost caller and
144
- # does the appropriate wrapup of the context.
145
- def pop
146
- metric = @path_stack.pop
147
- log_underflow if metric.nil?
148
- if @path_stack.empty?
149
- handle_empty_path_stack(metric)
150
- else
151
- set_new_scope!(current_stack_metric)
152
- end
153
- end
154
-
155
- # If we have an active metric frame, notice the error and increment the error metric.
156
- # Options:
157
- # * <tt>:request</tt> => Request object to get the uri and referer
158
- # * <tt>:uri</tt> => The request path, minus any request params or query string.
159
- # * <tt>:referer</tt> => The URI of the referer
160
- # * <tt>:metric</tt> => The metric name associated with the transaction
161
- # * <tt>:request_params</tt> => Request parameters, already filtered if necessary
162
- # * <tt>:custom_params</tt> => Custom parameters
163
- # Anything left over is treated as custom params
164
-
165
- def self.notice_error(e, options={})
166
- request = options.delete(:request)
167
- if request
168
- options[:referer] = referer_from_request(request)
169
- options[:uri] = uri_from_request(request)
170
- end
171
- if current
172
- current.notice_error(e, options)
173
- else
174
- agent.error_collector.notice_error(e, options)
175
- end
176
- end
177
-
178
- # Do not call this. Invoke the class method instead.
179
- def notice_error(e, options={}) # :nodoc:
180
- params = custom_parameters
181
- options[:referer] = referer if referer
182
- options[:request_params] = filtered_params if filtered_params
183
- options[:uri] = uri if uri
184
- options[:metric] = metric_name
185
- options.merge!(custom_parameters)
186
- if exception != e
187
- result = agent.error_collector.notice_error(e, options)
188
- self.exception = result if result
189
- end
190
- end
191
-
192
- # Add context parameters to the metric frame. This information will be passed in to errors
193
- # and transaction traces. Keys and Values should be strings, numbers or date/times.
194
- def self.add_custom_parameters(p)
195
- current.add_custom_parameters(p) if current
196
- end
197
-
198
- def self.custom_parameters
199
- (current && current.custom_parameters) ? current.custom_parameters : {}
200
- end
201
-
202
- def self.set_user_attributes(attributes)
203
- current.set_user_attributes(attributes) if current
204
- end
205
-
206
- def self.user_attributes
207
- (current) ? current.user_attributes : {}
208
- end
209
-
210
- def record_apdex()
211
- return unless recording_web_transaction? && NewRelic::Agent.is_execution_traced?
212
- t = Time.now
213
- self.class.record_apdex(current_metric, t - start, t - apdex_start, !exception.nil?)
214
- end
215
-
216
- def metric_name
217
- return nil if @path_stack.empty?
218
- current_metric.name
219
- end
220
-
221
- # Return the array of metrics to record for the current metric frame.
222
- def recorded_metrics
223
- metrics = [ metric_name ]
224
- metrics += current_metric.summary_metrics if @path_stack.size == 1
225
- metrics
226
- end
227
-
228
- # Yield to a block that is run with a database metric name context. This means
229
- # the Database instrumentation will use this for the metric name if it does not
230
- # otherwise know about a model. This is re-entrant.
231
- #
232
- # * <tt>model</tt> is the DB model class
233
- # * <tt>method</tt> is the name of the finder method or other method to identify the operation with.
234
- #
235
- def with_database_metric_name(model, method)
236
- previous = @database_metric_name
237
- model_name = case model
238
- when Class
239
- model.name
240
- when String
241
- model
242
- else
243
- model.to_s
244
- end
245
- @database_metric_name = "ActiveRecord/#{model_name}/#{method}"
246
- yield
247
- ensure
248
- @database_metric_name=previous
249
- end
250
-
251
- def custom_parameters
252
- @custom_parameters ||= {}
253
- end
254
-
255
- def user_attributes
256
- @user_atrributes ||= {}
257
- end
258
-
259
- def queue_time
260
- start - apdex_start
261
- end
262
-
263
- def add_custom_parameters(p)
264
- custom_parameters.merge!(p)
265
- end
266
-
267
- def set_user_attributes(attributes)
268
- user_attributes.merge!(attributes)
269
- end
270
-
271
- def self.recording_web_transaction?
272
- c = Thread.current[:newrelic_metric_frame]
273
- if c
274
- c.recording_web_transaction?
275
- end
276
- end
277
-
278
- def recording_web_transaction?
279
- current_metric && current_metric.is_web_transaction?
280
- end
281
-
282
- def is_web_transaction?(metric)
283
- 0 == metric.index("Controller")
284
- end
285
-
286
- # Make a safe attempt to get the referer from a request object, generally successful when
287
- # it's a Rack request.
288
- def self.referer_from_request(request)
289
- if request && request.respond_to?(:referer)
290
- request.referer.to_s.split('?').first
291
- end
292
- end
293
-
294
- # Make a safe attempt to get the URI, without the host and query string.
295
- def self.uri_from_request(request)
296
- approximate_uri = case
297
- when request.respond_to?(:fullpath) then request.fullpath
298
- when request.respond_to?(:path) then request.path
299
- when request.respond_to?(:request_uri) then request.request_uri
300
- when request.respond_to?(:uri) then request.uri
301
- when request.respond_to?(:url) then request.url
302
- end
303
- return approximate_uri[%r{^(https?://.*?)?(/[^?]*)}, 2] || '/' if approximate_uri # '
304
- end
305
-
306
- def self.record_apdex(current_metric, action_duration, total_duration, is_error)
307
- agent.stats_engine.record_metrics('Apdex') do |stat|
308
- update_apdex(stat, total_duration, is_error)
309
- end
310
- agent.stats_engine.record_metrics(current_metric.apdex_metric_path) do |stat|
311
- update_apdex(stat, action_duration, is_error)
312
- end
313
- end
314
-
315
- # Record an apdex value for the given stat. when `failed`
316
- # the apdex should be recorded as a failure regardless of duration.
317
- def self.update_apdex(stat, duration, failed)
318
- apdex_t = TransactionInfo.get.apdex_t
319
- duration = duration.to_f
320
- case
321
- when failed
322
- stat.record_apdex_f
323
- when duration <= apdex_t
324
- stat.record_apdex_s
325
- when duration <= 4 * apdex_t
326
- stat.record_apdex_t
327
- else
328
- stat.record_apdex_f
329
- end
330
- # Apdex min and max values should be initialized to the
331
- # current apdex_t
332
- stat.min_call_time = apdex_t
333
- stat.max_call_time = apdex_t
334
- end
335
-
336
- private
337
-
338
- def process_cpu
339
- return nil if defined? JRuby
340
- p = Process.times
341
- p.stime + p.utime
342
- end
343
-
344
- def jruby_cpu_time # :nodoc:
345
- return nil unless @@java_classes_loaded
346
- threadMBean = ManagementFactory.getThreadMXBean()
347
- java_utime = threadMBean.getCurrentThreadUserTime() # ns
348
- -1 == java_utime ? 0.0 : java_utime/1e9
349
- end
350
- end
351
- end
352
- end
353
- end
@@ -1,175 +0,0 @@
1
- # encoding: utf-8
2
- # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
-
5
- require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'test_helper'))
6
- require 'new_relic/agent/instrumentation/metric_frame/pop'
7
- class NewRelic::Agent::Instrumentation::MetricFrame::PopTest < Test::Unit::TestCase
8
- include NewRelic::Agent::Instrumentation::MetricFrame::Pop
9
-
10
- attr_reader :agent
11
- attr_reader :transaction_sampler
12
- attr_reader :sql_sampler
13
-
14
- def setup
15
- @agent = mock('agent')
16
- @transaction_sampler = mock('transaction sampler')
17
- @sql_sampler = mock('sql sampler')
18
- end
19
-
20
- def teardown
21
- Thread.current[:newrelic_metric_frame] = nil
22
- end
23
-
24
- def test_clear_thread_metric_frame
25
- Thread.current[:newrelic_metric_frame] = 'whee'
26
- clear_thread_metric_frame!
27
- assert_equal nil, Thread.current[:newrelic_metric_frame], 'should nil out the thread var'
28
- end
29
-
30
- def test_set_new_scope
31
- fakeagent = mock('agent')
32
- self.expects(:agent).returns(fakeagent)
33
- fakeengine = mock('stats_engine')
34
- fakeagent.expects(:stats_engine).returns(fakeengine)
35
- fakeengine.expects(:scope_name=).with('A METRIC')
36
-
37
- set_new_scope!('A METRIC')
38
- end
39
-
40
- def test_log_underflow
41
- expects_logging(:error, regexp_matches(/Underflow in metric frames: /))
42
- log_underflow
43
- end
44
-
45
- def test_notice_scope_empty
46
- transaction_sampler.expects(:notice_scope_empty)
47
- sql_sampler.expects(:notice_scope_empty)
48
- notice_scope_empty
49
- end
50
-
51
- def test_record_transaction_cpu_positive
52
- self.expects(:cpu_burn).once.returns(1.0)
53
- transaction_sampler.expects(:notice_transaction_cpu_time).with(1.0)
54
- record_transaction_cpu
55
- end
56
-
57
- def test_record_transaction_cpu_negative
58
- self.expects(:cpu_burn).once.returns(nil)
59
- # should not be called for the nil case
60
- transaction_sampler.expects(:notice_transaction_cpu_time).never
61
- record_transaction_cpu
62
- end
63
-
64
- def test_normal_cpu_burn_positive
65
- @process_cpu_start = 3
66
- self.expects(:process_cpu).returns(4)
67
- assert_equal 1, normal_cpu_burn
68
- end
69
-
70
- def test_normal_cpu_burn_negative
71
- @process_cpu_start = nil
72
- self.expects(:process_cpu).never
73
- assert_equal nil, normal_cpu_burn
74
- end
75
-
76
- def test_jruby_cpu_burn_positive
77
- @jruby_cpu_start = 3
78
- self.expects(:jruby_cpu_time).returns(4)
79
- self.expects(:record_jruby_cpu_burn).with(1)
80
- assert_equal 1, jruby_cpu_burn
81
- end
82
-
83
- def test_jruby_cpu_burn_negative
84
- @jruby_cpu_start = nil
85
- self.expects(:jruby_cpu_time).never
86
- self.expects(:record_jruby_cpu_burn).never
87
- assert_equal nil, jruby_cpu_burn
88
- end
89
-
90
- def test_record_jruby_cpu_burn
91
- NewRelic::Agent.get_stats_no_scope(NewRelic::Metrics::USER_TIME).expects(:record_data_point).with(1.0)
92
- record_jruby_cpu_burn(1.0)
93
- end
94
-
95
- def test_cpu_burn_normal
96
- self.expects(:normal_cpu_burn).returns(1)
97
- self.expects(:jruby_cpu_burn).never
98
- assert_equal 1, cpu_burn
99
- end
100
-
101
- def test_cpu_burn_jruby
102
- self.expects(:normal_cpu_burn).returns(nil)
103
- self.expects(:jruby_cpu_burn).returns(2)
104
- assert_equal 2, cpu_burn
105
- end
106
-
107
- def test_end_transaction
108
- fake_stats_engine = mock('stats engine')
109
- agent.expects(:stats_engine).returns(fake_stats_engine)
110
- fake_stats_engine.expects(:end_transaction)
111
- end_transaction!
112
- end
113
-
114
- def test_notify_transaction_sampler_true
115
- self.expects(:record_transaction_cpu)
116
- self.expects(:notice_scope_empty)
117
- notify_transaction_sampler(true)
118
- end
119
-
120
- def test_notify_transaction_sampler_false
121
- self.expects(:record_transaction_cpu)
122
- self.expects(:notice_scope_empty)
123
- notify_transaction_sampler(false)
124
- end
125
-
126
- def test_traced
127
- NewRelic::Agent.expects(:is_execution_traced?)
128
- traced?
129
- end
130
-
131
- def test_handle_empty_path_stack_default
132
- @path_stack = [] # it is empty
133
- self.expects(:traced?).returns(true)
134
- fakemetric = mock('metric')
135
- fakemetric.expects(:is_web_transaction?).returns(true)
136
- self.expects(:notify_transaction_sampler).with(true)
137
- self.expects(:end_transaction!)
138
- self.expects(:clear_thread_metric_frame!)
139
- handle_empty_path_stack(fakemetric)
140
- end
141
-
142
- def test_handle_empty_path_stack_non_web
143
- @path_stack = [] # it is empty
144
- self.expects(:traced?).returns(true)
145
- fakemetric = mock('metric')
146
- fakemetric.expects(:is_web_transaction?).returns(false)
147
- self.expects(:notify_transaction_sampler).with(false)
148
- self.expects(:end_transaction!)
149
- self.expects(:clear_thread_metric_frame!)
150
- handle_empty_path_stack(fakemetric)
151
- end
152
-
153
- def test_handle_empty_path_stack_error
154
- @path_stack = ['not empty']
155
- assert_raise(RuntimeError) do
156
- handle_empty_path_stack(mock('metric'))
157
- end
158
- end
159
-
160
- def test_handle_empty_path_stack_untraced
161
- @path_stack = [] # it is empty
162
- self.expects(:traced?).returns(false)
163
- fakemetric = mock('metric')
164
- fakemetric.expects(:is_web_transaction?).never
165
- self.expects(:end_transaction!)
166
- self.expects(:clear_thread_metric_frame!)
167
- handle_empty_path_stack(fakemetric)
168
- end
169
-
170
- def test_current_stack_metric
171
- self.expects(:metric_name)
172
- current_stack_metric
173
- end
174
- end
175
-
@@ -1,34 +0,0 @@
1
- # encoding: utf-8
2
- # This file is distributed under New Relic's license terms.
3
- # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
-
5
-
6
- module TestContexts
7
- def with_running_agent
8
-
9
- context 'with running agent' do # this is needed for the nested setups
10
-
11
- setup do
12
- @log_data = StringIO.new
13
- @log = Logger.new(@log_data)
14
- NewRelic::Agent::Agent.instance.service = default_service
15
- NewRelic::Agent.manual_start :log => @log
16
- @agent = NewRelic::Agent.instance
17
- @agent.transaction_sampler.send :clear_builder
18
- @agent.transaction_sampler.reset!
19
- @agent.stats_engine.clear_stats
20
- end
21
-
22
- yield
23
-
24
- def teardown
25
- super
26
- NewRelic::Agent.shutdown
27
- @log_data.reset
28
- NewRelic::Control.instance['dispatcher']=nil
29
- NewRelic::Control.instance['dispatcher_instance_id']=nil
30
- end
31
-
32
- end
33
- end
34
- end