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
@@ -3,10 +3,7 @@ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper
3
3
 
4
4
  class NewRelic::Agent::WorkerLoopTest < Test::Unit::TestCase
5
5
  def setup
6
- @log = ""
7
- @logger = Logger.new(StringIO.new(@log))
8
6
  @worker_loop = NewRelic::Agent::WorkerLoop.new
9
- @worker_loop.stubs(:log).returns(@logger)
10
7
  @test_start_time = Time.now
11
8
  end
12
9
 
@@ -19,11 +16,28 @@ class NewRelic::Agent::WorkerLoopTest < Test::Unit::TestCase
19
16
  assert @x
20
17
  end
21
18
 
19
+ def test_with_duration
20
+ worker_loop = NewRelic::Agent::WorkerLoop.new(:duration => 0.1)
21
+ count = 0
22
+ worker_loop.run(0.04) do
23
+ count += 1
24
+ end
25
+
26
+ assert_equal 2, count
27
+ end
28
+
29
+ def test_loop_limit
30
+ worker_loop = NewRelic::Agent::WorkerLoop.new(:limit => 2)
31
+ iterations = 0
32
+ worker_loop.run(0) { iterations += 1 }
33
+ assert_equal 2, iterations
34
+ end
35
+
22
36
  def test_density
23
37
  # This shows how the tasks stay aligned with the period and don't drift.
24
38
  count = 0
25
39
  start = Time.now
26
- @worker_loop.run(0.01) do
40
+ @worker_loop.run(0.03) do
27
41
  count +=1
28
42
  if count == 3
29
43
  @worker_loop.stop
@@ -31,11 +45,11 @@ class NewRelic::Agent::WorkerLoopTest < Test::Unit::TestCase
31
45
  end
32
46
  end
33
47
  elapsed = Time.now - start
34
- assert_in_delta 0.03, elapsed, 0.02
48
+ assert_in_delta 0.09, elapsed, 0.03
35
49
  end
50
+
36
51
  def test_task_error__standard
37
- @logger.expects(:debug)
38
- @logger.expects(:error)
52
+ expects_logging(:error, any_parameters)
39
53
  # This loop task will run twice
40
54
  done = false
41
55
  @worker_loop.run(0) do
@@ -45,19 +59,20 @@ class NewRelic::Agent::WorkerLoopTest < Test::Unit::TestCase
45
59
  end
46
60
  assert done
47
61
  end
62
+
48
63
  class BadBoy < StandardError; end
49
64
 
50
65
  def test_task_error__exception
51
- @logger.expects(:error).once
52
- @logger.expects(:debug).once
66
+ expects_logging(:error, any_parameters)
53
67
  @worker_loop.run(0) do
54
68
  @worker_loop.stop
55
69
  raise BadBoy, "oops"
56
70
  end
57
71
  end
72
+
58
73
  def test_task_error__server
59
- @logger.expects(:error).never
60
- @logger.expects(:debug).once
74
+ expects_no_logging(:error, any_parameters)
75
+ expects_logging(:debug, any_parameters)
61
76
  @worker_loop.run(0) do
62
77
  @worker_loop.stop
63
78
  raise NewRelic::Agent::ServerError, "Runtime Error Test"
@@ -1,28 +1,105 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
2
+ require 'ostruct'
3
+
2
4
  module NewRelic
5
+ # mostly this class just passes through to the active agent
6
+ # through the agent method or the control instance through
7
+ # NewRelic::Control.instance . But it's nice to make sure.
3
8
  class MainAgentTest < Test::Unit::TestCase
4
-
5
- # mostly this module just passes through to the active agent
6
- # through the agent method or the control instance through
7
- # NewRelic::Control.instance . But it's nice to make sure.
9
+
10
+ def setup
11
+ NewRelic::Agent.reset_config
12
+ end
8
13
 
9
14
  def teardown
10
15
  super
11
16
  Thread.current[:newrelic_untraced] = nil
12
17
  end
13
-
18
+
14
19
  def test_shutdown
15
20
  mock_agent = mocked_agent
16
21
  mock_agent.expects(:shutdown).with({})
17
22
  NewRelic::Agent.shutdown
18
23
  end
19
24
 
25
+ def test_shutdown_removes_manual_startup_config
26
+ NewRelic::Agent.manual_start(:some_absurd_setting => true)
27
+ assert NewRelic::Agent.config[:some_absurd_setting]
28
+ NewRelic::Agent.shutdown
29
+ assert !NewRelic::Agent.config[:some_absurd_setting]
30
+ end
31
+
32
+ def test_shutdown_removes_server_config
33
+ NewRelic::Agent.manual_start
34
+ NewRelic::Agent.instance.finish_setup('agent_config' =>
35
+ { :some_absurd_setting => true })
36
+ assert NewRelic::Agent.config[:some_absurd_setting]
37
+ NewRelic::Agent.shutdown
38
+ assert !NewRelic::Agent.config[:some_absurd_setting]
39
+ end
40
+
41
+ def test_finish_setup_applied_server_side_config
42
+ with_config({ :'transction_tracer.enabled' => true,
43
+ 'error_collector.enabled' => true,
44
+ :log_level => 'info' }, 2) do
45
+ NewRelic::Agent.instance.finish_setup('log_level' => 'debug',
46
+ 'agent_config' => { 'transaction_tracer.enabled' => false },
47
+ 'collect_errors' => false)
48
+ assert !NewRelic::Agent.config[:'transaction_tracer.enabled']
49
+ assert !NewRelic::Agent.config[:'error_collector.enabled']
50
+ assert_equal 'debug', NewRelic::Agent.config[:log_level]
51
+ end
52
+ end
53
+
20
54
  def test_after_fork
21
55
  mock_agent = mocked_agent
22
56
  mock_agent.expects(:after_fork).with({})
23
57
  NewRelic::Agent.after_fork
24
58
  end
25
-
59
+
60
+ def test_after_fork_sets_forked_flag
61
+ agent = NewRelic::Agent::Agent.new
62
+ assert !agent.forked?
63
+ agent.after_fork
64
+
65
+ assert agent.forked?
66
+ end
67
+
68
+ if NewRelic::LanguageSupport.can_fork? &&
69
+ !NewRelic::LanguageSupport.using_version?('1.9.1')
70
+ def test_timeslice_harvest_with_after_fork_report_to_channel
71
+ with_config(:agent_enabled => true, :monitor_mode => true) do
72
+ NewRelic::Agent.shutdown # make sure the agent is not already started
73
+ NewRelic::Agent::Agent.instance.service = NewRelic::FakeService.new
74
+ NewRelic::Agent.manual_start(:license_key => ('1234567890' * 4),
75
+ :start_channel_listener => true)
76
+
77
+ metric = 'Custom/test/method'
78
+ NewRelic::Agent.instance.stats_engine.get_stats_no_scope(metric) \
79
+ .record_data_point(1.0)
80
+
81
+ # ensure that cached metric ids don't interfere with metric merging
82
+ NewRelic::Agent.agent.instance_variable_set(:@metric_ids,
83
+ { NewRelic::MetricSpec.new('Instance/Busy') => 1 })
84
+
85
+ NewRelic::Agent::PipeChannelManager.listener.close_all_pipes
86
+ NewRelic::Agent.register_report_channel(:agent_test) # before fork
87
+ pid = Process.fork do
88
+ NewRelic::Agent.after_fork(:report_to_channel => :agent_test)
89
+ NewRelic::Agent.agent.stats_engine.get_stats_no_scope(metric) \
90
+ .record_data_point(2.0)
91
+ end
92
+ Process.wait(pid)
93
+ NewRelic::Agent::PipeChannelManager.listener.stop
94
+
95
+ engine = NewRelic::Agent.agent.stats_engine
96
+ assert_equal(3.0, engine.lookup_stats(metric).total_call_time)
97
+ assert_equal(2, engine.lookup_stats(metric).call_count)
98
+ engine.reset_stats
99
+ end
100
+ end
101
+ end
102
+
26
103
  def test_reset_stats
27
104
  mock_agent = mocked_agent
28
105
  mock_agent.expects(:reset_stats)
@@ -34,17 +111,20 @@ module NewRelic
34
111
  mock_control.expects(:init_plugin).with({:agent_enabled => true, :sync_startup => true})
35
112
  NewRelic::Agent.manual_start
36
113
  end
37
-
114
+
38
115
  def test_manual_start_with_opts
39
116
  mock_control = mocked_control
40
117
  mock_control.expects(:init_plugin).with({:agent_enabled => true, :sync_startup => false})
41
118
  NewRelic::Agent.manual_start(:sync_startup => false)
42
119
  end
43
120
 
44
- def test_logger
45
- control = mocked_control
46
- control.expects(:log)
47
- NewRelic::Agent.logger
121
+ def test_manual_start_starts_channel_listener
122
+ NewRelic::Agent::PipeChannelManager.listener.stop
123
+ NewRelic::Agent.agent.service = NewRelic::FakeService.new
124
+ NewRelic::Agent.manual_start(:start_channel_listener => true)
125
+ assert NewRelic::Agent::PipeChannelManager.listener.started?
126
+ NewRelic::Agent::PipeChannelManager.listener.stop
127
+ NewRelic::Agent.shutdown
48
128
  end
49
129
 
50
130
  def test_browser_timing_header
@@ -66,7 +146,7 @@ module NewRelic
66
146
  mock_stats_engine.expects(:get_stats).with('Custom/test/metric', false)
67
147
  NewRelic::Agent.get_stats('Custom/test/metric')
68
148
  end
69
-
149
+
70
150
  # note that this is the same as get_stats above, they're just aliases
71
151
  def test_get_stats_no_scope
72
152
  agent = mocked_agent
@@ -111,7 +191,7 @@ module NewRelic
111
191
  Thread.current[:record_tt] = false
112
192
  assert_equal(false, NewRelic::Agent.is_transaction_traced?, 'should be false since the thread local is false')
113
193
  end
114
-
194
+
115
195
  def test_is_sql_recorded_true
116
196
  Thread.current[:record_sql] = true
117
197
  assert_equal(true, NewRelic::Agent.is_sql_recorded?, 'should be true since the thread local is set')
@@ -126,7 +206,7 @@ module NewRelic
126
206
  Thread.current[:record_sql] = false
127
207
  assert_equal(false, NewRelic::Agent.is_sql_recorded?, 'should be false since the thread local is false')
128
208
  end
129
-
209
+
130
210
  def test_is_execution_traced_true
131
211
  Thread.current[:newrelic_untraced] = [true, true]
132
212
  assert_equal(true, NewRelic::Agent.is_execution_traced?, 'should be true since the thread local is set')
@@ -146,28 +226,16 @@ module NewRelic
146
226
  Thread.current[:newrelic_untraced] = [true, false]
147
227
  assert_equal(false, NewRelic::Agent.is_execution_traced?, 'should be false since the thread local stack has the last element false')
148
228
  end
149
-
229
+
150
230
  def test_instance
151
231
  assert_equal(NewRelic::Agent.agent, NewRelic::Agent.instance, "should return the same agent for both identical methods")
152
232
  end
153
233
 
154
- def test_load_data_should_disable_serialization_if_an_error_is_encountered
155
- NewRelic::Control.instance['disable_serialization'] = false
156
- NewRelic::DataSerialization.stubs(:should_send_data?).returns(false)
157
- NewRelic::Agent.stubs(:save_data).raises(Errno::EACCES)
158
- begin
159
- NewRelic::Agent.instance.send(:save_or_transmit_data)
160
- rescue Errno::EACCES; end
161
- # should be true
162
- assert(NewRelic::Control.instance['disable_serialization'])
163
- NewRelic::Control.instance['disable_serialization'] = false
164
- end
165
-
166
- def test_load_data_should_not_write_files_when_serialization_disabled
167
- NewRelic::Control.instance['disable_serialization'] = true
168
- NewRelic::DataSerialization.expects(:read_and_write_to_file).never
169
- NewRelic::Agent.load_data
170
- NewRelic::Control.instance['disable_serialization'] = false
234
+ def test_register_report_channel
235
+ NewRelic::Agent.register_report_channel(:channel_id)
236
+ assert NewRelic::Agent::PipeChannelManager.channels[:channel_id] \
237
+ .kind_of?(NewRelic::Agent::PipeChannelManager::Pipe)
238
+ NewRelic::Agent::PipeChannelManager.listener.close_all_pipes
171
239
  end
172
240
 
173
241
  private
@@ -179,7 +247,19 @@ module NewRelic
179
247
  end
180
248
 
181
249
  def mocked_control
182
- control = mock('control')
250
+ server = NewRelic::Control::Server.new('localhost', 3000)
251
+ control = OpenStruct.new(:license_key => 'abcdef',
252
+ :server => server)
253
+ control.instance_eval do
254
+ def [](key)
255
+ nil
256
+ end
257
+
258
+ def fetch(k,d)
259
+ nil
260
+ end
261
+ end
262
+
183
263
  NewRelic::Control.stubs(:instance).returns(control)
184
264
  control
185
265
  end
@@ -24,7 +24,7 @@ class NewRelic::CollectionHelperTest < Test::Unit::TestCase
24
24
  assert_equal '1000', new_array[0]
25
25
  end
26
26
  def test_boolean
27
- np = normalize_params(NewRelic::Control.instance.settings)
27
+ np = normalize_params('monitor_mode' => false)
28
28
  assert_equal false, np['monitor_mode']
29
29
  end
30
30
  def test_string__singleton
@@ -118,14 +118,13 @@ class NewRelic::CollectionHelperTest < Test::Unit::TestCase
118
118
  end
119
119
 
120
120
  def test_disabled_strip_backtrace
121
- NewRelic::Control.instance['disable_backtrace_cleanup'] = true
122
- clean_trace = strip_nr_from_backtrace(mock_backtrace)
123
- assert_equal(1, clean_trace.grep(/new_relic/).size,
124
- "should not remove instances of new relic from backtrace but got: #{clean_trace.join("\n")}")
125
- assert_equal(1, clean_trace.grep(/_trace/).size,
121
+ with_config(:disable_backtrace_cleanup => true) do
122
+ clean_trace = strip_nr_from_backtrace(mock_backtrace)
123
+ assert_equal(1, clean_trace.grep(/new_relic/).size,
124
+ "should not remove instances of new relic from backtrace but got: #{clean_trace.join("\n")}")
125
+ assert_equal(1, clean_trace.grep(/_trace/).size,
126
126
  "should not remove trace method tags from method names but got: #{clean_trace.join("\n")}")
127
- # assert (clean_trace.grep(/find/).size >= 3), "should see at least three frames with 'find' in them (#{e}): \n#{clean_trace.join("\n")}"
128
- NewRelic::Control.instance['disable_backtrace_cleanup'] = false
127
+ end
129
128
  end
130
129
 
131
130
  private
@@ -10,6 +10,8 @@ class NewRelic::Command::DeploymentsTest < Test::Unit::TestCase
10
10
  def info(message); @messages = @messages ? @messages + message : message; end
11
11
  def just_exit(status=0); @exit_status ||= status; end
12
12
  end
13
+ @config = { :license_key => 'a' * 40 }
14
+ NewRelic::Agent.config.apply_config(@config)
13
15
  end
14
16
  def teardown
15
17
  super
@@ -17,6 +19,7 @@ class NewRelic::Command::DeploymentsTest < Test::Unit::TestCase
17
19
  puts @deployment.errors
18
20
  puts @deployment.messages
19
21
  puts @deployment.exit_status
22
+ NewRelic::Agent.config.remove_config(@config)
20
23
  end
21
24
  def test_help
22
25
  begin
@@ -33,7 +36,10 @@ class NewRelic::Command::DeploymentsTest < Test::Unit::TestCase
33
36
  end
34
37
  def test_interactive
35
38
  mock_the_connection
36
- @deployment = NewRelic::Command::Deployments.new :appname => 'APP', :revision => 3838, :user => 'Bill', :description => "Some lengthy description"
39
+ @deployment = NewRelic::Command::Deployments.new(:appname => 'APP',
40
+ :revision => 3838,
41
+ :user => 'Bill',
42
+ :description => "Some lengthy description")
37
43
  assert_nil @deployment.exit_status
38
44
  assert_nil @deployment.errors
39
45
  assert_equal '3838', @deployment.revision
@@ -56,7 +62,18 @@ class NewRelic::Command::DeploymentsTest < Test::Unit::TestCase
56
62
 
57
63
  @deployment = nil
58
64
  end
65
+
66
+ def test_error_if_no_license_key
67
+ with_config(:license_key => '') do
68
+ assert_raise NewRelic::Command::CommandFailure do
69
+ deployment = NewRelic::Command::Deployments.new(%w[-a APP -r 3838 --user=Bill] << "Some lengthy description")
70
+ deployment.run
71
+ end
72
+ end
73
+ end
74
+
59
75
  private
76
+
60
77
  def mock_the_connection
61
78
  mock_connection = mock()
62
79
  @mock_response = mock()
@@ -64,5 +81,4 @@ class NewRelic::Command::DeploymentsTest < Test::Unit::TestCase
64
81
  mock_connection.expects(:request).returns(@mock_response)
65
82
  NewRelic::Control.instance.stubs(:http_connection).returns(mock_connection)
66
83
  end
67
-
68
84
  end
@@ -18,24 +18,6 @@ class NewRelic::Control::ClassMethodsTest < Test::Unit::TestCase
18
18
  assert_equal('a new instance', @base.instance, "should return the result from the #new_instance call")
19
19
  end
20
20
 
21
- def test_new_instance_non_test
22
- local_env = mock('local env')
23
- @base.expects(:local_env).returns(local_env).at_least_once
24
- local_env.expects(:framework).returns('nontest').twice
25
- mock_klass = mock('klass')
26
- mock_klass.expects(:new).with(local_env)
27
- @base.expects(:load_framework_class).with('nontest').returns(mock_klass)
28
- @base.new_instance
29
- end
30
-
31
- def test_new_instance_test_framework
32
- local_env = mock('local env')
33
- local_env.expects(:framework).returns(:test)
34
- @base.expects(:local_env).returns(local_env)
35
- @base.expects(:load_test_framework)
36
- @base.new_instance
37
- end
38
-
39
21
  def test_load_test_framework
40
22
  local_env = mock('local env')
41
23
  # a loose requirement here because the tests will *all* break if
@@ -0,0 +1,26 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'/../../../test_helper'))
2
+
3
+ class NewRelic::Control::Frameworks::RailsTest < Test::Unit::TestCase
4
+ def test_install_browser_monitoring
5
+ require(File.expand_path(File.join(File.dirname(__FILE__),
6
+ '/../../../../lib/new_relic/rack/browser_monitoring')))
7
+ middleware = stub('middleware config')
8
+ config = stub('rails config', :middleware => middleware)
9
+ middleware.expects(:use).with(NewRelic::Rack::BrowserMonitoring)
10
+ NewRelic::Control.instance.instance_eval { @browser_monitoring_installed = false }
11
+ with_config(:'browser_monitoring.auto_instrument' => true) do
12
+ NewRelic::Control.instance.install_browser_monitoring(config)
13
+ end
14
+ end
15
+
16
+ def test_install_browser_monitoring_should_not_install_when_not_configured
17
+ middleware = stub('middleware config')
18
+ config = stub('rails config', :middleware => middleware)
19
+ middleware.expects(:use).never
20
+ NewRelic::Control.instance.instance_eval { @browser_monitoring_installed = false }
21
+
22
+ with_config(:'browser_monitoring.auto_instrument' => false) do
23
+ NewRelic::Control.instance.install_browser_monitoring(config)
24
+ end
25
+ end
26
+ end
@@ -1,10 +1,9 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'/../test_helper'))
2
- class NewRelic::ControlTest < Test::Unit::TestCase
3
2
 
3
+ class NewRelic::ControlTest < Test::Unit::TestCase
4
4
  attr_reader :control
5
5
 
6
6
  def setup
7
- NewRelic::Agent.manual_start(:dispatcher_instance_id => 'test')
8
7
  @control = NewRelic::Control.instance
9
8
  raise 'oh geez, wrong class' unless NewRelic::Control.instance.is_a?(::NewRelic::Control::Frameworks::Test)
10
9
  end
@@ -17,12 +16,11 @@ class NewRelic::ControlTest < Test::Unit::TestCase
17
16
  assert @control.cert_file_path
18
17
  assert_equal File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'cert', 'cacert.pem')), @control.cert_file_path
19
18
  end
20
-
19
+
21
20
  # This test does not actually use the ruby agent in any way - it's
22
21
  # testing that the CA file we ship actually validates our server's
23
22
  # certificate. It's used for customers who enable verify_certificate
24
23
  def test_cert_file
25
- return if ::RUBY_VERSION == '1.9.3'
26
24
  require 'socket'
27
25
  require 'openssl'
28
26
 
@@ -34,12 +32,11 @@ class NewRelic::ControlTest < Test::Unit::TestCase
34
32
  s.connect
35
33
  # should not raise an error
36
34
  end
37
-
35
+
38
36
  # see above, but for staging, as well. This allows us to test new
39
37
  # certificates in a non-customer-facing place before setting them
40
38
  # live.
41
39
  def test_staging_cert_file
42
- return if ::RUBY_VERSION == '1.9.3'
43
40
  require 'socket'
44
41
  require 'openssl'
45
42
 
@@ -52,39 +49,21 @@ class NewRelic::ControlTest < Test::Unit::TestCase
52
49
  # should not raise an error
53
50
  end
54
51
 
55
- def test_monitor_mode
56
- assert ! @control.monitor_mode?
57
- @control.settings.delete 'enabled'
58
- @control.settings.delete 'monitor_mode'
59
- assert !@control.monitor_mode?
60
- @control['enabled'] = false
61
- assert ! @control.monitor_mode?
62
- @control['enabled'] = true
63
- assert @control.monitor_mode?
64
- @control['monitor_mode'] = nil
65
- assert !@control.monitor_mode?
66
- @control['monitor_mode'] = false
67
- assert !@control.monitor_mode?
68
- @control['monitor_mode'] = true
69
- assert @control.monitor_mode?
70
- ensure
71
- @control['enabled'] = false
72
- @control['monitor_mode'] = false
73
- end
74
-
75
52
  def test_test_config
76
- if defined?(Rails) && Rails::VERSION::MAJOR.to_i == 3
53
+ if defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i == 4
54
+ assert_equal :rails4, control.app
55
+ elsif defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i == 3
77
56
  assert_equal :rails3, control.app
78
- elsif defined?(Rails)
57
+ elsif defined?(::Rails)
79
58
  assert_equal :rails, control.app
80
59
  else
81
60
  assert_equal :test, control.app
82
61
  end
83
62
  assert_equal :test, control.framework
84
- assert_match /test/i, control.dispatcher_instance_id
85
- assert("" == control.dispatcher.to_s, "Expected dispatcher to be empty, but was #{control.dispatcher.to_s}")
86
- assert !control['enabled']
87
- assert_equal false, control['monitor_mode']
63
+ assert_match /test/i, control.local_env.dispatcher_instance_id
64
+ assert("" == NewRelic::Agent.config[:dispatcher].to_s,
65
+ "Expected dispatcher to be empty, but was #{NewRelic::Agent.config[:dispatcher].to_s}")
66
+ assert !NewRelic::Agent.config[:monitor_mode]
88
67
  control.local_env
89
68
  end
90
69
 
@@ -96,19 +75,58 @@ class NewRelic::ControlTest < Test::Unit::TestCase
96
75
  end
97
76
 
98
77
  def test_info
78
+ NewRelic::Agent.manual_start(:dispatcher_instance_id => 'test')
99
79
  props = NewRelic::Control.instance.local_env.snapshot
100
80
  if defined?(Rails)
101
81
  assert_match /jdbc|postgres|mysql|sqlite/, props.assoc('Database adapter').last, props.inspect
102
82
  end
103
83
  end
104
84
 
105
- def test_resolve_ip
85
+ def test_resolve_ip_for_localhost
106
86
  assert_equal nil, control.send(:convert_to_ip_address, 'localhost')
87
+ end
88
+
89
+ def test_resolve_ip_for_non_existent_domain
90
+ Resolv.stubs(:getaddress).raises(Resolv::ResolvError)
91
+ IPSocket.stubs(:getaddress).raises(SocketError)
107
92
  assert_equal nil, control.send(:convert_to_ip_address, 'q1239988737.us')
108
- # This will fail if you don't have a valid, accessible, DNS server
93
+ end
94
+
95
+ def test_resolves_valid_ip
96
+ Resolv.stubs(:getaddress).with('collector.newrelic.com').returns('204.93.223.153')
109
97
  assert_equal '204.93.223.153', control.send(:convert_to_ip_address, 'collector.newrelic.com')
110
98
  end
111
99
 
100
+ def test_do_not_resolve_if_we_need_to_verify_a_cert
101
+ assert_equal nil, control.send(:convert_to_ip_address, 'localhost')
102
+ with_config(:ssl => true, :verify_certificate => true) do
103
+ assert_equal 'localhost', control.send(:convert_to_ip_address, 'localhost')
104
+ end
105
+ end
106
+
107
+ def test_api_server_uses_configured_values
108
+ control.instance_variable_set(:@api_server, nil)
109
+ with_config(:api_host => 'somewhere', :api_port => 8080) do
110
+ assert_equal 'somewhere', control.api_server.name
111
+ assert_equal 8080, control.api_server.port
112
+ end
113
+ end
114
+
115
+ def test_proxy_server_uses_configured_values
116
+ control.instance_variable_set(:@proxy_server, nil)
117
+ with_config(:proxy_host => 'proxytown', :proxy_port => 81) do
118
+ assert_equal 'proxytown', control.proxy_server.name
119
+ assert_equal 81, control.proxy_server.port
120
+ end
121
+ end
122
+
123
+ def test_server_from_host_uses_configured_values
124
+ with_config(:host => 'donkeytown', :port => 8080) do
125
+ assert_equal 'donkeytown', control.server_from_host.name
126
+ assert_equal 8080, control.server_from_host.port
127
+ end
128
+ end
129
+
112
130
  class FakeResolv
113
131
  def self.getaddress(host)
114
132
  raise 'deliberately broken'
@@ -131,126 +149,67 @@ class NewRelic::ControlTest < Test::Unit::TestCase
131
149
  assert_equal old_ipsocket, IPSocket
132
150
  end
133
151
 
134
- def test_config_yaml_erb
135
- assert_equal 'heyheyhey', control['erb_value']
136
- assert_equal '', control['message']
137
- assert_equal '', control['license_key']
138
- end
139
-
140
- def test_appnames
141
- assert_equal %w[a b c], NewRelic::Control.instance.app_names
142
- end
143
-
144
- def test_config_booleans
145
- assert_equal control['tval'], true
146
- assert_equal control['fval'], false
147
- assert_nil control['not_in_yaml_val']
148
- assert_equal control['yval'], true
149
- assert_equal control['sval'], 'sure'
150
- end
151
-
152
- def test_config_apdex
153
- assert_equal 1.1, control.apdex_t
154
- end
155
-
156
- # def test_transaction_threshold
157
- # assert_equal 'Apdex_f', c['transaction_tracer']['transaction_threshold']
158
- # assert_equal 4.4, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
159
- # end
160
-
161
- def test_log_file_name
162
- NewRelic::Control.instance.setup_log
163
- assert_match /newrelic_agent.log$/, control.instance_variable_get('@log_file')
164
- end
165
-
166
- # def test_transaction_threshold__apdex
167
- # forced_start
168
- # assert_equal 'Apdex_f', c['transaction_tracer']['transaction_threshold']
169
- # assert_equal 4.4, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
170
- # end
171
-
172
- def test_transaction_threshold__default
173
- forced_start :transaction_tracer => { :transaction_threshold => nil}
174
- assert_nil control['transaction_tracer']['transaction_threshold']
175
- assert_equal 2.0, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
176
- end
177
-
178
152
  def test_transaction_threshold__override
179
- forced_start :transaction_tracer => { :transaction_threshold => 1}
180
- assert_equal 1, control['transaction_tracer']['transaction_threshold']
181
- assert_equal 1, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
153
+ with_config(:transaction_tracer => { :transaction_threshold => 1}) do
154
+ assert_equal 1, NewRelic::Agent.config[:'transaction_tracer.transaction_threshold']
155
+ end
182
156
  end
183
157
 
184
158
  def test_transaction_tracer_disabled
185
- forced_start(:transaction_tracer => { :enabled => false },
186
- :developer_mode => false, :monitor_mode => true)
187
- NewRelic::Agent::Agent.instance.check_transaction_sampler_status
188
-
189
- assert(!NewRelic::Agent::Agent.instance.transaction_sampler.enabled?,
190
- 'transaction tracer enabled when config calls for disabled')
191
-
192
- @control['developer_mode'] = true
193
- @control['monitor_mode'] = false
159
+ with_config(:'transaction_tracer.enabled' => false,
160
+ :developer_mode => false, :monitor_mode => true) do
161
+ assert(!NewRelic::Agent::Agent.instance.transaction_sampler.enabled?,
162
+ 'transaction tracer enabled when config calls for disabled')
163
+ end
194
164
  end
195
-
165
+
196
166
  def test_sql_tracer_disabled
197
- forced_start(:slow_sql => { :enabled => false }, :monitor_mode => true)
198
- NewRelic::Agent::Agent.instance.check_sql_sampler_status
199
-
200
- assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
201
- 'sql tracer enabled when config calls for disabled')
202
-
203
- @control['monitor_mode'] = false
167
+ with_config(:'slow_sql.enabled' => false, :monitor_mode => true) do
168
+ assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
169
+ 'sql tracer enabled when config calls for disabled')
170
+ end
204
171
  end
205
-
172
+
206
173
  def test_sql_tracer_disabled_with_record_sql_false
207
- forced_start(:slow_sql => { :enabled => true, :record_sql => 'off' })
208
- NewRelic::Agent::Agent.instance.check_sql_sampler_status
209
-
210
- assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
211
- 'sql tracer enabled when config calls for disabled')
174
+ with_config(:slow_sql => { :enabled => true, :record_sql => 'off' }) do
175
+ assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
176
+ 'sql tracer enabled when config calls for disabled')
177
+ end
212
178
  end
213
179
 
214
180
  def test_sql_tracer_disabled_when_tt_disabled
215
- forced_start(:transaction_tracer => { :enabled => false },
216
- :slow_sql => { :enabled => true },
217
- :developer_mode => false, :monitor_mode => true)
218
- NewRelic::Agent::Agent.instance.check_sql_sampler_status
219
-
220
- assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
221
- 'sql enabled when transaction tracer disabled')
222
-
223
- @control['developer_mode'] = true
224
- @control['monitor_mode'] = false
181
+ with_config(:'transaction_tracer.enabled' => false,
182
+ :'slow_sql.enabled' => true,
183
+ :developer_mode => false, :monitor_mode => true) do
184
+ assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
185
+ 'sql enabled when transaction tracer disabled')
186
+ end
225
187
  end
226
188
 
227
189
  def test_sql_tracer_disabled_when_tt_disabled_by_server
228
- forced_start(:slow_sql => { :enabled => true },
229
- :transaction_tracer => { :enabled => true },
230
- :monitor_mode => true)
231
- NewRelic::Agent::Agent.instance.check_sql_sampler_status
232
- NewRelic::Agent::Agent.instance.finish_setup('collect_traces' => false)
233
-
234
- assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
235
- 'sql enabled when tracing disabled by server')
236
-
237
- @control['monitor_mode'] = false
238
- end
190
+ with_config({:'slow_sql.enabled' => true,
191
+ :'transaction_tracer.enabled' => true,
192
+ :monitor_mode => true}, 2) do
193
+ NewRelic::Agent.instance.finish_setup('collect_traces' => false)
239
194
 
240
- def test_merging_options
241
- NewRelic::Control.send :public, :merge_options
242
- @control.merge_options :api_port => 66, :transaction_tracer => { :explain_threshold => 2.0 }
243
- assert_equal 66, NewRelic::Control.instance['api_port']
244
- assert_equal 2.0, NewRelic::Control.instance['transaction_tracer']['explain_threshold']
245
- assert_equal 'raw', NewRelic::Control.instance['transaction_tracer']['record_sql']
195
+ assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
196
+ 'sql enabled when tracing disabled by server')
197
+ end
246
198
  end
247
199
 
248
- private
200
+ def test_init_plugin_loads_samplers_enabled
201
+ NewRelic::Agent.shutdown
202
+ with_config(:disable_samplers => false, :agent_enabled => true) do
203
+ NewRelic::Control.instance.init_plugin
204
+ assert NewRelic::Agent.instance.stats_engine.send(:harvest_samplers).any?
205
+ end
206
+ end
249
207
 
250
- def forced_start overrides = {}
251
- NewRelic::Agent.manual_start overrides
252
- # This is to force the agent to start again.
253
- NewRelic::Agent.instance.stubs(:started?).returns(nil)
254
- NewRelic::Agent.instance.start
208
+ def test_init_plugin_loads_samplers_disabled
209
+ NewRelic::Agent.shutdown
210
+ with_config(:disable_samplers => true, :agent_enabled => true) do
211
+ NewRelic::Control.instance.init_plugin
212
+ assert NewRelic::Agent.instance.stats_engine.send(:harvest_samplers).empty?
213
+ end
255
214
  end
256
215
  end