wd_newrelic_rpm 3.3.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (264) hide show
  1. data/CHANGELOG +591 -0
  2. data/LICENSE +64 -0
  3. data/README.rdoc +179 -0
  4. data/bin/mongrel_rpm +33 -0
  5. data/bin/newrelic +13 -0
  6. data/bin/newrelic_cmd +5 -0
  7. data/cert/cacert.pem +118 -0
  8. data/cert/oldsite.pem +28 -0
  9. data/cert/site.pem +27 -0
  10. data/install.rb +9 -0
  11. data/lib/conditional_vendored_dependency_detection.rb +3 -0
  12. data/lib/conditional_vendored_metric_parser.rb +5 -0
  13. data/lib/new_relic/agent.rb +467 -0
  14. data/lib/new_relic/agent/agent.rb +1325 -0
  15. data/lib/new_relic/agent/beacon_configuration.rb +121 -0
  16. data/lib/new_relic/agent/browser_monitoring.rb +142 -0
  17. data/lib/new_relic/agent/busy_calculator.rb +99 -0
  18. data/lib/new_relic/agent/chained_call.rb +13 -0
  19. data/lib/new_relic/agent/database.rb +223 -0
  20. data/lib/new_relic/agent/error_collector.rb +251 -0
  21. data/lib/new_relic/agent/instrumentation.rb +9 -0
  22. data/lib/new_relic/agent/instrumentation/active_merchant.rb +29 -0
  23. data/lib/new_relic/agent/instrumentation/active_record.rb +137 -0
  24. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +68 -0
  25. data/lib/new_relic/agent/instrumentation/authlogic.rb +19 -0
  26. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +443 -0
  27. data/lib/new_relic/agent/instrumentation/data_mapper.rb +238 -0
  28. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +52 -0
  29. data/lib/new_relic/agent/instrumentation/memcache.rb +80 -0
  30. data/lib/new_relic/agent/instrumentation/merb/controller.rb +41 -0
  31. data/lib/new_relic/agent/instrumentation/merb/errors.rb +29 -0
  32. data/lib/new_relic/agent/instrumentation/metric_frame.rb +353 -0
  33. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +80 -0
  34. data/lib/new_relic/agent/instrumentation/net.rb +29 -0
  35. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +37 -0
  36. data/lib/new_relic/agent/instrumentation/queue_time.rb +210 -0
  37. data/lib/new_relic/agent/instrumentation/rack.rb +98 -0
  38. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +114 -0
  39. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +42 -0
  40. data/lib/new_relic/agent/instrumentation/rails/errors.rb +42 -0
  41. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +180 -0
  42. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +37 -0
  43. data/lib/new_relic/agent/instrumentation/sinatra.rb +78 -0
  44. data/lib/new_relic/agent/instrumentation/sunspot.rb +29 -0
  45. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +21 -0
  46. data/lib/new_relic/agent/method_tracer.rb +528 -0
  47. data/lib/new_relic/agent/sampler.rb +50 -0
  48. data/lib/new_relic/agent/samplers/cpu_sampler.rb +58 -0
  49. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +40 -0
  50. data/lib/new_relic/agent/samplers/memory_sampler.rb +143 -0
  51. data/lib/new_relic/agent/samplers/object_sampler.rb +26 -0
  52. data/lib/new_relic/agent/shim_agent.rb +29 -0
  53. data/lib/new_relic/agent/sql_sampler.rb +286 -0
  54. data/lib/new_relic/agent/stats_engine.rb +26 -0
  55. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +123 -0
  56. data/lib/new_relic/agent/stats_engine/metric_stats.rb +187 -0
  57. data/lib/new_relic/agent/stats_engine/samplers.rb +95 -0
  58. data/lib/new_relic/agent/stats_engine/transactions.rb +125 -0
  59. data/lib/new_relic/agent/transaction_info.rb +74 -0
  60. data/lib/new_relic/agent/transaction_sample_builder.rb +116 -0
  61. data/lib/new_relic/agent/transaction_sampler.rb +468 -0
  62. data/lib/new_relic/agent/worker_loop.rb +89 -0
  63. data/lib/new_relic/collection_helper.rb +77 -0
  64. data/lib/new_relic/command.rb +85 -0
  65. data/lib/new_relic/commands/deployments.rb +105 -0
  66. data/lib/new_relic/commands/install.rb +80 -0
  67. data/lib/new_relic/control.rb +46 -0
  68. data/lib/new_relic/control/class_methods.rb +53 -0
  69. data/lib/new_relic/control/configuration.rb +206 -0
  70. data/lib/new_relic/control/frameworks.rb +10 -0
  71. data/lib/new_relic/control/frameworks/external.rb +16 -0
  72. data/lib/new_relic/control/frameworks/merb.rb +31 -0
  73. data/lib/new_relic/control/frameworks/rails.rb +164 -0
  74. data/lib/new_relic/control/frameworks/rails3.rb +75 -0
  75. data/lib/new_relic/control/frameworks/ruby.rb +42 -0
  76. data/lib/new_relic/control/frameworks/sinatra.rb +20 -0
  77. data/lib/new_relic/control/instance_methods.rb +179 -0
  78. data/lib/new_relic/control/instrumentation.rb +100 -0
  79. data/lib/new_relic/control/logging_methods.rb +143 -0
  80. data/lib/new_relic/control/profiling.rb +25 -0
  81. data/lib/new_relic/control/server_methods.rb +114 -0
  82. data/lib/new_relic/data_serialization.rb +151 -0
  83. data/lib/new_relic/delayed_job_injection.rb +51 -0
  84. data/lib/new_relic/language_support.rb +73 -0
  85. data/lib/new_relic/local_environment.rb +428 -0
  86. data/lib/new_relic/merbtasks.rb +6 -0
  87. data/lib/new_relic/metric_data.rb +51 -0
  88. data/lib/new_relic/metric_spec.rb +76 -0
  89. data/lib/new_relic/metrics.rb +9 -0
  90. data/lib/new_relic/noticed_error.rb +29 -0
  91. data/lib/new_relic/rack/browser_monitoring.rb +76 -0
  92. data/lib/new_relic/rack/developer_mode.rb +268 -0
  93. data/lib/new_relic/recipes.rb +77 -0
  94. data/lib/new_relic/stats.rb +335 -0
  95. data/lib/new_relic/timer_lib.rb +27 -0
  96. data/lib/new_relic/transaction_analysis.rb +77 -0
  97. data/lib/new_relic/transaction_analysis/segment_summary.rb +49 -0
  98. data/lib/new_relic/transaction_sample.rb +261 -0
  99. data/lib/new_relic/transaction_sample/composite_segment.rb +27 -0
  100. data/lib/new_relic/transaction_sample/fake_segment.rb +9 -0
  101. data/lib/new_relic/transaction_sample/segment.rb +203 -0
  102. data/lib/new_relic/transaction_sample/summary_segment.rb +21 -0
  103. data/lib/new_relic/url_rule.rb +14 -0
  104. data/lib/new_relic/version.rb +55 -0
  105. data/lib/newrelic_rpm.rb +49 -0
  106. data/lib/tasks/all.rb +4 -0
  107. data/lib/tasks/install.rake +7 -0
  108. data/lib/tasks/tests.rake +19 -0
  109. data/newrelic.yml +265 -0
  110. data/newrelic_rpm.gemspec +312 -0
  111. data/recipes/newrelic.rb +6 -0
  112. data/test/active_record_fixtures.rb +77 -0
  113. data/test/config/newrelic.yml +48 -0
  114. data/test/config/test_control.rb +48 -0
  115. data/test/fixtures/proc_cpuinfo.txt +575 -0
  116. data/test/new_relic/agent/agent/connect_test.rb +403 -0
  117. data/test/new_relic/agent/agent/start_test.rb +255 -0
  118. data/test/new_relic/agent/agent/start_worker_thread_test.rb +153 -0
  119. data/test/new_relic/agent/agent_test.rb +140 -0
  120. data/test/new_relic/agent/agent_test_controller.rb +77 -0
  121. data/test/new_relic/agent/agent_test_controller_test.rb +382 -0
  122. data/test/new_relic/agent/apdex_from_server_test.rb +9 -0
  123. data/test/new_relic/agent/beacon_configuration_test.rb +111 -0
  124. data/test/new_relic/agent/browser_monitoring_test.rb +323 -0
  125. data/test/new_relic/agent/busy_calculator_test.rb +81 -0
  126. data/test/new_relic/agent/database_test.rb +149 -0
  127. data/test/new_relic/agent/error_collector/notice_error_test.rb +257 -0
  128. data/test/new_relic/agent/error_collector_test.rb +192 -0
  129. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +576 -0
  130. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +34 -0
  131. data/test/new_relic/agent/instrumentation/instrumentation_test.rb +11 -0
  132. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +171 -0
  133. data/test/new_relic/agent/instrumentation/metric_frame_test.rb +50 -0
  134. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +84 -0
  135. data/test/new_relic/agent/instrumentation/queue_time_test.rb +382 -0
  136. data/test/new_relic/agent/instrumentation/rack_test.rb +35 -0
  137. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +184 -0
  138. data/test/new_relic/agent/memcache_instrumentation_test.rb +143 -0
  139. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +164 -0
  140. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +234 -0
  141. data/test/new_relic/agent/method_tracer_test.rb +386 -0
  142. data/test/new_relic/agent/mock_scope_listener.rb +23 -0
  143. data/test/new_relic/agent/rpm_agent_test.rb +149 -0
  144. data/test/new_relic/agent/sampler_test.rb +19 -0
  145. data/test/new_relic/agent/shim_agent_test.rb +20 -0
  146. data/test/new_relic/agent/sql_sampler_test.rb +192 -0
  147. data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +150 -0
  148. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +82 -0
  149. data/test/new_relic/agent/stats_engine/samplers_test.rb +99 -0
  150. data/test/new_relic/agent/stats_engine_test.rb +220 -0
  151. data/test/new_relic/agent/transaction_info_test.rb +13 -0
  152. data/test/new_relic/agent/transaction_sample_builder_test.rb +219 -0
  153. data/test/new_relic/agent/transaction_sampler_test.rb +967 -0
  154. data/test/new_relic/agent/worker_loop_test.rb +66 -0
  155. data/test/new_relic/agent_test.rb +187 -0
  156. data/test/new_relic/collection_helper_test.rb +149 -0
  157. data/test/new_relic/command/deployments_test.rb +68 -0
  158. data/test/new_relic/control/class_methods_test.rb +62 -0
  159. data/test/new_relic/control/configuration_test.rb +84 -0
  160. data/test/new_relic/control/logging_methods_test.rb +185 -0
  161. data/test/new_relic/control_test.rb +256 -0
  162. data/test/new_relic/data_serialization_test.rb +208 -0
  163. data/test/new_relic/delayed_job_injection_test.rb +16 -0
  164. data/test/new_relic/local_environment_test.rb +85 -0
  165. data/test/new_relic/metric_data_test.rb +125 -0
  166. data/test/new_relic/metric_parser/metric_parser_test.rb +11 -0
  167. data/test/new_relic/metric_spec_test.rb +95 -0
  168. data/test/new_relic/rack/all_test.rb +11 -0
  169. data/test/new_relic/rack/browser_monitoring_test.rb +142 -0
  170. data/test/new_relic/rack/developer_mode_helper_test.rb +141 -0
  171. data/test/new_relic/rack/developer_mode_test.rb +74 -0
  172. data/test/new_relic/stats_test.rb +411 -0
  173. data/test/new_relic/transaction_analysis/segment_summary_test.rb +91 -0
  174. data/test/new_relic/transaction_analysis_test.rb +121 -0
  175. data/test/new_relic/transaction_sample/composite_segment_test.rb +35 -0
  176. data/test/new_relic/transaction_sample/fake_segment_test.rb +17 -0
  177. data/test/new_relic/transaction_sample/segment_test.rb +389 -0
  178. data/test/new_relic/transaction_sample/summary_segment_test.rb +31 -0
  179. data/test/new_relic/transaction_sample_subtest_test.rb +56 -0
  180. data/test/new_relic/transaction_sample_test.rb +177 -0
  181. data/test/new_relic/version_number_test.rb +89 -0
  182. data/test/script/build_test_gem.sh +51 -0
  183. data/test/script/ci.sh +94 -0
  184. data/test/script/ci_bench.sh +52 -0
  185. data/test/test_contexts.rb +29 -0
  186. data/test/test_helper.rb +155 -0
  187. data/ui/helpers/developer_mode_helper.rb +357 -0
  188. data/ui/helpers/google_pie_chart.rb +48 -0
  189. data/ui/views/layouts/newrelic_default.rhtml +47 -0
  190. data/ui/views/newrelic/_explain_plans.rhtml +27 -0
  191. data/ui/views/newrelic/_sample.rhtml +20 -0
  192. data/ui/views/newrelic/_segment.rhtml +28 -0
  193. data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
  194. data/ui/views/newrelic/_segment_row.rhtml +12 -0
  195. data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
  196. data/ui/views/newrelic/_show_sample_sql.rhtml +24 -0
  197. data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
  198. data/ui/views/newrelic/_sql_row.rhtml +16 -0
  199. data/ui/views/newrelic/_stack_trace.rhtml +15 -0
  200. data/ui/views/newrelic/_table.rhtml +12 -0
  201. data/ui/views/newrelic/explain_sql.rhtml +43 -0
  202. data/ui/views/newrelic/file/images/arrow-close.png +0 -0
  203. data/ui/views/newrelic/file/images/arrow-open.png +0 -0
  204. data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
  205. data/ui/views/newrelic/file/images/file_icon.png +0 -0
  206. data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
  207. data/ui/views/newrelic/file/images/new-relic-rpm-desktop.gif +0 -0
  208. data/ui/views/newrelic/file/images/new_relic_rpm_desktop.gif +0 -0
  209. data/ui/views/newrelic/file/images/textmate.png +0 -0
  210. data/ui/views/newrelic/file/javascript/jquery-1.4.2.js +6240 -0
  211. data/ui/views/newrelic/file/javascript/transaction_sample.js +120 -0
  212. data/ui/views/newrelic/file/stylesheets/style.css +490 -0
  213. data/ui/views/newrelic/index.rhtml +71 -0
  214. data/ui/views/newrelic/sample_not_found.rhtml +2 -0
  215. data/ui/views/newrelic/show_sample.rhtml +80 -0
  216. data/ui/views/newrelic/show_source.rhtml +3 -0
  217. data/ui/views/newrelic/threads.rhtml +53 -0
  218. data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +5 -0
  219. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +67 -0
  220. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection/version.rb +3 -0
  221. data/vendor/gems/metric_parser-0.1.0.pre1/lib/metric_parser.rb +1 -0
  222. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser.rb +64 -0
  223. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/action_mailer.rb +14 -0
  224. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_merchant.rb +31 -0
  225. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_record.rb +33 -0
  226. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/apdex.rb +89 -0
  227. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/background_transaction.rb +7 -0
  228. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/client.rb +46 -0
  229. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller.rb +67 -0
  230. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_cpu.rb +43 -0
  231. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_ext.rb +17 -0
  232. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database.rb +48 -0
  233. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database_pool.rb +24 -0
  234. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net.rb +28 -0
  235. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net_parser.rb +17 -0
  236. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/errors.rb +11 -0
  237. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/external.rb +55 -0
  238. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/frontend.rb +40 -0
  239. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/gc.rb +20 -0
  240. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/hibernate_session.rb +7 -0
  241. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java.rb +31 -0
  242. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java_parser.rb +17 -0
  243. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp.rb +34 -0
  244. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp_tag.rb +7 -0
  245. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +55 -0
  246. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +135 -0
  247. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/orm.rb +27 -0
  248. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/other_transaction.rb +40 -0
  249. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet.rb +7 -0
  250. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_context_listener.rb +7 -0
  251. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_filter.rb +7 -0
  252. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr.rb +27 -0
  253. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr_request_handler.rb +15 -0
  254. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring.rb +54 -0
  255. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_controller.rb +6 -0
  256. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_view.rb +6 -0
  257. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_action.rb +20 -0
  258. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_result.rb +20 -0
  259. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/version.rb +5 -0
  260. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +70 -0
  261. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_frontend.rb +18 -0
  262. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_service.rb +14 -0
  263. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_transaction.rb +133 -0
  264. metadata +376 -0
@@ -0,0 +1,9 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
+
3
+ class NewRelic::Agent::ApdexFromServerTest < Test::Unit::TestCase
4
+
5
+ def test_true
6
+ # we need tests in this file - TBD
7
+ assert true
8
+ end
9
+ end
@@ -0,0 +1,111 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
+ require "new_relic/agent/beacon_configuration"
3
+ class NewRelic::Agent::BeaconConfigurationTest < Test::Unit::TestCase
4
+ def test_initialize_basic
5
+ connect_data = {}
6
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
7
+ assert_equal true, bc.rum_enabled
8
+ assert_equal '', bc.browser_timing_header
9
+ %w[application_id browser_monitoring_key beacon].each do |method|
10
+ value = bc.send(method.to_sym)
11
+ assert_equal nil, value, "Expected #{method} to be nil, but was #{value.inspect}"
12
+ end
13
+ end
14
+
15
+ def test_initialize_with_real_data
16
+ connect_data = {'browser_key' => 'a browser monitoring key', 'application_id' => 'an application id', 'beacon' => 'a beacon', 'rum_enabled' => true}
17
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
18
+ assert_equal(true, bc.rum_enabled)
19
+ assert_equal('a browser monitoring key', bc.browser_monitoring_key)
20
+ assert_equal('an application id', bc.application_id)
21
+ assert_equal('a beacon', bc.beacon)
22
+ s = "<script type=\"text/javascript\">var NREUMQ=NREUMQ||[];NREUMQ.push([\"mark\",\"firstbyte\",new Date().getTime()]);</script>"
23
+ assert_equal(s, bc.browser_timing_header)
24
+ end
25
+
26
+ def test_license_bytes_nil
27
+ connect_data = {}
28
+ NewRelic::Control.instance.expects(:license_key).returns('a' * 40).once
29
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
30
+ assert_equal([97] * 40, bc.license_bytes, 'should return the bytes of the license key')
31
+ end
32
+
33
+ def test_license_bytes_existing_bytes
34
+ connect_data = {}
35
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
36
+ bc.instance_eval { @license_bytes = [97] * 40 }
37
+ NewRelic::Control.instance.expects(:license_key).never
38
+ assert_equal([97] * 40, bc.license_bytes, "should return the cached value if it exists")
39
+ end
40
+
41
+ def test_license_bytes_should_set_instance_cache
42
+ connect_data = {}
43
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
44
+ NewRelic::Control.instance.expects(:license_key).returns('a' * 40)
45
+ bc.instance_eval { @license_bytes = nil }
46
+ bc.license_bytes
47
+ assert_equal([97] * 40, bc.instance_variable_get('@license_bytes'), "should cache the license bytes for later")
48
+ end
49
+
50
+ def test_build_browser_timing_header_disabled
51
+ connect_data = {}
52
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
53
+ bc.instance_eval { @rum_enabled = false }
54
+ assert_equal '', bc.build_browser_timing_header, "should not return a header when rum enabled is false"
55
+ end
56
+
57
+ def test_build_browser_timing_header_enabled_but_no_key
58
+ connect_data = {}
59
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
60
+ bc.instance_eval { @rum_enabled = true; @browser_monitoring_key = nil }
61
+ assert_equal '', bc.build_browser_timing_header, "should not return a header when browser_monitoring_key is nil"
62
+ end
63
+
64
+ def test_build_browser_timing_header_enabled_with_key
65
+ connect_data = {}
66
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
67
+ bc.instance_eval { @browser_monitoring_key = 'a browser monitoring key' }
68
+ assert(bc.build_browser_timing_header.include?('NREUMQ'), "header should be generated when rum is enabled and browser monitoring key is set")
69
+ end
70
+
71
+ def test_build_browser_timing_header_should_html_safe_header
72
+ mock_javascript = mock('javascript')
73
+ connect_data = {'browser_key' => 'a' * 40}
74
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
75
+ assert_equal('a' * 40, bc.instance_variable_get('@browser_monitoring_key'), "should save the key from the config")
76
+ bc.expects(:javascript_header).returns(mock_javascript)
77
+ mock_javascript.expects(:respond_to?).with(:html_safe).returns(true)
78
+ mock_javascript.expects(:html_safe)
79
+ bc.build_browser_timing_header
80
+ end
81
+
82
+ def test_build_load_file_js_load_episodes_file_false
83
+ connect_data = {'rum.load_episodes_file' => false}
84
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
85
+ s = "if (!NREUMQ.f) { NREUMQ.f=function() {\nNREUMQ.push([\"load\",new Date().getTime()]);\nif(NREUMQ.a)NREUMQ.a();\n};\nNREUMQ.a=window.onload;window.onload=NREUMQ.f;\n};\n"
86
+ assert_equal(s, bc.build_load_file_js(connect_data))
87
+ end
88
+
89
+ def test_build_load_file_js_load_episodes_file_missing
90
+ connect_data = {}
91
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
92
+ s = "if (!NREUMQ.f) { NREUMQ.f=function() {\nNREUMQ.push([\"load\",new Date().getTime()]);\nvar e=document.createElement(\"script\");\ne.type=\"text/javascript\";e.async=true;e.src=\"\";\ndocument.body.appendChild(e);\nif(NREUMQ.a)NREUMQ.a();\n};\nNREUMQ.a=window.onload;window.onload=NREUMQ.f;\n};\n"
93
+
94
+ assert_equal(s, bc.build_load_file_js(connect_data))
95
+ end
96
+
97
+ def test_build_load_file_js_load_episodes_file_present
98
+ connect_data = {'rum.load_episodes_file' => true}
99
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
100
+ s = "if (!NREUMQ.f) { NREUMQ.f=function() {\nNREUMQ.push([\"load\",new Date().getTime()]);\nvar e=document.createElement(\"script\");\ne.type=\"text/javascript\";e.async=true;e.src=\"\";\ndocument.body.appendChild(e);\nif(NREUMQ.a)NREUMQ.a();\n};\nNREUMQ.a=window.onload;window.onload=NREUMQ.f;\n};\n"
101
+
102
+ assert_equal(s, bc.build_load_file_js(connect_data))
103
+ end
104
+
105
+ def test_build_load_file_js_load_episodes_file_with_episodes_url
106
+ connect_data = {'episodes_url' => 'an episodes url'}
107
+ bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
108
+ assert(bc.build_load_file_js(connect_data).include?('an episodes url'),
109
+ "should include the episodes url by default")
110
+ end
111
+ end
@@ -0,0 +1,323 @@
1
+ ENV['SKIP_RAILS'] = 'true'
2
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
3
+ require "new_relic/agent/browser_monitoring"
4
+
5
+ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
6
+ include NewRelic::Agent::BrowserMonitoring
7
+ include NewRelic::Agent::Instrumentation::ControllerInstrumentation
8
+
9
+ def setup
10
+ NewRelic::Agent.manual_start
11
+ @browser_monitoring_key = "fred"
12
+ @episodes_file = "this_is_my_file"
13
+ NewRelic::Agent.instance.instance_eval do
14
+ @beacon_configuration = NewRelic::Agent::BeaconConfiguration.new({"rum.enabled" => true, "browser_key" => "browserKey", "application_id" => "apId", "beacon"=>"beacon", "episodes_url"=>"this_is_my_file", 'rum.jsonp' => true})
15
+ end
16
+ Thread.current[:last_metric_frame] = nil
17
+ NewRelic::Agent::TransactionInfo.clear
18
+ end
19
+
20
+ def teardown
21
+ mocha_teardown
22
+ end
23
+
24
+ def test_browser_monitoring_start_time_is_reset_each_request_when_auto_instrument_is_disabled
25
+ controller = Object.new
26
+ def controller.perform_action_without_newrelic_trace(method, options={});
27
+ # noop; instrument me
28
+ end
29
+ def controller.newrelic_metric_path; "foo"; end
30
+ controller.extend ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
31
+ controller.extend ::NewRelic::Agent::BrowserMonitoring
32
+ NewRelic::Control.instance['browser_monitoring'] = { 'auto_instrument' => false }
33
+
34
+ controller.perform_action_with_newrelic_trace(:index)
35
+ first_request_start_time = controller.send(:browser_monitoring_start_time)
36
+ controller.perform_action_with_newrelic_trace(:index)
37
+ second_request_start_time = controller.send(:browser_monitoring_start_time)
38
+
39
+ # assert that these aren't the same time object
40
+ # the start time should be reinitialized each request to the controller
41
+ assert !(first_request_start_time.equal? second_request_start_time)
42
+ end
43
+
44
+ def test_browser_timing_header_with_no_beacon_configuration
45
+ NewRelic::Agent.instance.expects(:beacon_configuration).returns( nil)
46
+ header = browser_timing_header
47
+ assert_equal "", header
48
+ end
49
+
50
+ def test_browser_timing_header
51
+ header = browser_timing_header
52
+ assert_equal "<script type=\"text/javascript\">var NREUMQ=NREUMQ||[];NREUMQ.push([\"mark\",\"firstbyte\",new Date().getTime()]);</script>", header
53
+ end
54
+
55
+ def test_browser_timing_header_with_rum_enabled_not_specified
56
+ NewRelic::Agent.instance.expects(:beacon_configuration).at_least_once.returns( NewRelic::Agent::BeaconConfiguration.new({"browser_key" => "browserKey", "application_id" => "apId", "beacon"=>"beacon", "episodes_url"=>"this_is_my_file"}))
57
+ header = browser_timing_header
58
+ assert_equal "<script type=\"text/javascript\">var NREUMQ=NREUMQ||[];NREUMQ.push([\"mark\",\"firstbyte\",new Date().getTime()]);</script>", header
59
+ end
60
+
61
+ def test_browser_timing_header_with_rum_enabled_false
62
+ NewRelic::Agent.instance.expects(:beacon_configuration).twice.returns( NewRelic::Agent::BeaconConfiguration.new({"rum.enabled" => false, "browser_key" => "browserKey", "application_id" => "apId", "beacon"=>"beacon", "episodes_url"=>"this_is_my_file"}))
63
+ header = browser_timing_header
64
+ assert_equal "", header
65
+ end
66
+
67
+ def test_browser_timing_header_disable_all_tracing
68
+ header = nil
69
+ NewRelic::Agent.disable_all_tracing do
70
+ header = browser_timing_header
71
+ end
72
+ assert_equal "", header
73
+ end
74
+
75
+ def test_browser_timing_header_disable_transaction_tracing
76
+ header = nil
77
+ NewRelic::Agent.disable_transaction_tracing do
78
+ header = browser_timing_header
79
+ end
80
+ assert_equal "", header
81
+ end
82
+
83
+ def test_browser_timing_footer
84
+ browser_timing_header
85
+ NewRelic::Control.instance.expects(:license_key).returns("a" * 13)
86
+
87
+ footer = browser_timing_footer
88
+ snippet = '<script type="text/javascript">if (!NREUMQ.f) { NREUMQ.f=function() {
89
+ NREUMQ.push(["load",new Date().getTime()]);
90
+ var e=document.createElement("script");'
91
+ assert footer.include?(snippet), "Expected footer to include snippet: #{snippet}, but instead was #{footer}"
92
+ end
93
+
94
+ def test_browser_timing_footer_with_no_browser_key_rum_enabled
95
+ browser_timing_header
96
+ NewRelic::Agent.instance.expects(:beacon_configuration).returns( NewRelic::Agent::BeaconConfiguration.new({"rum.enabled" => true, "application_id" => "apId", "beacon"=>"beacon", "episodes_url"=>"this_is_my_file"}))
97
+ footer = browser_timing_footer
98
+ assert_equal "", footer
99
+ end
100
+
101
+ def test_browser_timing_footer_with_no_browser_key_rum_disabled
102
+ browser_timing_header
103
+ NewRelic::Agent.instance.expects(:beacon_configuration).returns( NewRelic::Agent::BeaconConfiguration.new({"rum.enabled" => false, "application_id" => "apId", "beacon"=>"beacon", "episodes_url"=>"this_is_my_file"}))
104
+ footer = browser_timing_footer
105
+ assert_equal "", footer
106
+ end
107
+
108
+ def test_browser_timing_footer_with_rum_enabled_not_specified
109
+ browser_timing_header
110
+
111
+ license_bytes = [];
112
+ ("a" * 13).each_byte {|byte| license_bytes << byte}
113
+ config = NewRelic::Agent::BeaconConfiguration.new({"browser_key" => "browserKey", "application_id" => "apId", "beacon"=>"beacon", "episodes_url"=>"this_is_my_file", "license_bytes" => license_bytes})
114
+ config.expects(:license_bytes).returns(license_bytes).at_least_once
115
+ NewRelic::Agent.instance.expects(:beacon_configuration).returns(config).at_least_once
116
+ footer = browser_timing_footer
117
+ beginning_snippet = '<script type="text/javascript">if (!NREUMQ.f) { NREUMQ.f=function() {
118
+ NREUMQ.push(["load",new Date().getTime()]);
119
+ var e=document.createElement("script");'
120
+ ending_snippet = "])</script>"
121
+ assert(footer.include?(beginning_snippet), "expected footer to include beginning snippet: #{beginning_snippet}, but was #{footer}")
122
+ assert(footer.include?(ending_snippet), "expected footer to include ending snippet: #{ending_snippet}, but was #{footer}")
123
+ end
124
+
125
+ def test_browser_timing_footer_with_no_beacon_configuration
126
+ browser_timing_header
127
+ NewRelic::Agent.instance.expects(:beacon_configuration).returns( nil)
128
+ footer = browser_timing_footer
129
+ assert_equal "", footer
130
+ end
131
+
132
+
133
+ def test_browser_timing_footer_disable_all_tracing
134
+ browser_timing_header
135
+ footer = nil
136
+ NewRelic::Agent.disable_all_tracing do
137
+ footer = browser_timing_footer
138
+ end
139
+ assert_equal "", footer
140
+ end
141
+
142
+ def test_browser_timing_footer_disable_transaction_tracing
143
+ browser_timing_header
144
+ footer = nil
145
+ NewRelic::Agent.disable_transaction_tracing do
146
+ footer = browser_timing_footer
147
+ end
148
+ assert_equal "", footer
149
+ end
150
+
151
+ def test_browser_timing_footer_browser_monitoring_key_missing
152
+ fake_config = mock('beacon configuration')
153
+ NewRelic::Agent.instance.expects(:beacon_configuration).returns(fake_config)
154
+ fake_config.expects(:nil?).returns(false)
155
+ fake_config.expects(:rum_enabled).returns(true)
156
+ fake_config.expects(:browser_monitoring_key).returns(nil)
157
+ self.expects(:generate_footer_js).never
158
+ assert_equal('', browser_timing_footer, "should not return a footer when there is no key")
159
+ end
160
+
161
+ def test_generate_footer_js_null_case
162
+ self.expects(:browser_monitoring_start_time).returns(nil)
163
+ assert_equal('', generate_footer_js(NewRelic::Agent.instance.beacon_configuration), "should not send javascript when there is no start time")
164
+ end
165
+
166
+ def test_generate_footer_js_with_start_time
167
+ self.expects(:browser_monitoring_start_time).returns(Time.at(100))
168
+ fake_bc = mock('beacon configuration')
169
+ fake_bc.expects(:application_id).returns(1)
170
+ fake_bc.expects(:beacon).returns('beacon')
171
+ fake_bc.expects(:browser_monitoring_key).returns('a' * 40)
172
+ NewRelic::Agent.instance.stubs(:beacon_configuration).returns(fake_bc)
173
+ self.expects(:footer_js_string).with(NewRelic::Agent.instance.beacon_configuration, 'beacon', 'a' * 40, 1).returns('footer js')
174
+ assert_equal('footer js', generate_footer_js(NewRelic::Agent.instance.beacon_configuration), 'should generate and return the footer JS when there is a start time')
175
+ end
176
+
177
+ def test_browser_monitoring_transaction_name_basic
178
+ mock = mock('transaction sample')
179
+ NewRelic::Agent::TransactionInfo.set(mock)
180
+ mock.stubs(:transaction_name).returns('a transaction name')
181
+
182
+ assert_equal('a transaction name', browser_monitoring_transaction_name, "should take the value from the thread local")
183
+ end
184
+
185
+ def test_browser_monitoring_transaction_name_empty
186
+ mock = mock('transaction sample')
187
+ NewRelic::Agent::TransactionInfo.set(mock)
188
+
189
+ mock.stubs(:transaction_name).returns('')
190
+ assert_equal('', browser_monitoring_transaction_name, "should take the value even when it is empty")
191
+ end
192
+
193
+ def test_browser_monitoring_transaction_name_nil
194
+ assert_equal('(unknown)', browser_monitoring_transaction_name, "should fill in a default when it is nil")
195
+ end
196
+
197
+ def test_browser_monitoring_transaction_name_when_tt_disabled
198
+ @sampler = NewRelic::Agent.instance.transaction_sampler
199
+ @sampler.disable
200
+
201
+ perform_action_with_newrelic_trace(:name => 'disabled_transactions') do
202
+ self.class.inspect
203
+ end
204
+
205
+ assert_match(/disabled_transactions/, browser_monitoring_transaction_name,
206
+ "should name transaction when transaction tracing disabled")
207
+ ensure
208
+ @sampler.enable
209
+ end
210
+
211
+
212
+ def test_browser_monitoring_start_time
213
+ mock = mock('transaction info')
214
+
215
+ NewRelic::Agent::TransactionInfo.set(mock)
216
+
217
+ mock.stubs(:start_time).returns(Time.at(100))
218
+ mock.stubs(:guid).returns('ABC')
219
+ assert_equal(Time.at(100), browser_monitoring_start_time, "should take the value from the thread local")
220
+ end
221
+
222
+ def test_clamp_to_positive
223
+ assert_equal(0.0, clamp_to_positive(-1), "should clamp a negative value to zero")
224
+ assert_equal(1232, clamp_to_positive(1232), "should pass through the value when it is positive")
225
+ assert_equal(0, clamp_to_positive(0), "should not mess with zero when passing it through")
226
+ end
227
+
228
+ def test_browser_monitoring_app_time_nonzero
229
+ start = Time.now
230
+ self.expects(:browser_monitoring_start_time).returns(start - 1)
231
+ Time.expects(:now).returns(start)
232
+ assert_equal(1000, browser_monitoring_app_time, 'should return a rounded time')
233
+ end
234
+
235
+ def test_browser_monitoring_queue_time_nil
236
+ assert_equal(0.0, browser_monitoring_queue_time, 'should return zero when there is no queue time')
237
+ end
238
+
239
+ def test_browser_monitoring_queue_time_zero
240
+ frame = Thread.current[:last_metric_frame] = mock('metric frame')
241
+ frame.expects(:queue_time).returns(0.0)
242
+ assert_equal(0.0, browser_monitoring_queue_time, 'should return zero when there is zero queue time')
243
+ end
244
+
245
+ def test_browser_monitoring_queue_time_ducks
246
+ frame = Thread.current[:last_metric_frame] = mock('metric frame')
247
+ frame.expects(:queue_time).returns('a duck')
248
+ assert_equal(0.0, browser_monitoring_queue_time, 'should return zero when there is an incorrect queue time')
249
+ end
250
+
251
+ def test_browser_monitoring_queue_time_nonzero
252
+ frame = Thread.current[:last_metric_frame] = mock('metric frame')
253
+ frame.expects(:queue_time).returns(3.00002)
254
+ assert_equal(3000, browser_monitoring_queue_time, 'should return a rounded time')
255
+ end
256
+
257
+ def test_footer_js_string_basic
258
+ beacon = ''
259
+ license_key = ''
260
+ application_id = 1
261
+
262
+ # mocking this because JRuby thinks that Time.now - Time.now
263
+ # always takes at least 1ms
264
+ self.expects(:browser_monitoring_app_time).returns(0)
265
+ frame = Thread.current[:last_metric_frame] = mock('metric frame')
266
+ user_attributes = {:user => "user", :account => "account", :product => "product"}
267
+ frame.expects(:user_attributes).returns(user_attributes).at_least_once
268
+ frame.expects(:queue_time).returns(0)
269
+
270
+ sample = mock('transaction info')
271
+ NewRelic::Agent::TransactionInfo.set(sample)
272
+
273
+ sample.stubs(:start_time).returns(Time.at(100))
274
+ sample.stubs(:guid).returns('ABC')
275
+ sample.stubs(:transaction_name).returns('most recent transaction')
276
+ sample.stubs(:include_guid?).returns(true)
277
+ sample.stubs(:duration).returns(12.0)
278
+ sample.stubs(:token).returns('0123456789ABCDEF')
279
+
280
+ self.expects(:obfuscate).with(NewRelic::Agent.instance.beacon_configuration, 'most recent transaction').returns('most recent transaction')
281
+ self.expects(:obfuscate).with(NewRelic::Agent.instance.beacon_configuration, 'user').returns('user')
282
+ self.expects(:obfuscate).with(NewRelic::Agent.instance.beacon_configuration, 'account').returns('account')
283
+ self.expects(:obfuscate).with(NewRelic::Agent.instance.beacon_configuration, 'product').returns('product')
284
+
285
+ value = footer_js_string(NewRelic::Agent.instance.beacon_configuration, beacon, license_key, application_id)
286
+ assert_equal("<script type=\"text/javascript\">if (!NREUMQ.f) { NREUMQ.f=function() {\nNREUMQ.push([\"load\",new Date().getTime()]);\nvar e=document.createElement(\"script\");\ne.type=\"text/javascript\";e.async=true;e.src=\"this_is_my_file\";\ndocument.body.appendChild(e);\nif(NREUMQ.a)NREUMQ.a();\n};\nNREUMQ.a=window.onload;window.onload=NREUMQ.f;\n};\nNREUMQ.push([\"nrfj\",\"\",\"\",1,\"most recent transaction\",0,0,new Date().getTime(),\"ABC\",\"0123456789ABCDEF\",\"user\",\"account\",\"product\"])</script>", value, "should return the javascript given some default values")
287
+ end
288
+
289
+ def test_html_safe_if_needed_unsafed
290
+ string = mock('string')
291
+ # here to handle 1.9 encoding - we stub this out because it should
292
+ # be handled automatically and is outside the scope of this test
293
+ string.stubs(:respond_to?).with(:encoding).returns(false)
294
+ string.expects(:respond_to?).with(:html_safe).returns(false)
295
+ assert_equal(string, html_safe_if_needed(string))
296
+ end
297
+
298
+ def test_html_safe_if_needed_safed
299
+ string = mock('string')
300
+ string.expects(:respond_to?).with(:html_safe).returns(true)
301
+ string.expects(:html_safe).returns(string)
302
+ # here to handle 1.9 encoding - we stub this out because it should
303
+ # be handled automatically and is outside the scope of this test
304
+ string.stubs(:respond_to?).with(:encoding).returns(false)
305
+ assert_equal(string, html_safe_if_needed(string))
306
+ end
307
+
308
+ def test_obfuscate_basic
309
+ text = 'a happy piece of small text'
310
+ key = (1..40).to_a
311
+ NewRelic::Agent.instance.beacon_configuration.expects(:license_bytes).returns(key)
312
+ output = obfuscate(NewRelic::Agent.instance.beacon_configuration, text)
313
+ assert_equal('YCJrZXV2fih5Y25vaCFtZSR2a2ZkZSp/aXV1', output, "should output obfuscated text")
314
+ end
315
+
316
+ def test_obfuscate_long_string
317
+ text = 'a happy piece of small text' * 5
318
+ key = (1..40).to_a
319
+ NewRelic::Agent.instance.beacon_configuration.expects(:license_bytes).returns(key)
320
+ output = obfuscate(NewRelic::Agent.instance.beacon_configuration, text)
321
+ assert_equal('YCJrZXV2fih5Y25vaCFtZSR2a2ZkZSp/aXV1YyNsZHZ3cSl6YmluZCJsYiV1amllZit4aHl2YiRtZ3d4cCp7ZWhiZyNrYyZ0ZWhmZyx5ZHp3ZSVuZnh5cyt8ZGRhZiRqYCd7ZGtnYC11Z3twZCZvaXl6cix9aGdgYSVpYSh6Z2pgYSF2Znxx', output, "should output obfuscated text")
322
+ end
323
+ end
@@ -0,0 +1,81 @@
1
+ # Run faster standalone
2
+ ENV['SKIP_RAILS'] = 'true'
3
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
4
+ class NewRelic::Agent::BusyCalculatorTest < Test::Unit::TestCase
5
+ attr_reader :now
6
+ def setup
7
+ @now = Time.now.to_f
8
+ NewRelic::Agent::BusyCalculator.reset
9
+ @instance_busy = NewRelic::MethodTraceStats.new
10
+ NewRelic::Agent::BusyCalculator.stubs(:instance_busy_stats).returns(@instance_busy)
11
+ end
12
+
13
+ def test_normal
14
+ # start the timewindow 10 seconds ago
15
+ # start a request at 10 seconds, 5 seconds long
16
+ NewRelic::Agent::BusyCalculator.stubs(:harvest_start).returns(now - 10.0)
17
+ NewRelic::Agent::BusyCalculator.dispatcher_start(now - 10.0)
18
+ NewRelic::Agent::BusyCalculator.dispatcher_finish(now - 5.0)
19
+ assert_equal 5, NewRelic::Agent::BusyCalculator.accumulator
20
+ NewRelic::Agent::BusyCalculator.harvest_busy
21
+
22
+ assert_equal 1, @instance_busy.call_count
23
+ assert_in_delta 0.50, @instance_busy.total_call_time, 0.05
24
+ end
25
+ def test_split
26
+ # start the timewindow 10 seconds ago
27
+ # start a request at 5 seconds, don't finish
28
+ NewRelic::Agent::BusyCalculator.stubs(:harvest_start).returns(now - 10.0)
29
+ NewRelic::Agent::BusyCalculator.dispatcher_start(now - 5.0)
30
+ NewRelic::Agent::BusyCalculator.harvest_busy
31
+
32
+ assert_equal 1, @instance_busy.call_count, @instance_busy
33
+ assert_in_delta 0.50, @instance_busy.total_call_time, 0.05
34
+ end
35
+ def test_reentrancy
36
+ # start the timewindow 10 seconds ago
37
+ # start a request at 5 seconds, don't finish, but make two more
38
+ # complete calls, which should be ignored.
39
+ NewRelic::Agent::BusyCalculator.stubs(:harvest_start).returns(now - 10.0)
40
+ NewRelic::Agent::BusyCalculator.dispatcher_start(now - 5.0)
41
+ NewRelic::Agent::BusyCalculator.dispatcher_start(now - 4.5)
42
+ NewRelic::Agent::BusyCalculator.dispatcher_start(now - 4.0)
43
+ NewRelic::Agent::BusyCalculator.dispatcher_finish(now - 3.5)
44
+ NewRelic::Agent::BusyCalculator.dispatcher_finish(now - 3.0)
45
+ NewRelic::Agent::BusyCalculator.dispatcher_start(now - 2.0)
46
+ NewRelic::Agent::BusyCalculator.dispatcher_finish(now - 1.0)
47
+ NewRelic::Agent::BusyCalculator.harvest_busy
48
+
49
+ assert_equal 1, @instance_busy.call_count
50
+ assert_in_delta 0.50, @instance_busy.total_call_time, 0.05
51
+ end
52
+ def test_concurrency
53
+ # start the timewindow 10 seconds ago
54
+ # start a request at 10 seconds, 5 seconds long
55
+ NewRelic::Agent::BusyCalculator.stubs(:harvest_start).returns(now - 10.0)
56
+ NewRelic::Agent::BusyCalculator.dispatcher_start(now - 8.0)
57
+ worker = Thread.new do
58
+ # Get busy for 6 - 3 seconds
59
+ NewRelic::Agent::BusyCalculator.dispatcher_start(now - 6.0)
60
+ NewRelic::Agent::BusyCalculator.dispatcher_start(now - 5.0)
61
+ NewRelic::Agent::BusyCalculator.dispatcher_finish(now - 4.0)
62
+ NewRelic::Agent::BusyCalculator.dispatcher_finish(now - 3.0)
63
+ end
64
+ # Get busy for 8 - 2 seconds
65
+ NewRelic::Agent::BusyCalculator.dispatcher_finish(now - 2.0)
66
+ worker.join
67
+ NewRelic::Agent::BusyCalculator.harvest_busy
68
+
69
+ assert_equal 1, @instance_busy.call_count
70
+ # 3 + 6 = 9, or 90%
71
+ assert_in_delta 0.90, @instance_busy.total_call_time, 0.1
72
+
73
+ end
74
+ def test_dont_ignore_zero_counts
75
+ assert_equal 0, @instance_busy.call_count, "Problem with test--instance busy not starting off at zero."
76
+ NewRelic::Agent::BusyCalculator.harvest_busy
77
+ NewRelic::Agent::BusyCalculator.harvest_busy
78
+ NewRelic::Agent::BusyCalculator.harvest_busy
79
+ assert_equal 3, @instance_busy.call_count
80
+ end
81
+ end