newrelic_rpm 3.6.6.147 → 3.6.7.152

Sign up to get free protection for your applications and to get access to all the features.
Files changed (265) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.gitignore +0 -1
  3. data/CHANGELOG +55 -17
  4. data/Guardfile +7 -0
  5. data/Rakefile +6 -0
  6. data/bin/mongrel_rpm +33 -0
  7. data/bin/newrelic +13 -0
  8. data/bin/newrelic_cmd +5 -0
  9. data/bin/nrdebug +273 -0
  10. data/install.rb +3 -3
  11. data/lib/new_relic/agent.rb +4 -6
  12. data/lib/new_relic/agent/agent.rb +76 -72
  13. data/lib/new_relic/agent/autostart.rb +18 -5
  14. data/lib/new_relic/agent/browser_monitoring.rb +41 -35
  15. data/lib/new_relic/agent/browser_token.rb +38 -0
  16. data/lib/new_relic/agent/busy_calculator.rb +7 -5
  17. data/lib/new_relic/agent/commands/agent_command.rb +19 -0
  18. data/lib/new_relic/agent/commands/agent_command_router.rb +88 -0
  19. data/lib/new_relic/agent/commands/thread_profiler.rb +80 -0
  20. data/lib/new_relic/agent/configuration/default_source.rb +700 -0
  21. data/lib/new_relic/agent/configuration/environment_source.rb +83 -30
  22. data/lib/new_relic/agent/configuration/manager.rb +8 -8
  23. data/lib/new_relic/agent/configuration/mask_defaults.rb +2 -2
  24. data/lib/new_relic/agent/cross_app_monitor.rb +10 -21
  25. data/lib/new_relic/agent/cross_app_tracing.rb +3 -3
  26. data/lib/new_relic/agent/error_collector.rb +7 -10
  27. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +1 -1
  28. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +5 -1
  29. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +5 -1
  30. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +5 -1
  31. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +1 -1
  32. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +5 -12
  33. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +4 -0
  34. data/lib/new_relic/agent/instrumentation/{rails4/active_record.rb → active_record_4.rb} +1 -1
  35. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +11 -11
  36. data/lib/new_relic/agent/instrumentation/authlogic.rb +8 -6
  37. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +12 -6
  38. data/lib/new_relic/agent/instrumentation/curb.rb +11 -2
  39. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -3
  40. data/lib/new_relic/agent/instrumentation/evented_subscriber.rb +11 -2
  41. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +13 -4
  42. data/lib/new_relic/agent/instrumentation/puma.rb +2 -1
  43. data/lib/new_relic/agent/instrumentation/rack.rb +15 -17
  44. data/lib/new_relic/agent/method_tracer.rb +181 -191
  45. data/lib/new_relic/agent/new_relic_service.rb +16 -14
  46. data/lib/new_relic/agent/pipe_channel_manager.rb +1 -1
  47. data/lib/new_relic/agent/request_sampler.rb +32 -165
  48. data/lib/new_relic/agent/sampled_buffer.rb +79 -0
  49. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +1 -8
  50. data/lib/new_relic/agent/sql_sampler.rb +3 -3
  51. data/lib/new_relic/agent/stats_engine.rb +1 -1
  52. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -1
  53. data/lib/new_relic/agent/stats_engine/metric_stats.rb +2 -3
  54. data/lib/new_relic/agent/stats_engine/transactions.rb +2 -22
  55. data/lib/new_relic/agent/threading/agent_thread.rb +41 -0
  56. data/lib/new_relic/agent/threading/backtrace_node.rb +71 -0
  57. data/lib/new_relic/agent/threading/thread_profile.rb +172 -0
  58. data/lib/new_relic/agent/transaction.rb +16 -4
  59. data/lib/new_relic/agent/transaction_sample_builder.rb +13 -3
  60. data/lib/new_relic/agent/transaction_sampler.rb +5 -8
  61. data/lib/new_relic/agent/transaction_state.rb +166 -0
  62. data/lib/new_relic/agent/transaction_timings.rb +53 -0
  63. data/lib/new_relic/cli/command.rb +91 -0
  64. data/lib/new_relic/{commands → cli}/deployments.rb +13 -9
  65. data/lib/new_relic/{commands → cli}/install.rb +2 -2
  66. data/lib/new_relic/control/frameworks/rails.rb +1 -8
  67. data/lib/new_relic/control/instance_methods.rb +1 -2
  68. data/lib/new_relic/helper.rb +9 -0
  69. data/lib/new_relic/local_environment.rb +16 -63
  70. data/lib/new_relic/rack/browser_monitoring.rb +8 -5
  71. data/lib/new_relic/recipes.rb +44 -31
  72. data/lib/new_relic/transaction_sample.rb +6 -2
  73. data/lib/new_relic/version.rb +1 -1
  74. data/lib/tasks/install.rake +21 -1
  75. data/newrelic_rpm.gemspec +5 -1
  76. data/test/agent_helper.rb +4 -9
  77. data/test/environments/.gitignore +16 -0
  78. data/test/environments/lib/environments/runner.rb +104 -0
  79. data/test/environments/norails/Gemfile +11 -0
  80. data/test/environments/norails/Rakefile +9 -0
  81. data/test/environments/rails21/Gemfile +24 -0
  82. data/test/environments/rails21/Rakefile +12 -0
  83. data/test/environments/rails21/app/controllers/application.rb +20 -0
  84. data/test/environments/rails21/config/boot.rb +113 -0
  85. data/test/environments/rails21/config/database.yml +31 -0
  86. data/test/environments/rails21/config/environment.rb +28 -0
  87. data/test/environments/rails21/config/environments/development.rb +16 -0
  88. data/test/environments/rails21/config/environments/production.rb +8 -0
  89. data/test/environments/rails21/config/environments/test.rb +10 -0
  90. data/test/environments/rails21/config/routes.rb +5 -0
  91. data/test/environments/rails21/db/schema.rb +5 -0
  92. data/test/environments/rails22/Gemfile +29 -0
  93. data/test/environments/rails22/Rakefile +12 -0
  94. data/test/environments/rails22/app/controllers/application.rb +20 -0
  95. data/test/environments/rails22/config/boot.rb +113 -0
  96. data/test/environments/rails22/config/database.yml +31 -0
  97. data/test/environments/rails22/config/environment.rb +27 -0
  98. data/test/environments/rails22/config/environments/development.rb +16 -0
  99. data/test/environments/rails22/config/environments/production.rb +8 -0
  100. data/test/environments/rails22/config/environments/test.rb +10 -0
  101. data/test/environments/rails22/config/routes.rb +5 -0
  102. data/test/environments/rails22/db/schema.rb +5 -0
  103. data/test/environments/rails23/Gemfile +22 -0
  104. data/test/environments/rails23/Rakefile +12 -0
  105. data/test/environments/rails23/app/controllers/application.rb +20 -0
  106. data/test/environments/rails23/config/boot.rb +127 -0
  107. data/test/environments/rails23/config/database.yml +31 -0
  108. data/test/environments/rails23/config/environment.rb +25 -0
  109. data/test/environments/rails23/config/environments/development.rb +16 -0
  110. data/test/environments/rails23/config/environments/production.rb +8 -0
  111. data/test/environments/rails23/config/environments/test.rb +10 -0
  112. data/test/environments/rails23/config/preinitializer.rb +25 -0
  113. data/test/environments/rails23/config/routes.rb +5 -0
  114. data/test/environments/rails23/db/schema.rb +5 -0
  115. data/test/environments/rails30/Gemfile +19 -0
  116. data/test/environments/rails30/Rakefile +9 -0
  117. data/test/environments/rails30/config/application.rb +17 -0
  118. data/test/environments/rails30/config/boot.rb +10 -0
  119. data/test/environments/rails30/config/database.yml +31 -0
  120. data/test/environments/rails30/config/environment.rb +6 -0
  121. data/test/environments/rails30/config/initializers/new_rails_defaults.rb +11 -0
  122. data/test/environments/rails30/db/schema.rb +5 -0
  123. data/test/environments/rails31/Gemfile +19 -0
  124. data/test/environments/rails31/Rakefile +9 -0
  125. data/test/environments/rails31/config/application.rb +18 -0
  126. data/test/environments/rails31/config/boot.rb +10 -0
  127. data/test/environments/rails31/config/database.yml +31 -0
  128. data/test/environments/rails31/config/environment.rb +6 -0
  129. data/test/environments/rails31/config/initializers/new_rails_defaults.rb +21 -0
  130. data/test/environments/rails31/db/schema.rb +5 -0
  131. data/test/environments/rails32/Gemfile +25 -0
  132. data/test/environments/rails32/Rakefile +9 -0
  133. data/test/environments/rails32/config/application.rb +19 -0
  134. data/test/environments/rails32/config/boot.rb +10 -0
  135. data/test/environments/rails32/config/database.yml +31 -0
  136. data/test/environments/rails32/config/environment.rb +6 -0
  137. data/test/environments/rails32/db/schema.rb +5 -0
  138. data/test/environments/rails40/Gemfile +25 -0
  139. data/test/environments/rails40/Rakefile +9 -0
  140. data/test/environments/rails40/config/application.rb +18 -0
  141. data/test/environments/rails40/config/boot.rb +10 -0
  142. data/test/environments/rails40/config/database.yml +31 -0
  143. data/test/environments/rails40/config/environment.rb +6 -0
  144. data/test/environments/rails40/db/schema.rb +5 -0
  145. data/test/multiverse/lib/multiverse/suite.rb +24 -12
  146. data/test/multiverse/suites/agent_only/logging_test.rb +18 -1
  147. data/test/multiverse/suites/agent_only/rum_instrumentation_test.rb +1 -8
  148. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +10 -7
  149. data/test/multiverse/suites/curb/curb_test.rb +17 -3
  150. data/test/multiverse/suites/excon/Envfile +1 -1
  151. data/test/multiverse/suites/excon/excon_test.rb +18 -2
  152. data/test/multiverse/suites/httpclient/httpclient_test.rb +2 -2
  153. data/test/multiverse/suites/net_http/net_http_test.rb +2 -2
  154. data/test/multiverse/suites/rails/error_tracing_test.rb +35 -8
  155. data/test/multiverse/suites/rails/ignore_test.rb +48 -0
  156. data/test/multiverse/suites/rails/mongrel_queue_depth_test.rb +44 -0
  157. data/test/multiverse/suites/sequel/sequel_test.rb +11 -0
  158. data/test/multiverse/suites/sinatra/ignoring_test.rb +2 -2
  159. data/test/multiverse/suites/typhoeus/Envfile +9 -2
  160. data/test/multiverse/suites/typhoeus/typhoeus_test.rb +3 -2
  161. data/test/new_relic/agent/agent/start_test.rb +3 -22
  162. data/test/new_relic/agent/agent_test.rb +6 -5
  163. data/test/new_relic/agent/autostart_test.rb +39 -1
  164. data/test/new_relic/agent/browser_monitoring_test.rb +43 -88
  165. data/test/new_relic/agent/browser_token_test.rb +52 -0
  166. data/test/new_relic/agent/busy_calculator_test.rb +1 -1
  167. data/test/new_relic/agent/commands/agent_command_router_test.rb +98 -0
  168. data/test/new_relic/agent/commands/agent_command_test.rb +37 -0
  169. data/test/new_relic/agent/commands/thread_profiler_test.rb +177 -0
  170. data/test/new_relic/agent/configuration/default_source_test.rb +81 -0
  171. data/test/new_relic/agent/configuration/environment_source_test.rb +81 -7
  172. data/test/new_relic/agent/configuration/manager_test.rb +16 -1
  173. data/test/new_relic/agent/cross_app_monitor_test.rb +3 -5
  174. data/test/new_relic/agent/error_collector_test.rb +14 -0
  175. data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +1 -1
  176. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +2 -3
  177. data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +29 -31
  178. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +22 -0
  179. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +2 -2
  180. data/test/new_relic/agent/method_tracer_test.rb +2 -2
  181. data/test/new_relic/agent/new_relic_service_test.rb +5 -49
  182. data/test/new_relic/agent/pipe_channel_manager_test.rb +1 -0
  183. data/test/new_relic/agent/request_sampler_test.rb +32 -95
  184. data/test/new_relic/agent/rpm_agent_test.rb +7 -5
  185. data/test/new_relic/agent/sampled_buffer_test.rb +178 -0
  186. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +0 -1
  187. data/test/new_relic/agent/stats_engine_test.rb +10 -17
  188. data/test/new_relic/agent/threading/agent_thread_test.rb +107 -0
  189. data/test/new_relic/agent/threading/backtrace_node_test.rb +96 -0
  190. data/test/new_relic/agent/{threaded_test.rb → threading/fake_thread.rb} +0 -25
  191. data/test/new_relic/agent/threading/thread_profile_test.rb +308 -0
  192. data/test/new_relic/agent/threading/threaded_test_case.rb +33 -0
  193. data/test/new_relic/agent/transaction/pop_test.rb +0 -16
  194. data/test/new_relic/agent/transaction_sample_builder_test.rb +23 -4
  195. data/test/new_relic/agent/transaction_sampler_test.rb +14 -15
  196. data/test/new_relic/agent/transaction_state_test.rb +75 -0
  197. data/test/new_relic/agent/transaction_test.rb +15 -0
  198. data/test/new_relic/agent/transaction_timings_test.rb +81 -0
  199. data/test/new_relic/agent_test.rb +12 -14
  200. data/test/new_relic/{command → cli}/deployments_test.rb +41 -13
  201. data/test/new_relic/control/frameworks/rails_test.rb +1 -2
  202. data/test/new_relic/control_test.rb +1 -2
  203. data/test/new_relic/dependency_detection_test.rb +14 -0
  204. data/test/new_relic/fake_collector.rb +1 -0
  205. data/test/new_relic/helper_test.rb +7 -2
  206. data/test/new_relic/http_client_test_cases.rb +33 -1
  207. data/test/new_relic/local_environment_test.rb +0 -23
  208. data/test/new_relic/metric_data_test.rb +4 -0
  209. data/test/new_relic/rack/browser_monitoring_test.rb +31 -30
  210. data/test/performance/lib/performance/result.rb +15 -4
  211. data/test/performance/lib/performance/timer.rb +7 -1
  212. data/test/performance/script/baselines +102 -0
  213. data/test/performance/suites/rum_autoinsertion.rb +57 -0
  214. data/test/rum/basic.result.html +10 -0
  215. data/test/rum/basic.source.html +10 -0
  216. data/test/rum/comments1.result.html +24 -0
  217. data/test/rum/comments1.source.html +24 -0
  218. data/test/rum/comments2.result.html +24 -0
  219. data/test/rum/comments2.source.html +24 -0
  220. data/test/rum/gt_in_quotes1.result.html +27 -0
  221. data/test/rum/gt_in_quotes1.source.html +27 -0
  222. data/test/rum/gt_in_quotes2.result.html +24 -0
  223. data/test/rum/gt_in_quotes2.source.html +24 -0
  224. data/test/rum/gt_in_quotes_mismatch.result.html +24 -0
  225. data/test/rum/gt_in_quotes_mismatch.source.html +24 -0
  226. data/test/rum/gt_in_single_quotes1.result.html +25 -0
  227. data/test/rum/gt_in_single_quotes1.source.html +25 -0
  228. data/test/rum/gt_in_single_quotes_mismatch.result.html +25 -0
  229. data/test/rum/gt_in_single_quotes_mismatch.source.html +25 -0
  230. data/test/rum/incomplete_non_meta_tags.result.html +10 -0
  231. data/test/rum/incomplete_non_meta_tags.source.html +10 -0
  232. data/test/rum/no_body.result.html +21 -0
  233. data/test/rum/no_body.source.html +21 -0
  234. data/test/rum/no_header.result.html +7 -0
  235. data/test/rum/no_header.source.html +7 -0
  236. data/test/rum/no_start_header.result.html +9 -0
  237. data/test/rum/no_start_header.source.html +9 -0
  238. data/test/rum/script1.result.html +19 -0
  239. data/test/rum/script1.source.html +19 -0
  240. data/test/rum/script2.result.html +17 -0
  241. data/test/rum/script2.source.html +17 -0
  242. data/test/rum/x_ua_meta_tag.result.html +10 -0
  243. data/test/rum/x_ua_meta_tag.source.html +10 -0
  244. data/test/rum/x_ua_meta_tag_multiline.result.html +11 -0
  245. data/test/rum/x_ua_meta_tag_multiline.source.html +11 -0
  246. data/test/rum/x_ua_meta_tag_with_others.result.html +11 -0
  247. data/test/rum/x_ua_meta_tag_with_others.source.html +11 -0
  248. data/test/rum/x_ua_meta_tag_with_spaces.result.html +10 -0
  249. data/test/rum/x_ua_meta_tag_with_spaces.source.html +10 -0
  250. data/test/script/ci.sh +1 -12
  251. data/test/test_helper.rb +1 -0
  252. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +11 -0
  253. metadata +225 -32
  254. metadata.gz.sig +0 -0
  255. data/lib/new_relic/agent/configuration/defaults.rb +0 -157
  256. data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +0 -56
  257. data/lib/new_relic/agent/thread.rb +0 -37
  258. data/lib/new_relic/agent/thread_profiler.rb +0 -323
  259. data/lib/new_relic/agent/transaction_info.rb +0 -114
  260. data/lib/new_relic/command.rb +0 -89
  261. data/test/new_relic/agent/agent_test_controller_test.rb +0 -348
  262. data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +0 -70
  263. data/test/new_relic/agent/thread_profiler_test.rb +0 -586
  264. data/test/new_relic/agent/thread_test.rb +0 -93
  265. data/test/new_relic/agent/transaction_info_test.rb +0 -99
@@ -0,0 +1,33 @@
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/threading/fake_thread'
6
+
7
+ class ThreadedTestCase < Test::Unit::TestCase
8
+ def setup
9
+ @original_thread_class = NewRelic::Agent::Threading::AgentThread
10
+ swap_thread_class(FakeThread)
11
+ end
12
+
13
+ def teardown
14
+ swap_thread_class(@original_thread_class)
15
+ @original_thread_class = nil
16
+
17
+ FakeThread.list.clear
18
+ end
19
+
20
+ def default_test
21
+ # no-op to keep quiet....
22
+ end
23
+
24
+ private
25
+
26
+ def swap_thread_class(klass)
27
+ if NewRelic::Agent::Threading.const_defined?("AgentThread")
28
+ NewRelic::Agent::Threading.send(:remove_const, "AgentThread")
29
+ end
30
+ NewRelic::Agent::Threading.const_set("AgentThread", klass)
31
+ end
32
+ end
33
+
@@ -18,10 +18,6 @@ class NewRelic::Agent::Transaction::PopTest < Test::Unit::TestCase
18
18
  @sql_sampler = mock('sql sampler')
19
19
  end
20
20
 
21
- def teardown
22
- Thread.current[:newrelic_transaction] = nil
23
- end
24
-
25
21
  def test_log_underflow
26
22
  expects_logging(:error, regexp_matches(/Underflow in transaction: /))
27
23
  log_underflow
@@ -52,13 +48,6 @@ class NewRelic::Agent::Transaction::PopTest < Test::Unit::TestCase
52
48
  assert_equal nil, normal_cpu_burn
53
49
  end
54
50
 
55
- # def test_jruby_cpu_burn_positive
56
- # @jruby_cpu_start = 3
57
- # self.expects(:jruby_cpu_time).returns(4)
58
- # self.expects(:record_jruby_cpu_burn).with(1)
59
- # assert_equal 1, jruby_cpu_burn
60
- # end
61
-
62
51
  def test_jruby_cpu_burn_negative
63
52
  @jruby_cpu_start = nil
64
53
  self.expects(:jruby_cpu_time).never
@@ -83,11 +72,6 @@ class NewRelic::Agent::Transaction::PopTest < Test::Unit::TestCase
83
72
  assert_equal 2, cpu_burn
84
73
  end
85
74
 
86
- def test_traced
87
- NewRelic::Agent.expects(:is_execution_traced?)
88
- traced?
89
- end
90
-
91
75
  def test_current_stack_metric
92
76
  self.expects(:metric_name)
93
77
  current_stack_metric
@@ -220,10 +220,10 @@ class NewRelic::Agent::TransationSampleBuilderTest < Test::Unit::TestCase
220
220
  end
221
221
 
222
222
  def test_finish_trace_records_threshold
223
- NewRelic::Agent::TransactionInfo.get.stubs(:transaction_trace_threshold) \
224
- .returns(2.0)
225
- @builder.finish_trace
226
- assert_equal 2.0, @builder.sample.threshold
223
+ with_config(:'transaction_tracer.transaction_threshold' => 2.0) do
224
+ @builder.finish_trace
225
+ assert_equal 2.0, @builder.sample.threshold
226
+ end
227
227
  end
228
228
 
229
229
  # regression
@@ -234,6 +234,25 @@ class NewRelic::Agent::TransationSampleBuilderTest < Test::Unit::TestCase
234
234
  end
235
235
  end
236
236
 
237
+ def test_has_correct_transaction_trace_threshold_when_default
238
+ NewRelic::Agent::TransactionState.get.transaction = stub()
239
+ NewRelic::Agent::TransactionState.get.transaction.stubs(:apdex_t).returns(1.5)
240
+ assert_equal 6.0, @builder.transaction_trace_threshold
241
+
242
+ NewRelic::Agent::TransactionState.get.transaction.stubs(:apdex_t).returns(2.0)
243
+ assert_equal 8.0, @builder.transaction_trace_threshold
244
+ end
245
+
246
+ def test_has_correct_transaction_trace_threshold_when_explicitly_specified
247
+ config = { :'transaction_tracer.transaction_threshold' => 4.0 }
248
+
249
+ with_config(config, :do_not_cast => true) do
250
+ NewRelic::Agent::TransactionState.get.transaction = stub()
251
+ NewRelic::Agent::TransactionState.get.transaction.stubs(:apdex_t).returns(1.5)
252
+ assert_equal 4.0, @builder.transaction_trace_threshold
253
+ end
254
+ end
255
+
237
256
  def validate_builder(check_names = true)
238
257
  validate_segment @builder.sample.root_segment, check_names
239
258
  end
@@ -25,7 +25,7 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
25
25
  end
26
26
 
27
27
  def setup
28
- Thread::current[:record_sql] = nil
28
+ NewRelic::Agent::TransactionState.clear
29
29
  agent = NewRelic::Agent.instance
30
30
  stats_engine = NewRelic::Agent::StatsEngine.new
31
31
  agent.stubs(:stats_engine).returns(stats_engine)
@@ -40,7 +40,7 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
40
40
 
41
41
  def teardown
42
42
  super
43
- Thread.current[:transaction_sample_builder] = nil
43
+ NewRelic::Agent::TransactionState.clear
44
44
  NewRelic::Agent.config.remove_config(@test_config)
45
45
  NewRelic::Agent.instance.instance_variable_set(:@transaction_sampler, @old_sampler)
46
46
  end
@@ -420,13 +420,13 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
420
420
  end
421
421
 
422
422
  def test_notice_sql_recording_sql
423
- Thread.current[:record_sql] = true
423
+ NewRelic::Agent::TransactionState.get.record_sql = true
424
424
  @sampler.expects(:notice_extra_data).with('some sql', 1.0, :sql)
425
425
  @sampler.notice_sql('some sql', {:config => 'a config'}, 1.0)
426
426
  end
427
427
 
428
428
  def test_notice_sql_not_recording
429
- Thread.current[:record_sql] = false
429
+ NewRelic::Agent::TransactionState.get.record_sql = false
430
430
  @sampler.expects(:notice_extra_data).with('some sql', 1.0, :sql).never # <--- important
431
431
  @sampler.notice_sql('some sql', {:config => 'a config'}, 1.0)
432
432
  end
@@ -597,42 +597,41 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
597
597
  end
598
598
 
599
599
  def test_start_builder_default
600
- Thread.current[:record_tt] = true
601
600
  NewRelic::Agent.expects(:is_execution_traced?).returns(true)
602
601
  @sampler.send(:start_builder)
603
- assert(Thread.current[:transaction_sample_builder] \
602
+ assert(NewRelic::Agent::TransactionState.get.transaction_sample_builder \
604
603
  .is_a?(NewRelic::Agent::TransactionSampleBuilder),
605
604
  "should set up a new builder by default")
606
605
  end
607
606
 
608
607
  def test_start_builder_disabled
609
- Thread.current[:transaction_sample_builder] = 'not nil.'
608
+ NewRelic::Agent::TransactionState.get.transaction_sample_builder = 'not nil.'
610
609
  with_config(:'transaction_tracer.enabled' => false,
611
610
  :developer_mode => false) do
612
611
  @sampler.send(:start_builder)
613
- assert_equal(nil, Thread.current[:transaction_sample_builder],
612
+ assert_equal(nil, NewRelic::Agent::TransactionState.get.transaction_sample_builder,
614
613
  "should clear the transaction builder when disabled")
615
614
  end
616
615
  end
617
616
 
618
617
  def test_start_builder_dont_replace_existing_builder
619
618
  fake_builder = mock('transaction sample builder')
620
- Thread.current[:transaction_sample_builder] = fake_builder
619
+ NewRelic::Agent::TransactionState.get.transaction_sample_builder = fake_builder
621
620
  @sampler.send(:start_builder)
622
- assert_equal(fake_builder, Thread.current[:transaction_sample_builder],
621
+ assert_equal(fake_builder, NewRelic::Agent::TransactionState.get.transaction_sample_builder,
623
622
  "should not overwrite an existing transaction sample builder")
624
- Thread.current[:transaction_sample_builder] = nil
623
+ NewRelic::Agent::TransactionState.get.transaction_sample_builder = nil
625
624
  end
626
625
 
627
626
  def test_builder
628
- Thread.current[:transaction_sample_builder] = 'shamalamadingdong, brother.'
627
+ NewRelic::Agent::TransactionState.get.transaction_sample_builder = 'shamalamadingdong, brother.'
629
628
  assert_equal('shamalamadingdong, brother.', @sampler.send(:builder),
630
629
  'should return the value from the thread local variable')
631
- Thread.current[:transaction_sample_builder] = nil
630
+ NewRelic::Agent::TransactionState.get.transaction_sample_builder = nil
632
631
  end
633
632
 
634
633
  def test_clear_builder
635
- Thread.current[:transaction_sample_builder] = 'shamalamadingdong, brother.'
634
+ NewRelic::Agent::TransactionState.get.transaction_sample_builder = 'shamalamadingdong, brother.'
636
635
  assert_equal(nil, @sampler.send(:clear_builder), 'should clear the thread local variable')
637
636
  end
638
637
 
@@ -814,7 +813,7 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
814
813
  def test_record_sql_off
815
814
  @sampler.notice_first_scope_push Time.now.to_f
816
815
 
817
- Thread::current[:record_sql] = false
816
+ NewRelic::Agent::TransactionState.get.record_sql = false
818
817
 
819
818
  @sampler.notice_sql("test", {}, 0)
820
819
 
@@ -0,0 +1,75 @@
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/transaction'
7
+ require 'new_relic/agent/transaction_state'
8
+
9
+ module NewRelic::Agent
10
+ class TransactionStateTest < Test::Unit::TestCase
11
+ attr_reader :state
12
+
13
+ def setup
14
+ @state = TransactionState.new
15
+ end
16
+
17
+ def test_without_transaction_stack_on_thread
18
+ state.current_transaction_stack = nil
19
+ assert_equal false, state.in_background_transaction?
20
+ assert_equal false, state.in_request_transaction?
21
+ end
22
+
23
+ def test_in_background_transaction
24
+ state.current_transaction_stack = [NewRelic::Agent::Transaction.new]
25
+
26
+ assert state.in_background_transaction?
27
+ end
28
+
29
+ def test_in_request_tranasction
30
+ transaction = NewRelic::Agent::Transaction.new
31
+ transaction.request = stub()
32
+
33
+ state.current_transaction_stack = [transaction]
34
+
35
+ assert state.in_request_transaction?
36
+ end
37
+
38
+ def test_in_request_transaction_checks_last
39
+ earlier_transaction = NewRelic::Agent::Transaction.new
40
+ transaction = NewRelic::Agent::Transaction.new
41
+ transaction.request = stub()
42
+
43
+ state.current_transaction_stack = [earlier_transaction, transaction]
44
+
45
+ assert state.in_request_transaction?
46
+ end
47
+
48
+ def test_timings_without_transaction
49
+ freeze_time
50
+
51
+ state.reset(nil)
52
+ timings = state.timings
53
+
54
+ assert_equal 0.0, timings.queue_time_in_seconds
55
+ assert_equal 0.0, timings.app_time_in_seconds
56
+ assert_equal nil, timings.transaction_name
57
+ end
58
+
59
+ def test_timings_with_transaction
60
+ earliest_time = freeze_time
61
+ transaction = NewRelic::Agent::Transaction.new
62
+ transaction.apdex_start = earliest_time
63
+ transaction.start_time = earliest_time + 5
64
+ transaction.name = "Transaction/name"
65
+ state.transaction = transaction
66
+
67
+ advance_time(10.0)
68
+ timings = state.timings
69
+
70
+ assert_equal 5.0, timings.queue_time_in_seconds
71
+ assert_equal 5.0, timings.app_time_in_seconds
72
+ assert_equal transaction.name, timings.transaction_name
73
+ end
74
+ end
75
+ end
@@ -87,6 +87,21 @@ class NewRelic::Agent::TransactionTest < Test::Unit::TestCase
87
87
  assert_equal(:apdex_f, bucket)
88
88
  end
89
89
 
90
+ def test_has_correct_apdex_t_for_transaction
91
+ config = {
92
+ :web_transactions_apdex => {'Controller/foo/bar' => 1.5},
93
+ :apdex_t => 2.0
94
+ }
95
+
96
+ with_config(config, :do_not_cast => true) do
97
+ txn.name = 'Controller/foo/bar'
98
+ assert_equal 1.5, txn.apdex_t
99
+
100
+ txn.name = 'Controller/some/other'
101
+ assert_equal 2.0, txn.apdex_t
102
+ end
103
+ end
104
+
90
105
  def test_update_apdex_records_correct_apdex_for_key_transaction
91
106
  config = {
92
107
  :web_transactions_apdex => {
@@ -0,0 +1,81 @@
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/transaction_timings'
7
+
8
+ module NewRelic::Agent
9
+ class TransactionTimingsTest < Test::Unit::TestCase
10
+
11
+ def setup
12
+ @start_time = freeze_time
13
+ @name = "Name"
14
+ end
15
+
16
+ def test_queue_time_nil
17
+ t = TransactionTimings.new(nil, @start_time, @name)
18
+ assert_equal 0.0, t.queue_time_in_millis
19
+ end
20
+
21
+ def test_queue_time_in_millis
22
+ t = TransactionTimings.new(1000.1234, @start_time, @name)
23
+ assert_equal 1_000_123, t.queue_time_in_millis
24
+ end
25
+
26
+ def test_queue_time_in_seconds
27
+ t = TransactionTimings.new(1000.1234, @start_time, @name)
28
+ assert_equal 1_000.1234, t.queue_time_in_seconds
29
+ end
30
+
31
+ def test_queue_time_clamps_to_positive_in_millis
32
+ t = TransactionTimings.new(-1000, @start_time, @name)
33
+ assert_equal 0, t.queue_time_in_millis
34
+ end
35
+
36
+ def test_queue_time_clamps_to_positive_in_seconds
37
+ t = TransactionTimings.new(-1000, @start_time, @name)
38
+ assert_equal 0, t.queue_time_in_seconds
39
+ end
40
+
41
+ def test_screwy_queue_time_defaults_to_zero
42
+ t = TransactionTimings.new("a duck", @start_time, @name)
43
+ assert_equal 0.0, t.queue_time_in_seconds
44
+ end
45
+
46
+ def test_app_time_in_millis
47
+ advance_time(2)
48
+ t = TransactionTimings.new(nil, @start_time, @name)
49
+ assert_equal 2_000.0, t.app_time_in_millis
50
+ end
51
+
52
+ def test_app_time_in_seconds
53
+ advance_time(2)
54
+ t = TransactionTimings.new(nil, @start_time, @name)
55
+ assert_equal 2.0, t.app_time_in_seconds
56
+ end
57
+
58
+ def test_locks_time_at_instantiation
59
+ t = TransactionTimings.new(1000, @start_time, @name)
60
+ original = t.app_time_in_seconds
61
+
62
+ advance_time(3)
63
+ later = t.app_time_in_seconds
64
+
65
+ assert_equal original, later
66
+ end
67
+
68
+ def test_transaction_name
69
+ t = TransactionTimings.new(nil, nil, @name)
70
+ assert_equal "Name", t.transaction_name
71
+ end
72
+
73
+ def test_clamp_to_positive
74
+ t = TransactionTimings.new(nil, nil, nil)
75
+ assert_equal(0.0, t.clamp_to_positive(-1), "should clamp a negative value to zero")
76
+ assert_equal(1232, t.clamp_to_positive(1232), "should pass through the value when it is positive")
77
+ assert_equal(0, t.clamp_to_positive(0), "should not mess with zero when passing it through")
78
+ end
79
+
80
+ end
81
+ end
@@ -19,7 +19,7 @@ module NewRelic
19
19
 
20
20
  def teardown
21
21
  super
22
- Thread.current[:newrelic_untraced] = nil
22
+ NewRelic::Agent::TransactionState.clear
23
23
  end
24
24
 
25
25
  def test_shutdown
@@ -83,10 +83,8 @@ module NewRelic
83
83
  end
84
84
 
85
85
  def test_manual_start_starts_channel_listener
86
- NewRelic::Agent::PipeChannelManager.listener.stop
86
+ NewRelic::Agent::PipeChannelManager.listener.expects(:start).at_least_once
87
87
  NewRelic::Agent.manual_start(:start_channel_listener => true)
88
- assert NewRelic::Agent::PipeChannelManager.listener.started?
89
- NewRelic::Agent::PipeChannelManager.listener.stop
90
88
  NewRelic::Agent.shutdown
91
89
  end
92
90
 
@@ -141,52 +139,52 @@ module NewRelic
141
139
  end
142
140
 
143
141
  def test_is_transaction_traced_true
144
- Thread.current[:record_tt] = true
142
+ NewRelic::Agent::TransactionState.get.record_tt = true
145
143
  assert_equal(true, NewRelic::Agent.is_transaction_traced?, 'should be true since the thread local is set')
146
144
  end
147
145
 
148
146
  def test_is_transaction_traced_blank
149
- Thread.current[:record_tt] = nil
147
+ NewRelic::Agent::TransactionState.get.record_tt = nil
150
148
  assert_equal(true, NewRelic::Agent.is_transaction_traced?, 'should be true since the thread local is not set')
151
149
  end
152
150
 
153
151
  def test_is_transaction_traced_false
154
- Thread.current[:record_tt] = false
152
+ NewRelic::Agent::TransactionState.get.record_tt = false
155
153
  assert_equal(false, NewRelic::Agent.is_transaction_traced?, 'should be false since the thread local is false')
156
154
  end
157
155
 
158
156
  def test_is_sql_recorded_true
159
- Thread.current[:record_sql] = true
157
+ NewRelic::Agent::TransactionState.get.record_sql = true
160
158
  assert_equal(true, NewRelic::Agent.is_sql_recorded?, 'should be true since the thread local is set')
161
159
  end
162
160
 
163
161
  def test_is_sql_recorded_blank
164
- Thread.current[:record_sql] = nil
162
+ NewRelic::Agent::TransactionState.get.record_sql = nil
165
163
  assert_equal(true, NewRelic::Agent.is_sql_recorded?, 'should be true since the thread local is not set')
166
164
  end
167
165
 
168
166
  def test_is_sql_recorded_false
169
- Thread.current[:record_sql] = false
167
+ NewRelic::Agent::TransactionState.get.record_sql = false
170
168
  assert_equal(false, NewRelic::Agent.is_sql_recorded?, 'should be false since the thread local is false')
171
169
  end
172
170
 
173
171
  def test_is_execution_traced_true
174
- Thread.current[:newrelic_untraced] = [true, true]
172
+ NewRelic::Agent::TransactionState.get.untraced = [true, true]
175
173
  assert_equal(true, NewRelic::Agent.is_execution_traced?, 'should be true since the thread local is set')
176
174
  end
177
175
 
178
176
  def test_is_execution_traced_blank
179
- Thread.current[:newrelic_untraced] = nil
177
+ NewRelic::Agent::TransactionState.get.untraced = nil
180
178
  assert_equal(true, NewRelic::Agent.is_execution_traced?, 'should be true since the thread local is not set')
181
179
  end
182
180
 
183
181
  def test_is_execution_traced_empty
184
- Thread.current[:newrelic_untraced] = []
182
+ NewRelic::Agent::TransactionState.get.untraced = []
185
183
  assert_equal(true, NewRelic::Agent.is_execution_traced?, 'should be true since the thread local is an empty array')
186
184
  end
187
185
 
188
186
  def test_is_execution_traced_false
189
- Thread.current[:newrelic_untraced] = [true, false]
187
+ NewRelic::Agent::TransactionState.get.untraced = [true, false]
190
188
  assert_equal(false, NewRelic::Agent.is_execution_traced?, 'should be false since the thread local stack has the last element false')
191
189
  end
192
190