wd_newrelic_rpm 3.3.4.1 → 3.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (290) hide show
  1. data/.gitignore +20 -0
  2. data/.project +23 -0
  3. data/.travis.yml +9 -0
  4. data/CHANGELOG +317 -39
  5. data/GUIDELINES_FOR_CONTRIBUTING.md +76 -0
  6. data/Gemfile +16 -0
  7. data/LICENSE +1 -1
  8. data/{README.rdoc → README.md} +71 -55
  9. data/Rakefile +62 -0
  10. data/bin/mongrel_rpm +1 -1
  11. data/config.dot +290 -0
  12. data/config/database.yml +5 -0
  13. data/init.rb +31 -0
  14. data/lib/new_relic/agent.rb +31 -60
  15. data/lib/new_relic/agent/agent.rb +277 -502
  16. data/lib/new_relic/agent/agent_logger.rb +165 -0
  17. data/lib/new_relic/agent/audit_logger.rb +72 -0
  18. data/lib/new_relic/agent/beacon_configuration.rb +36 -50
  19. data/lib/new_relic/agent/browser_monitoring.rb +114 -61
  20. data/lib/new_relic/agent/busy_calculator.rb +14 -6
  21. data/lib/new_relic/agent/configuration.rb +74 -0
  22. data/lib/new_relic/agent/configuration/defaults.rb +126 -0
  23. data/lib/new_relic/agent/configuration/environment_source.rb +49 -0
  24. data/lib/new_relic/agent/configuration/manager.rb +136 -0
  25. data/lib/new_relic/agent/configuration/mask_defaults.rb +10 -0
  26. data/lib/new_relic/agent/configuration/server_source.rb +27 -0
  27. data/lib/new_relic/agent/configuration/yaml_source.rb +63 -0
  28. data/lib/new_relic/agent/cross_process_monitoring.rb +43 -0
  29. data/lib/new_relic/agent/database.rb +39 -26
  30. data/lib/new_relic/agent/error_collector.rb +48 -49
  31. data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
  32. data/lib/new_relic/agent/instrumentation/active_record.rb +4 -7
  33. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +1 -1
  34. data/lib/new_relic/agent/instrumentation/authlogic.rb +1 -1
  35. data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +41 -0
  36. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +35 -12
  37. data/lib/new_relic/agent/instrumentation/data_mapper.rb +4 -12
  38. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +2 -2
  39. data/lib/new_relic/agent/instrumentation/memcache.rb +6 -6
  40. data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
  41. data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
  42. data/lib/new_relic/agent/instrumentation/metric_frame.rb +4 -14
  43. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +1 -1
  44. data/lib/new_relic/agent/instrumentation/net.rb +1 -1
  45. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +6 -20
  46. data/lib/new_relic/agent/instrumentation/queue_time.rb +2 -2
  47. data/lib/new_relic/agent/instrumentation/rack.rb +1 -1
  48. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +7 -7
  49. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
  50. data/lib/new_relic/agent/instrumentation/rails/errors.rb +1 -1
  51. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +5 -5
  52. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +6 -2
  53. data/lib/new_relic/agent/instrumentation/resque.rb +81 -0
  54. data/lib/new_relic/agent/instrumentation/sinatra.rb +21 -10
  55. data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
  56. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +5 -4
  57. data/lib/new_relic/agent/method_tracer.rb +11 -9
  58. data/lib/new_relic/agent/new_relic_service.rb +379 -0
  59. data/lib/new_relic/agent/pipe_channel_manager.rb +175 -0
  60. data/lib/new_relic/agent/pipe_service.rb +58 -0
  61. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +86 -0
  62. data/lib/new_relic/agent/samplers/memory_sampler.rb +6 -8
  63. data/lib/new_relic/agent/sql_sampler.rb +31 -74
  64. data/lib/new_relic/agent/stats_engine.rb +0 -5
  65. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +40 -24
  66. data/lib/new_relic/agent/stats_engine/metric_stats.rb +89 -14
  67. data/lib/new_relic/agent/stats_engine/samplers.rb +9 -7
  68. data/lib/new_relic/agent/stats_engine/transactions.rb +20 -12
  69. data/lib/new_relic/agent/thread.rb +32 -0
  70. data/lib/new_relic/agent/thread_profiler.rb +306 -0
  71. data/lib/new_relic/agent/transaction_info.rb +24 -4
  72. data/lib/new_relic/agent/transaction_sample_builder.rb +12 -13
  73. data/lib/new_relic/agent/transaction_sampler.rb +49 -65
  74. data/lib/new_relic/agent/worker_loop.rb +31 -25
  75. data/lib/new_relic/collection_helper.rb +1 -1
  76. data/lib/new_relic/commands/deployments.rb +19 -10
  77. data/lib/new_relic/control.rb +1 -3
  78. data/lib/new_relic/control/class_methods.rb +10 -5
  79. data/lib/new_relic/control/frameworks/merb.rb +0 -6
  80. data/lib/new_relic/control/frameworks/rails.rb +30 -45
  81. data/lib/new_relic/control/frameworks/rails3.rb +23 -18
  82. data/lib/new_relic/control/frameworks/rails4.rb +23 -0
  83. data/lib/new_relic/control/frameworks/ruby.rb +2 -23
  84. data/lib/new_relic/control/instance_methods.rb +35 -73
  85. data/lib/new_relic/control/instrumentation.rb +7 -12
  86. data/lib/new_relic/control/server_methods.rb +17 -19
  87. data/lib/new_relic/delayed_job_injection.rb +2 -2
  88. data/lib/new_relic/helper.rb +34 -0
  89. data/lib/new_relic/language_support.rb +56 -37
  90. data/lib/new_relic/local_environment.rb +32 -67
  91. data/lib/new_relic/metric_data.rb +10 -2
  92. data/lib/new_relic/metric_spec.rb +7 -3
  93. data/lib/new_relic/noticed_error.rb +32 -9
  94. data/lib/new_relic/rack.rb +4 -0
  95. data/lib/new_relic/rack/browser_monitoring.rb +34 -25
  96. data/lib/new_relic/rack/developer_mode.rb +3 -0
  97. data/lib/new_relic/rack/error_collector.rb +56 -0
  98. data/lib/new_relic/stats.rb +9 -7
  99. data/lib/new_relic/transaction_sample.rb +19 -18
  100. data/lib/new_relic/transaction_sample/segment.rb +13 -15
  101. data/lib/new_relic/version.rb +19 -3
  102. data/lib/newrelic_rpm.rb +1 -1
  103. data/lib/tasks/tests.rake +6 -8
  104. data/newrelic.yml +15 -32
  105. data/newrelic_rpm.gemspec +224 -43
  106. data/newrelic_rpm.gemspec.erb +54 -0
  107. data/test/config/newrelic.yml +4 -3
  108. data/test/config/test_control.rb +18 -18
  109. data/test/fixtures/gemspec_no_build.rb +442 -0
  110. data/test/fixtures/gemspec_with_build.rb +442 -0
  111. data/test/fixtures/gemspec_with_build_and_stage.rb +442 -0
  112. data/test/intentional_fail.rb +10 -0
  113. data/test/multiverse/.gitignore +10 -0
  114. data/test/multiverse/README.md +85 -0
  115. data/test/multiverse/lib/multiverse/color.rb +13 -0
  116. data/test/multiverse/lib/multiverse/envfile.rb +66 -0
  117. data/test/multiverse/lib/multiverse/environment.rb +16 -0
  118. data/test/multiverse/lib/multiverse/output_collector.rb +29 -0
  119. data/test/multiverse/lib/multiverse/runner.rb +44 -0
  120. data/test/multiverse/lib/multiverse/suite.rb +162 -0
  121. data/test/multiverse/script/run_one +3 -0
  122. data/test/multiverse/script/runner +9 -0
  123. data/test/multiverse/suites/active_record/Envfile +13 -0
  124. data/test/multiverse/suites/active_record/ar_method_aliasing.rb +94 -0
  125. data/test/multiverse/suites/active_record/config/newrelic.yml +22 -0
  126. data/test/multiverse/suites/active_record/encoding_test.rb +26 -0
  127. data/test/multiverse/suites/agent_only/Envfile +4 -0
  128. data/test/multiverse/suites/agent_only/audit_log_test.rb +99 -0
  129. data/test/multiverse/suites/agent_only/config/newrelic.yml +22 -0
  130. data/test/multiverse/suites/agent_only/http_response_code_test.rb +53 -0
  131. data/test/multiverse/suites/agent_only/marshaling_test.rb +109 -0
  132. data/test/multiverse/suites/agent_only/method_visibility_test.rb +98 -0
  133. data/test/multiverse/suites/agent_only/pipe_manager_test.rb +33 -0
  134. data/test/multiverse/suites/agent_only/service_timeout_test.rb +29 -0
  135. data/test/multiverse/suites/agent_only/test_trace_method_with_punctuation.rb +30 -0
  136. data/test/multiverse/suites/agent_only/test_trace_transaction_with_punctuation.rb +32 -0
  137. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +80 -0
  138. data/test/multiverse/suites/config_file_loading/Envfile +7 -0
  139. data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +106 -0
  140. data/test/multiverse/suites/datamapper/Envfile +8 -0
  141. data/test/multiverse/suites/datamapper/config/newrelic.yml +22 -0
  142. data/test/multiverse/suites/datamapper/encoding_test.rb +36 -0
  143. data/test/multiverse/suites/logging/Envfile +4 -0
  144. data/test/multiverse/suites/logging/config/newrelic.yml +22 -0
  145. data/test/multiverse/suites/logging/logging_test.rb +143 -0
  146. data/test/multiverse/suites/monitor_mode_false/Envfile +2 -0
  147. data/test/multiverse/suites/monitor_mode_false/config/newrelic.yml +25 -0
  148. data/test/multiverse/suites/monitor_mode_false/no_dns_resolv.rb +29 -0
  149. data/test/multiverse/suites/no_load/Envfile +2 -0
  150. data/test/multiverse/suites/no_load/config/newrelic.yml +22 -0
  151. data/test/multiverse/suites/no_load/start_up_test.rb +14 -0
  152. data/test/multiverse/suites/rails_3_error_tracing/Envfile +15 -0
  153. data/test/multiverse/suites/rails_3_error_tracing/config/newrelic.yml +165 -0
  154. data/test/multiverse/suites/rails_3_error_tracing/error_tracing_test.rb +236 -0
  155. data/test/multiverse/suites/rails_3_gc/Envfile +8 -0
  156. data/test/multiverse/suites/rails_3_gc/config/newrelic.yml +167 -0
  157. data/test/multiverse/suites/rails_3_gc/instrumentation_test.rb +92 -0
  158. data/test/multiverse/suites/rails_3_queue_time/Envfile +15 -0
  159. data/test/multiverse/suites/rails_3_queue_time/config/newrelic.yml +165 -0
  160. data/test/multiverse/suites/rails_3_queue_time/queue_time_test.rb +75 -0
  161. data/test/multiverse/suites/rails_3_views/.gitignore +3 -0
  162. data/test/multiverse/suites/rails_3_views/Envfile +16 -0
  163. data/test/multiverse/suites/rails_3_views/app/views/foos/_foo.html.haml +1 -0
  164. data/test/multiverse/suites/rails_3_views/app/views/test/_a_partial.html.erb +1 -0
  165. data/test/multiverse/suites/rails_3_views/app/views/test/_mid_partial.html.erb +1 -0
  166. data/test/multiverse/suites/rails_3_views/app/views/test/_top_partial.html.erb +3 -0
  167. data/test/multiverse/suites/rails_3_views/app/views/test/deep_partial.html.erb +3 -0
  168. data/test/multiverse/suites/rails_3_views/app/views/test/haml_view.html.haml +6 -0
  169. data/test/multiverse/suites/rails_3_views/app/views/test/index.html.erb +4 -0
  170. data/test/multiverse/suites/rails_3_views/config/newrelic.yml +164 -0
  171. data/test/multiverse/suites/rails_3_views/view_instrumentation_test.rb +245 -0
  172. data/test/multiverse/suites/resque/Envfile +21 -0
  173. data/test/multiverse/suites/resque/config/newrelic.yml +22 -0
  174. data/test/multiverse/suites/resque/dump.rdb +0 -0
  175. data/test/multiverse/suites/resque/instrumentation_test.rb +73 -0
  176. data/test/multiverse/suites/rum_auto_instrumentation/Envfile +4 -0
  177. data/test/multiverse/suites/rum_auto_instrumentation/config/newrelic.yml +24 -0
  178. data/test/multiverse/suites/rum_auto_instrumentation/responses/worst_case_small.html +5000 -0
  179. data/test/multiverse/suites/rum_auto_instrumentation/sanity_test.rb +102 -0
  180. data/test/multiverse/suites/sinatra/Envfile +13 -0
  181. data/test/multiverse/suites/sinatra/config/newrelic.yml +24 -0
  182. data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +77 -0
  183. data/test/multiverse/suites/sinatra/sinatra_routes_test.rb +46 -0
  184. data/test/multiverse/suites/sinatra/sinatra_test.rb +55 -0
  185. data/test/multiverse/test/multiverse_test.rb +55 -0
  186. data/test/multiverse/test/suite_examples/one/a/Envfile +3 -0
  187. data/test/multiverse/test/suite_examples/one/a/a_test.rb +11 -0
  188. data/test/multiverse/test/suite_examples/one/a/config/newrelic.yml +24 -0
  189. data/test/multiverse/test/suite_examples/one/b/Envfile +3 -0
  190. data/test/multiverse/test/suite_examples/one/b/b_test.rb +11 -0
  191. data/test/multiverse/test/suite_examples/one/b/config/newrelic.yml +24 -0
  192. data/test/multiverse/test/suite_examples/three/a/Envfile +2 -0
  193. data/test/multiverse/test/suite_examples/three/a/fail_test.rb +6 -0
  194. data/test/multiverse/test/suite_examples/three/b/Envfile +2 -0
  195. data/test/multiverse/test/suite_examples/three/b/win_test.rb +6 -0
  196. data/test/multiverse/test/suite_examples/two/a/Envfile +1 -0
  197. data/test/multiverse/test/suite_examples/two/a/fail_test.rb +6 -0
  198. data/test/new_relic/agent/agent/connect_test.rb +151 -227
  199. data/test/new_relic/agent/agent/start_test.rb +68 -118
  200. data/test/new_relic/agent/agent/start_worker_thread_test.rb +12 -74
  201. data/test/new_relic/agent/agent_logger_test.rb +153 -0
  202. data/test/new_relic/agent/agent_test.rb +116 -30
  203. data/test/new_relic/agent/agent_test_controller.rb +1 -1
  204. data/test/new_relic/agent/agent_test_controller_test.rb +42 -10
  205. data/test/new_relic/agent/audit_logger_test.rb +105 -0
  206. data/test/new_relic/agent/beacon_configuration_test.rb +63 -67
  207. data/test/new_relic/agent/browser_monitoring_test.rb +151 -79
  208. data/test/new_relic/agent/busy_calculator_test.rb +7 -0
  209. data/test/new_relic/agent/configuration/environment_source_test.rb +79 -0
  210. data/test/new_relic/agent/configuration/manager_test.rb +204 -0
  211. data/test/new_relic/agent/configuration/server_source_test.rb +45 -0
  212. data/test/new_relic/agent/configuration/yaml_source_test.rb +75 -0
  213. data/test/new_relic/agent/cross_process_monitoring_test.rb +77 -0
  214. data/test/new_relic/agent/database_test.rb +12 -11
  215. data/test/new_relic/agent/error_collector/notice_error_test.rb +64 -53
  216. data/test/new_relic/agent/error_collector_test.rb +33 -19
  217. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +60 -30
  218. data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +39 -0
  219. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +1 -1
  220. data/test/new_relic/agent/instrumentation/metric_frame_test.rb +6 -0
  221. data/test/new_relic/agent/instrumentation/queue_time_test.rb +14 -0
  222. data/test/new_relic/agent/instrumentation/sinatra_test.rb +25 -0
  223. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +2 -2
  224. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +4 -10
  225. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +3 -15
  226. data/test/new_relic/agent/method_tracer_test.rb +7 -6
  227. data/test/new_relic/agent/mock_scope_listener.rb +3 -0
  228. data/test/new_relic/agent/new_relic_service_test.rb +376 -0
  229. data/test/new_relic/agent/pipe_channel_manager_test.rb +131 -0
  230. data/test/new_relic/agent/pipe_service_test.rb +113 -0
  231. data/test/new_relic/agent/rpm_agent_test.rb +27 -50
  232. data/test/new_relic/agent/sql_sampler_test.rb +81 -56
  233. data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +3 -20
  234. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +12 -1
  235. data/test/new_relic/agent/stats_engine_test.rb +17 -8
  236. data/test/new_relic/agent/thread_profiler_test.rb +537 -0
  237. data/test/new_relic/agent/thread_test.rb +89 -0
  238. data/test/new_relic/agent/threaded_test.rb +65 -0
  239. data/test/new_relic/agent/transaction_info_test.rb +45 -4
  240. data/test/new_relic/agent/transaction_sample_builder_test.rb +8 -7
  241. data/test/new_relic/agent/transaction_sampler_test.rb +193 -204
  242. data/test/new_relic/agent/worker_loop_test.rb +26 -11
  243. data/test/new_relic/agent_test.rb +113 -33
  244. data/test/new_relic/collection_helper_test.rb +7 -8
  245. data/test/new_relic/command/deployments_test.rb +18 -2
  246. data/test/new_relic/control/class_methods_test.rb +0 -18
  247. data/test/new_relic/control/frameworks/rails_test.rb +26 -0
  248. data/test/new_relic/control_test.rb +96 -137
  249. data/test/new_relic/delayed_job_injection_test.rb +6 -1
  250. data/test/new_relic/dispatcher_test.rb +54 -0
  251. data/test/new_relic/fake_collector.rb +283 -0
  252. data/test/new_relic/fake_service.rb +53 -0
  253. data/test/new_relic/fakes_sending_data.rb +30 -0
  254. data/test/new_relic/framework_test.rb +53 -0
  255. data/test/new_relic/load_test.rb +13 -0
  256. data/test/new_relic/local_environment_test.rb +11 -11
  257. data/test/new_relic/metric_data_test.rb +45 -16
  258. data/test/new_relic/noticed_error_test.rb +24 -0
  259. data/test/new_relic/rack/browser_monitoring_test.rb +20 -10
  260. data/test/new_relic/rack/developer_mode_test.rb +13 -7
  261. data/test/new_relic/rack/error_collector_test.rb +74 -0
  262. data/test/new_relic/stats_test.rb +10 -0
  263. data/test/new_relic/transaction_sample/segment_test.rb +23 -4
  264. data/test/new_relic/transaction_sample_test.rb +47 -2
  265. data/test/new_relic/version_number_test.rb +32 -0
  266. data/test/script/build_test_gem.sh +9 -3
  267. data/test/script/ci.sh +108 -35
  268. data/test/script/ci_agent-tests_runner.sh +82 -0
  269. data/test/script/ci_multiverse_runner.sh +63 -0
  270. data/test/test_contexts.rb +1 -0
  271. data/test/test_helper.rb +68 -18
  272. data/ui/helpers/developer_mode_helper.rb +21 -11
  273. data/ui/views/layouts/newrelic_default.rhtml +1 -0
  274. data/ui/views/newrelic/file/images/arrow-close.png +0 -0
  275. data/ui/views/newrelic/file/images/arrow-open.png +0 -0
  276. data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
  277. data/ui/views/newrelic/file/images/file_icon.png +0 -0
  278. data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
  279. data/ui/views/newrelic/show_sample.rhtml +1 -1
  280. data/ui/views/newrelic/threads.rhtml +2 -10
  281. data/vendor/gems/metric_parser-0.1.0.pre1/.specification +116 -0
  282. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_init.rb +7 -0
  283. metadata +191 -65
  284. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +0 -40
  285. data/lib/new_relic/control/configuration.rb +0 -206
  286. data/lib/new_relic/control/logging_methods.rb +0 -143
  287. data/lib/new_relic/data_serialization.rb +0 -151
  288. data/test/new_relic/control/configuration_test.rb +0 -84
  289. data/test/new_relic/control/logging_methods_test.rb +0 -185
  290. data/test/new_relic/data_serialization_test.rb +0 -208
@@ -1,30 +1,38 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
+ require 'new_relic/agent/thread_profiler'
3
+
2
4
  module NewRelic
3
5
  module Agent
4
6
  class AgentTest < Test::Unit::TestCase
5
-
6
7
  def setup
7
8
  super
8
9
  @agent = NewRelic::Agent::Agent.new
10
+ @agent.service = NewRelic::FakeService.new
9
11
  end
10
12
 
11
- def test_save_or_transmit_data_should_save
12
- NewRelic::Agent.expects(:save_data).once
13
- @agent.expects(:harvest_and_send_timeslice_data).never
14
- NewRelic::DataSerialization.expects(:should_send_data?).returns(false)
15
- @agent.instance_eval { save_or_transmit_data }
13
+ def test_after_fork_reporting_to_channel
14
+ @agent.after_fork(:report_to_channel => 123)
15
+ assert(@agent.service.kind_of?(NewRelic::Agent::PipeService),
16
+ 'Agent should use PipeService when directed to report to pipe channel')
17
+ assert_equal 123, @agent.service.channel_id
16
18
  end
17
-
18
- def test_save_or_transmit_data_should_transmit
19
- NewRelic::Control.instance.stubs(:disable_serialization?).returns(false)
20
- NewRelic::Agent.expects(:load_data)
21
- @agent.expects(:harvest_and_send_timeslice_data)
22
- @agent.expects(:harvest_and_send_slowest_sample)
23
- @agent.expects(:harvest_and_send_errors)
24
- NewRelic::DataSerialization.expects(:should_send_data?).returns(true)
25
- @agent.instance_eval { save_or_transmit_data }
19
+
20
+ def test_transmit_data_should_transmit
21
+ @agent.instance_eval { transmit_data }
22
+ assert @agent.service.agent_data.any?
23
+ end
24
+
25
+ def test_transmit_data_should_close_explain_db_connections
26
+ NewRelic::Agent::Database.expects(:close_connections)
27
+ @agent.instance_eval { transmit_data }
26
28
  end
27
-
29
+
30
+ def test_transmit_data_should_not_close_db_connections_if_forked
31
+ NewRelic::Agent::Database.expects(:close_connections).never
32
+ @agent.after_fork
33
+ @agent.instance_eval { transmit_data }
34
+ end
35
+
28
36
  def test_serialize
29
37
  assert_equal([{}, [], []], @agent.send(:serialize), "should return nil when shut down")
30
38
  end
@@ -33,6 +41,61 @@ module NewRelic
33
41
  assert_equal([], @agent.send(:harvest_transaction_traces), 'should return transaction traces')
34
42
  end
35
43
 
44
+ def test_harvest_and_send_slowest_sample
45
+ with_config(:'transaction_tracer.explain_threshold' => 2,
46
+ :'transaction_tracer.explain_enabled' => true,
47
+ :'transaction_tracer.record_sql' => 'raw') do
48
+ trace = stub('transaction trace', :force_persist => true,
49
+ :truncate => 4000)
50
+ trace.expects(:prepare_to_send).with(:record_sql => :raw,
51
+ :explain_sql => 2,
52
+ :keep_backtraces => true)
53
+ @agent.instance_variable_set(:@traces, [ trace ])
54
+ @agent.send :harvest_and_send_slowest_sample
55
+ end
56
+ end
57
+
58
+ def test_graceful_shutdown_ends_thread_profiling
59
+ @agent.thread_profiler.expects(:stop).once
60
+ @agent.instance_variable_set(:@connected, true)
61
+
62
+ @agent.send(:graceful_disconnect)
63
+ end
64
+
65
+ def test_harvest_and_send_thread_profile
66
+ profile = with_profile(:finished => true)
67
+ @agent.send(:harvest_and_send_thread_profile, false)
68
+
69
+ assert_equal([profile],
70
+ @agent.service.agent_data \
71
+ .find{|data| data.action == :profile_data}.params)
72
+ end
73
+
74
+ def test_harvest_and_send_thread_profile_when_not_finished
75
+ with_profile(:finished => false)
76
+ @agent.send(:harvest_and_send_thread_profile, false)
77
+
78
+ assert_nil @agent.service.agent_data.find{|data| data.action == :profile_data}
79
+ end
80
+
81
+ def test_harvest_and_send_thread_profile_when_not_finished_but_disconnecting
82
+ profile = with_profile(:finished => false)
83
+ @agent.send(:harvest_and_send_thread_profile, true)
84
+
85
+ assert_equal([profile],
86
+ @agent.service.agent_data \
87
+ .find{|data| data.action == :profile_data}.params)
88
+ end
89
+
90
+ def with_profile(opts)
91
+ profile = NewRelic::Agent::ThreadProfile.new(-1, 0, 0, true)
92
+ profile.aggregate(["chunky.rb:42:in `bacon'"], profile.traces[:other])
93
+ profile.instance_variable_set(:@finished, opts[:finished])
94
+
95
+ @agent.thread_profiler.instance_variable_set(:@profile, profile)
96
+ profile
97
+ end
98
+
36
99
  def test_harvest_timeslice_data
37
100
  assert_equal({}, @agent.send(:harvest_timeslice_data),
38
101
  'should return timeslice data')
@@ -42,15 +105,17 @@ module NewRelic
42
105
  2000.times do |i|
43
106
  @agent.stats_engine.stats_hash[i.to_s] = NewRelic::StatsBase.new
44
107
  end
45
-
46
- harvest = Thread.new do
108
+
109
+ harvest = Thread.new("Harvesting Test run timeslices") do
47
110
  @agent.send(:harvest_timeslice_data)
48
111
  end
49
112
 
50
- app = Thread.new do
51
- @agent.stats_engine.stats_hash["a"] = NewRelic::StatsBase.new
113
+ app = Thread.new("Harvesting Test Modify stats_hash") do
114
+ 200.times do |i|
115
+ @agent.stats_engine.stats_hash["a#{i}"] = NewRelic::StatsBase.new
116
+ end
52
117
  end
53
-
118
+
54
119
  assert_nothing_raised do
55
120
  [app, harvest].each{|t| t.join}
56
121
  end
@@ -60,6 +125,11 @@ module NewRelic
60
125
  assert_equal([], @agent.send(:harvest_errors), 'should return errors')
61
126
  end
62
127
 
128
+ def test_check_for_agent_commands
129
+ @agent.send :check_for_agent_commands
130
+ assert_equal(1, @agent.service.calls_for(:get_agent_commands).size)
131
+ end
132
+
63
133
  def test_merge_data_from_empty
64
134
  unsent_timeslice_data = mock('unsent timeslice data')
65
135
  unsent_errors = mock('unsent errors')
@@ -86,7 +156,7 @@ module NewRelic
86
156
  }
87
157
  assert_equal(1, @agent.unsent_errors_size)
88
158
  end
89
-
159
+
90
160
  def test_unsent_traces_size_empty
91
161
  @agent.instance_eval {
92
162
  @traces = nil
@@ -115,7 +185,7 @@ module NewRelic
115
185
  }
116
186
  assert_equal(1, @agent.unsent_timeslice_data, "should have the key from above")
117
187
  end
118
-
188
+
119
189
  def test_merge_data_from_all_three_empty
120
190
  unsent_timeslice_data = mock('unsent timeslice data')
121
191
  unsent_errors = mock('unsent errors')
@@ -125,15 +195,31 @@ module NewRelic
125
195
  @unsent_timeslice_data = unsent_timeslice_data
126
196
  @traces = unsent_traces
127
197
  }
128
- unsent_errors.expects(:+).with([])
129
- unsent_traces.expects(:+).with([])
130
- @agent.merge_data_from([{}, [], []])
198
+ unsent_traces.expects(:+).with([1,2,3])
199
+ unsent_errors.expects(:+).with([4,5,6])
200
+ @agent.merge_data_from([{}, [1,2,3], [4,5,6]])
131
201
  end
132
202
 
133
- def test_should_not_log_log_file_location_if_no_log_file
134
- NewRelic::Control.instance.stubs(:log_file).returns('/vasrkjn4b3b4')
135
- @agent.expects(:log).never
136
- @agent.notify_log_file_location
203
+ def test_fill_metric_id_cache_from_collect_response
204
+ response = [[{"scope"=>"Controller/blogs/index", "name"=>"Database/SQL/other"}, 1328],
205
+ [{"scope"=>"", "name"=>"WebFrontend/QueueTime"}, 10],
206
+ [{"scope"=>"", "name"=>"ActiveRecord/Blog/find"}, 1017]]
207
+
208
+ @agent.send(:fill_metric_id_cache, response)
209
+ assert_equal 1328, @agent.metric_ids[MetricSpec.new('Database/SQL/other', 'Controller/blogs/index')]
210
+ assert_equal 10, @agent.metric_ids[MetricSpec.new('WebFrontend/QueueTime')]
211
+ assert_equal 1017, @agent.metric_ids[MetricSpec.new('ActiveRecord/Blog/find')]
212
+ end
213
+
214
+ def test_fill_metric_id_cache_from_collect_response
215
+ response = [[{"scope"=>"Controller/blogs/index", "name"=>"Database/SQL/other"}, 1328],
216
+ [{"scope"=>"", "name"=>"WebFrontend/QueueTime"}, 10],
217
+ [{"scope"=>"", "name"=>"ActiveRecord/Blog/find"}, 1017]]
218
+
219
+ @agent.send(:fill_metric_id_cache, response)
220
+ assert_equal 1328, @agent.metric_ids[MetricSpec.new('Database/SQL/other', 'Controller/blogs/index')]
221
+ assert_equal 10, @agent.metric_ids[MetricSpec.new('WebFrontend/QueueTime')]
222
+ assert_equal 1017, @agent.metric_ids[MetricSpec.new('ActiveRecord/Blog/find')]
137
223
  end
138
224
  end
139
225
  end
@@ -12,7 +12,7 @@ class NewRelic::Agent::AgentTestController < NewRelic::Agent::SuperclassControll
12
12
  @@headers_to_add = nil
13
13
 
14
14
  def index
15
- sleep params['wait'].to_i if params['wait']
15
+ sleep params['wait'].to_f if params['wait']
16
16
  render :text => params.inspect
17
17
  end
18
18
  def _filter_parameters(params)
@@ -7,7 +7,7 @@ class NewRelic::Agent::AgentTestControllerTest < ActionController::TestCase
7
7
  self.controller_class = NewRelic::Agent::AgentTestController
8
8
 
9
9
  attr_accessor :agent, :engine
10
-
10
+
11
11
  def test_initialization
12
12
  # Suggested by cee-dub for merb tests. I'm actually amazed if our tests work with merb.
13
13
  if defined?(Merb::Router)
@@ -23,7 +23,7 @@ class NewRelic::Agent::AgentTestControllerTest < ActionController::TestCase
23
23
  Rails.application.routes.draw do
24
24
  match '/:controller/:action.:format'
25
25
  match '/:controller/:action'
26
- end
26
+ end
27
27
  end
28
28
 
29
29
  if defined?(Rails) && Rails.respond_to?(:application) && Rails.application.respond_to?(:routes)
@@ -41,7 +41,7 @@ class NewRelic::Agent::AgentTestControllerTest < ActionController::TestCase
41
41
  end
42
42
  @engine = @agent.stats_engine
43
43
  end
44
-
44
+
45
45
  # Normally you can do this with #setup but for some reason in rails 2.0.2
46
46
  # setup is not called.
47
47
  if NewRelic::Control.instance.rails_version <= '2.1.0'
@@ -281,25 +281,57 @@ class NewRelic::Agent::AgentTestControllerTest < ActionController::TestCase
281
281
  def test_controller_params
282
282
  agent.transaction_sampler.reset!
283
283
  get :index, 'number' => "001-555-1212"
284
- s = agent.transaction_sampler.harvest(nil, 0.0)
284
+ s = with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
285
+ agent.transaction_sampler.harvest(nil)
286
+ end
285
287
  assert_equal 1, s.size
286
- assert_equal 6, s.first.params.size
288
+ assert_equal 5, s.first.params.size
287
289
  end
288
290
 
289
291
 
290
- def test_busycalculation
292
+ def test_busy_calculation_correctly_calculates_based_acccumlator
293
+
294
+ # woah it's 1970
295
+ now = Time.at 0
296
+
297
+ # We'll record two seconds of transactions
298
+ later = Time.at(now + 2)
299
+ NewRelic::Agent::BusyCalculator.stubs(:time_now).
300
+ returns(now).then.returns(later)
301
+
302
+ # reset harvest time to epoch (based on stub)
303
+ NewRelic::Agent::BusyCalculator.reset
304
+
305
+ # We record 1 second of busy time in our two seconds of wall clock
306
+ NewRelic::Agent::BusyCalculator.instance_variable_set(:@accumulator, 1.0)
307
+
308
+
309
+ NewRelic::Agent::BusyCalculator.harvest_busy
310
+
311
+ # smooth out floating point math
312
+ stat_int = (stats('Instance/Busy').total_call_time * 10).to_i
313
+
314
+ # Despite your expectations, #total_call_time is a percentage here.
315
+ assert_equal(stat_int, 5,
316
+ "#{stats('Instance/Busy').total_call_time} != 0.5")
317
+ end
318
+
319
+ def test_busy_calculation_generates_a_positive_value
291
320
  engine.clear_stats
292
- assert_equal 0, NewRelic::Agent::BusyCalculator.busy_count
293
321
  get :index, 'social_security_number' => "001-555-1212", 'wait' => '0.05'
294
322
  NewRelic::Agent::BusyCalculator.harvest_busy
295
323
 
296
324
  assert_equal 1, stats('Instance/Busy').call_count
297
325
  assert_equal 1, stats('HttpDispatcher').call_count
298
- # We are probably busy about 99% of the time, but lets make sure it's at least 50
299
- assert stats('Instance/Busy').total_call_time > (0.5 * 0.05), stats('Instance/Busy').inspect
326
+
327
+ # Timing is too non-deterministic, so we just assert a positive, non-zero
328
+ # value here. See
329
+ # #test_busy_calculation_correctly_calculates_based_acccumlator for
330
+ # assertions that the formula is correct.
331
+ assert(stats('Instance/Busy').total_call_time > 0,
332
+ "#{stats('Instance/Busy').total_call_time} !> 0")
300
333
  assert_equal 0, stats('WebFrontend/Mongrel/Average Queue Time').call_count
301
334
  end
302
-
303
335
  def test_queue_headers_no_header
304
336
  engine.clear_stats
305
337
  queue_length_stat = stats('Mongrel/Queue Length')
@@ -0,0 +1,105 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
+ require 'new_relic/agent/audit_logger'
3
+
4
+ class AuditLoggerTest < Test::Unit::TestCase
5
+ def setup
6
+ @config = {
7
+ :'audit_log.enabled' => true
8
+ }
9
+ @uri = "http://really.notreal"
10
+ @marshaller = NewRelic::Agent::NewRelicService::Marshaller.new
11
+ @hostname = 'dummyhost'
12
+ @dummy_data = {
13
+ 'foo' => [1, 2, 3],
14
+ 'bar' => {
15
+ 'baz' => 'qux',
16
+ 'jingle' => 'bells'
17
+ }
18
+ }
19
+ Socket.stubs(:gethostname).returns(@hostname)
20
+ end
21
+
22
+ def setup_fake_logger
23
+ @fakelog = StringIO.new
24
+ @logger = NewRelic::Agent::AuditLogger.new(@config)
25
+ @logger.stubs(:ensure_log_path).returns(@fakelog)
26
+ end
27
+
28
+ def assert_log_contains_string(str)
29
+ @fakelog.rewind
30
+ log_body = @fakelog.read
31
+ assert(log_body.include?(str), "Expected log to contain string '#{str}'")
32
+ end
33
+
34
+ def test_never_setup_if_disabled
35
+ config = { :'audit_log.enabled' => false }
36
+ logger = NewRelic::Agent::AuditLogger.new(config)
37
+ logger.log_request(@uri, "hi there", @marshaller)
38
+ assert(!logger.setup?, "Expected logger to not have been setup")
39
+ end
40
+
41
+ def test_never_prepare_if_disabled
42
+ config = { :'audit_log.enabled' => false }
43
+ logger = NewRelic::Agent::AuditLogger.new(config)
44
+ marshaller = NewRelic::Agent::NewRelicService::Marshaller.new
45
+ marshaller.expects(:prepare).never
46
+ logger.log_request(@uri, "hi there", @marshaller)
47
+ end
48
+
49
+ def test_log_formatter
50
+ formatter = NewRelic::Agent::AuditLogger.new(@config).log_formatter
51
+ time = '2012-01-01 00:00:00'
52
+ msg = 'hello'
53
+ result = formatter.call(Logger::INFO, time, 'bleh', msg)
54
+ expected = "[2012-01-01 00:00:00 #{@hostname} (#{$$})] : hello\n"
55
+ assert_equal(expected, result)
56
+ end
57
+
58
+ def test_ensure_path_returns_nil_with_bogus_path
59
+ opts = { :'audit_log.path' => '/really/really/not/a/path' }
60
+ FileUtils.stubs(:mkdir_p).raises(SystemCallError, "i'd rather not")
61
+ logger = NewRelic::Agent::AuditLogger.new(@config.merge(opts))
62
+ assert_nil(logger.ensure_log_path)
63
+ end
64
+
65
+ def test_log_request_captures_system_call_errors
66
+ logger = NewRelic::Agent::AuditLogger.new(@config)
67
+ dummy_sink = StringIO.new
68
+ dummy_sink.stubs(:write).raises(SystemCallError, "nope")
69
+ logger.stubs(:ensure_log_path).returns(dummy_sink)
70
+
71
+ # In 1.9.2 and later, Logger::LogDevice#write captures any errors during
72
+ # writing and spits them out with Kernel#warn.
73
+ # This just silences that output to keep the test output uncluttered.
74
+ Logger::LogDevice.any_instance.stubs(:warn)
75
+
76
+ assert_nothing_raised do
77
+ logger.log_request(@uri, 'whatever', @marshaller)
78
+ end
79
+ end
80
+
81
+ def test_prepares_data_with_identity_encoder
82
+ setup_fake_logger
83
+ data = { 'foo' => 'bar' }
84
+ identity_encoder = NewRelic::Agent::NewRelicService::Encoders::Identity
85
+ @marshaller.expects(:prepare).with(data, { :encoder => identity_encoder })
86
+ @logger.log_request(@uri, data, @marshaller)
87
+ end
88
+
89
+ def test_logs_inspect_with_pruby_marshaller
90
+ setup_fake_logger
91
+ pruby_marshaller = NewRelic::Agent::NewRelicService::PrubyMarshaller.new
92
+ @logger.log_request(@uri, @dummy_data, pruby_marshaller)
93
+ assert_log_contains_string(@dummy_data.inspect)
94
+ end
95
+
96
+ def test_logs_json_with_json_marshaller
97
+ marshaller_cls = NewRelic::Agent::NewRelicService::JsonMarshaller
98
+ if marshaller_cls.is_supported?
99
+ setup_fake_logger
100
+ json_marshaller = marshaller_cls.new
101
+ @logger.log_request(@uri, @dummy_data, json_marshaller)
102
+ assert_log_contains_string(JSON.dump(@dummy_data))
103
+ end
104
+ end
105
+ end
@@ -2,110 +2,106 @@ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper
2
2
  require "new_relic/agent/beacon_configuration"
3
3
  class NewRelic::Agent::BeaconConfigurationTest < Test::Unit::TestCase
4
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}"
5
+ with_config(:application_id => 'an application id',
6
+ :beacon => 'beacon', :'rum.enabled' => true) do
7
+ bc = NewRelic::Agent::BeaconConfiguration.new
8
+ assert_equal true, bc.enabled?
9
+ assert_equal '', bc.browser_timing_header
12
10
  end
13
11
  end
14
12
 
15
13
  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)
14
+ with_config(:browser_key => 'a key', :application_id => 'an application id',
15
+ :beacon => 'beacon', :'rum.enabled' => true) do
16
+ bc = NewRelic::Agent::BeaconConfiguration.new
17
+ assert bc.enabled?
18
+ s = "<script type=\"text/javascript\">var NREUMQ=NREUMQ||[];NREUMQ.push([\"mark\",\"firstbyte\",new Date().getTime()]);</script>"
19
+ assert_equal(s, bc.browser_timing_header)
20
+ end
24
21
  end
25
22
 
26
23
  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')
24
+ with_config(:license_key => 'a' * 40) do
25
+ bc = NewRelic::Agent::BeaconConfiguration.new
26
+ assert_equal([97] * 40, bc.license_bytes, 'should return the bytes of the license key')
27
+ end
31
28
  end
32
29
 
33
30
  def test_license_bytes_existing_bytes
34
- connect_data = {}
35
- bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
31
+ bc = NewRelic::Agent::BeaconConfiguration.new
36
32
  bc.instance_eval { @license_bytes = [97] * 40 }
37
- NewRelic::Control.instance.expects(:license_key).never
33
+ NewRelic::Agent.config.expects(:[]).with('license_key').never
38
34
  assert_equal([97] * 40, bc.license_bytes, "should return the cached value if it exists")
39
35
  end
40
36
 
41
37
  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")
38
+ with_config(:license_key => 'a' * 40) do
39
+ bc = NewRelic::Agent::BeaconConfiguration.new
40
+ bc.instance_eval { @license_bytes = nil }
41
+ bc.license_bytes
42
+ assert_equal([97] * 40, bc.instance_variable_get('@license_bytes'), "should cache the license bytes for later")
43
+ end
48
44
  end
49
45
 
50
46
  def test_build_browser_timing_header_disabled
51
- connect_data = {}
52
- bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
47
+ bc = NewRelic::Agent::BeaconConfiguration.new
53
48
  bc.instance_eval { @rum_enabled = false }
54
49
  assert_equal '', bc.build_browser_timing_header, "should not return a header when rum enabled is false"
55
50
  end
56
51
 
57
52
  def test_build_browser_timing_header_enabled_but_no_key
58
- connect_data = {}
59
- bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
53
+ bc = NewRelic::Agent::BeaconConfiguration.new
60
54
  bc.instance_eval { @rum_enabled = true; @browser_monitoring_key = nil }
61
55
  assert_equal '', bc.build_browser_timing_header, "should not return a header when browser_monitoring_key is nil"
62
56
  end
63
-
57
+
64
58
  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")
59
+ with_config(:browser_key => 'a browser monitoring key', :beacon => 'beacon') do
60
+ bc = NewRelic::Agent::BeaconConfiguration.new
61
+ assert(bc.build_browser_timing_header.include?('NREUMQ'),
62
+ "header should be generated when rum is enabled and browser monitoring key is set")
63
+ end
69
64
  end
70
65
 
71
66
  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
67
+ with_config(:browser_key => 'a' * 40, :beacon => 'beacon') do
68
+ mock_javascript = mock('javascript')
69
+ bc = NewRelic::Agent::BeaconConfiguration.new
70
+ bc.expects(:javascript_header).returns(mock_javascript)
71
+ mock_javascript.expects(:respond_to?).with(:html_safe).returns(true)
72
+ mock_javascript.expects(:html_safe)
73
+ bc.build_browser_timing_header
74
+ end
80
75
  end
81
-
76
+
82
77
  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))
78
+ with_config(:'rum.load_episodes_file' => false) do
79
+ bc = NewRelic::Agent::BeaconConfiguration.new
80
+ 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"
81
+ assert_equal(s, bc.build_load_file_js)
82
+ end
87
83
  end
88
-
84
+
89
85
  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))
86
+ with_config(:'rum.load_episodes_file' => '') do
87
+ bc = NewRelic::Agent::BeaconConfiguration.new
88
+ 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"
89
+ assert_equal(s, bc.build_load_file_js)
90
+ end
95
91
  end
96
92
 
97
93
  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))
94
+ bc = NewRelic::Agent::BeaconConfiguration.new
95
+ # 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"
96
+ s = "if (!NREUMQ.f) { NREUMQ.f=function() {\nNREUMQ.push([\"load\",new Date().getTime()]);\nvar e=document.createElement(\"script\");\ne.type=\"text/javascript\";\ne.src=((\"http:\"===document.location.protocol)?\"http:\":\"https:\") + \"//\" +\n \"\";\ndocument.body.appendChild(e);\nif(NREUMQ.a)NREUMQ.a();\n};\nNREUMQ.a=window.onload;window.onload=NREUMQ.f;\n};\n"
97
+ assert_equal(s, bc.build_load_file_js)
103
98
  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")
99
+
100
+ def test_build_load_file_js_load_episodes_file_with_episodes_file
101
+ with_config(:episodes_file => 'an episodes url') do
102
+ bc = NewRelic::Agent::BeaconConfiguration.new
103
+ assert(bc.build_load_file_js.include?('an episodes url'),
104
+ "should include the episodes url by default")
105
+ end
110
106
  end
111
107
  end