newrelic_rpm 3.6.6.147 → 3.6.7.152

Sign up to get free protection for your applications and to get access to all the features.
Files changed (265) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.gitignore +0 -1
  3. data/CHANGELOG +55 -17
  4. data/Guardfile +7 -0
  5. data/Rakefile +6 -0
  6. data/bin/mongrel_rpm +33 -0
  7. data/bin/newrelic +13 -0
  8. data/bin/newrelic_cmd +5 -0
  9. data/bin/nrdebug +273 -0
  10. data/install.rb +3 -3
  11. data/lib/new_relic/agent.rb +4 -6
  12. data/lib/new_relic/agent/agent.rb +76 -72
  13. data/lib/new_relic/agent/autostart.rb +18 -5
  14. data/lib/new_relic/agent/browser_monitoring.rb +41 -35
  15. data/lib/new_relic/agent/browser_token.rb +38 -0
  16. data/lib/new_relic/agent/busy_calculator.rb +7 -5
  17. data/lib/new_relic/agent/commands/agent_command.rb +19 -0
  18. data/lib/new_relic/agent/commands/agent_command_router.rb +88 -0
  19. data/lib/new_relic/agent/commands/thread_profiler.rb +80 -0
  20. data/lib/new_relic/agent/configuration/default_source.rb +700 -0
  21. data/lib/new_relic/agent/configuration/environment_source.rb +83 -30
  22. data/lib/new_relic/agent/configuration/manager.rb +8 -8
  23. data/lib/new_relic/agent/configuration/mask_defaults.rb +2 -2
  24. data/lib/new_relic/agent/cross_app_monitor.rb +10 -21
  25. data/lib/new_relic/agent/cross_app_tracing.rb +3 -3
  26. data/lib/new_relic/agent/error_collector.rb +7 -10
  27. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +1 -1
  28. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +5 -1
  29. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +5 -1
  30. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +5 -1
  31. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +1 -1
  32. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +5 -12
  33. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +4 -0
  34. data/lib/new_relic/agent/instrumentation/{rails4/active_record.rb → active_record_4.rb} +1 -1
  35. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +11 -11
  36. data/lib/new_relic/agent/instrumentation/authlogic.rb +8 -6
  37. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +12 -6
  38. data/lib/new_relic/agent/instrumentation/curb.rb +11 -2
  39. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -3
  40. data/lib/new_relic/agent/instrumentation/evented_subscriber.rb +11 -2
  41. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +13 -4
  42. data/lib/new_relic/agent/instrumentation/puma.rb +2 -1
  43. data/lib/new_relic/agent/instrumentation/rack.rb +15 -17
  44. data/lib/new_relic/agent/method_tracer.rb +181 -191
  45. data/lib/new_relic/agent/new_relic_service.rb +16 -14
  46. data/lib/new_relic/agent/pipe_channel_manager.rb +1 -1
  47. data/lib/new_relic/agent/request_sampler.rb +32 -165
  48. data/lib/new_relic/agent/sampled_buffer.rb +79 -0
  49. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +1 -8
  50. data/lib/new_relic/agent/sql_sampler.rb +3 -3
  51. data/lib/new_relic/agent/stats_engine.rb +1 -1
  52. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -1
  53. data/lib/new_relic/agent/stats_engine/metric_stats.rb +2 -3
  54. data/lib/new_relic/agent/stats_engine/transactions.rb +2 -22
  55. data/lib/new_relic/agent/threading/agent_thread.rb +41 -0
  56. data/lib/new_relic/agent/threading/backtrace_node.rb +71 -0
  57. data/lib/new_relic/agent/threading/thread_profile.rb +172 -0
  58. data/lib/new_relic/agent/transaction.rb +16 -4
  59. data/lib/new_relic/agent/transaction_sample_builder.rb +13 -3
  60. data/lib/new_relic/agent/transaction_sampler.rb +5 -8
  61. data/lib/new_relic/agent/transaction_state.rb +166 -0
  62. data/lib/new_relic/agent/transaction_timings.rb +53 -0
  63. data/lib/new_relic/cli/command.rb +91 -0
  64. data/lib/new_relic/{commands → cli}/deployments.rb +13 -9
  65. data/lib/new_relic/{commands → cli}/install.rb +2 -2
  66. data/lib/new_relic/control/frameworks/rails.rb +1 -8
  67. data/lib/new_relic/control/instance_methods.rb +1 -2
  68. data/lib/new_relic/helper.rb +9 -0
  69. data/lib/new_relic/local_environment.rb +16 -63
  70. data/lib/new_relic/rack/browser_monitoring.rb +8 -5
  71. data/lib/new_relic/recipes.rb +44 -31
  72. data/lib/new_relic/transaction_sample.rb +6 -2
  73. data/lib/new_relic/version.rb +1 -1
  74. data/lib/tasks/install.rake +21 -1
  75. data/newrelic_rpm.gemspec +5 -1
  76. data/test/agent_helper.rb +4 -9
  77. data/test/environments/.gitignore +16 -0
  78. data/test/environments/lib/environments/runner.rb +104 -0
  79. data/test/environments/norails/Gemfile +11 -0
  80. data/test/environments/norails/Rakefile +9 -0
  81. data/test/environments/rails21/Gemfile +24 -0
  82. data/test/environments/rails21/Rakefile +12 -0
  83. data/test/environments/rails21/app/controllers/application.rb +20 -0
  84. data/test/environments/rails21/config/boot.rb +113 -0
  85. data/test/environments/rails21/config/database.yml +31 -0
  86. data/test/environments/rails21/config/environment.rb +28 -0
  87. data/test/environments/rails21/config/environments/development.rb +16 -0
  88. data/test/environments/rails21/config/environments/production.rb +8 -0
  89. data/test/environments/rails21/config/environments/test.rb +10 -0
  90. data/test/environments/rails21/config/routes.rb +5 -0
  91. data/test/environments/rails21/db/schema.rb +5 -0
  92. data/test/environments/rails22/Gemfile +29 -0
  93. data/test/environments/rails22/Rakefile +12 -0
  94. data/test/environments/rails22/app/controllers/application.rb +20 -0
  95. data/test/environments/rails22/config/boot.rb +113 -0
  96. data/test/environments/rails22/config/database.yml +31 -0
  97. data/test/environments/rails22/config/environment.rb +27 -0
  98. data/test/environments/rails22/config/environments/development.rb +16 -0
  99. data/test/environments/rails22/config/environments/production.rb +8 -0
  100. data/test/environments/rails22/config/environments/test.rb +10 -0
  101. data/test/environments/rails22/config/routes.rb +5 -0
  102. data/test/environments/rails22/db/schema.rb +5 -0
  103. data/test/environments/rails23/Gemfile +22 -0
  104. data/test/environments/rails23/Rakefile +12 -0
  105. data/test/environments/rails23/app/controllers/application.rb +20 -0
  106. data/test/environments/rails23/config/boot.rb +127 -0
  107. data/test/environments/rails23/config/database.yml +31 -0
  108. data/test/environments/rails23/config/environment.rb +25 -0
  109. data/test/environments/rails23/config/environments/development.rb +16 -0
  110. data/test/environments/rails23/config/environments/production.rb +8 -0
  111. data/test/environments/rails23/config/environments/test.rb +10 -0
  112. data/test/environments/rails23/config/preinitializer.rb +25 -0
  113. data/test/environments/rails23/config/routes.rb +5 -0
  114. data/test/environments/rails23/db/schema.rb +5 -0
  115. data/test/environments/rails30/Gemfile +19 -0
  116. data/test/environments/rails30/Rakefile +9 -0
  117. data/test/environments/rails30/config/application.rb +17 -0
  118. data/test/environments/rails30/config/boot.rb +10 -0
  119. data/test/environments/rails30/config/database.yml +31 -0
  120. data/test/environments/rails30/config/environment.rb +6 -0
  121. data/test/environments/rails30/config/initializers/new_rails_defaults.rb +11 -0
  122. data/test/environments/rails30/db/schema.rb +5 -0
  123. data/test/environments/rails31/Gemfile +19 -0
  124. data/test/environments/rails31/Rakefile +9 -0
  125. data/test/environments/rails31/config/application.rb +18 -0
  126. data/test/environments/rails31/config/boot.rb +10 -0
  127. data/test/environments/rails31/config/database.yml +31 -0
  128. data/test/environments/rails31/config/environment.rb +6 -0
  129. data/test/environments/rails31/config/initializers/new_rails_defaults.rb +21 -0
  130. data/test/environments/rails31/db/schema.rb +5 -0
  131. data/test/environments/rails32/Gemfile +25 -0
  132. data/test/environments/rails32/Rakefile +9 -0
  133. data/test/environments/rails32/config/application.rb +19 -0
  134. data/test/environments/rails32/config/boot.rb +10 -0
  135. data/test/environments/rails32/config/database.yml +31 -0
  136. data/test/environments/rails32/config/environment.rb +6 -0
  137. data/test/environments/rails32/db/schema.rb +5 -0
  138. data/test/environments/rails40/Gemfile +25 -0
  139. data/test/environments/rails40/Rakefile +9 -0
  140. data/test/environments/rails40/config/application.rb +18 -0
  141. data/test/environments/rails40/config/boot.rb +10 -0
  142. data/test/environments/rails40/config/database.yml +31 -0
  143. data/test/environments/rails40/config/environment.rb +6 -0
  144. data/test/environments/rails40/db/schema.rb +5 -0
  145. data/test/multiverse/lib/multiverse/suite.rb +24 -12
  146. data/test/multiverse/suites/agent_only/logging_test.rb +18 -1
  147. data/test/multiverse/suites/agent_only/rum_instrumentation_test.rb +1 -8
  148. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +10 -7
  149. data/test/multiverse/suites/curb/curb_test.rb +17 -3
  150. data/test/multiverse/suites/excon/Envfile +1 -1
  151. data/test/multiverse/suites/excon/excon_test.rb +18 -2
  152. data/test/multiverse/suites/httpclient/httpclient_test.rb +2 -2
  153. data/test/multiverse/suites/net_http/net_http_test.rb +2 -2
  154. data/test/multiverse/suites/rails/error_tracing_test.rb +35 -8
  155. data/test/multiverse/suites/rails/ignore_test.rb +48 -0
  156. data/test/multiverse/suites/rails/mongrel_queue_depth_test.rb +44 -0
  157. data/test/multiverse/suites/sequel/sequel_test.rb +11 -0
  158. data/test/multiverse/suites/sinatra/ignoring_test.rb +2 -2
  159. data/test/multiverse/suites/typhoeus/Envfile +9 -2
  160. data/test/multiverse/suites/typhoeus/typhoeus_test.rb +3 -2
  161. data/test/new_relic/agent/agent/start_test.rb +3 -22
  162. data/test/new_relic/agent/agent_test.rb +6 -5
  163. data/test/new_relic/agent/autostart_test.rb +39 -1
  164. data/test/new_relic/agent/browser_monitoring_test.rb +43 -88
  165. data/test/new_relic/agent/browser_token_test.rb +52 -0
  166. data/test/new_relic/agent/busy_calculator_test.rb +1 -1
  167. data/test/new_relic/agent/commands/agent_command_router_test.rb +98 -0
  168. data/test/new_relic/agent/commands/agent_command_test.rb +37 -0
  169. data/test/new_relic/agent/commands/thread_profiler_test.rb +177 -0
  170. data/test/new_relic/agent/configuration/default_source_test.rb +81 -0
  171. data/test/new_relic/agent/configuration/environment_source_test.rb +81 -7
  172. data/test/new_relic/agent/configuration/manager_test.rb +16 -1
  173. data/test/new_relic/agent/cross_app_monitor_test.rb +3 -5
  174. data/test/new_relic/agent/error_collector_test.rb +14 -0
  175. data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +1 -1
  176. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +2 -3
  177. data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +29 -31
  178. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +22 -0
  179. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +2 -2
  180. data/test/new_relic/agent/method_tracer_test.rb +2 -2
  181. data/test/new_relic/agent/new_relic_service_test.rb +5 -49
  182. data/test/new_relic/agent/pipe_channel_manager_test.rb +1 -0
  183. data/test/new_relic/agent/request_sampler_test.rb +32 -95
  184. data/test/new_relic/agent/rpm_agent_test.rb +7 -5
  185. data/test/new_relic/agent/sampled_buffer_test.rb +178 -0
  186. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +0 -1
  187. data/test/new_relic/agent/stats_engine_test.rb +10 -17
  188. data/test/new_relic/agent/threading/agent_thread_test.rb +107 -0
  189. data/test/new_relic/agent/threading/backtrace_node_test.rb +96 -0
  190. data/test/new_relic/agent/{threaded_test.rb → threading/fake_thread.rb} +0 -25
  191. data/test/new_relic/agent/threading/thread_profile_test.rb +308 -0
  192. data/test/new_relic/agent/threading/threaded_test_case.rb +33 -0
  193. data/test/new_relic/agent/transaction/pop_test.rb +0 -16
  194. data/test/new_relic/agent/transaction_sample_builder_test.rb +23 -4
  195. data/test/new_relic/agent/transaction_sampler_test.rb +14 -15
  196. data/test/new_relic/agent/transaction_state_test.rb +75 -0
  197. data/test/new_relic/agent/transaction_test.rb +15 -0
  198. data/test/new_relic/agent/transaction_timings_test.rb +81 -0
  199. data/test/new_relic/agent_test.rb +12 -14
  200. data/test/new_relic/{command → cli}/deployments_test.rb +41 -13
  201. data/test/new_relic/control/frameworks/rails_test.rb +1 -2
  202. data/test/new_relic/control_test.rb +1 -2
  203. data/test/new_relic/dependency_detection_test.rb +14 -0
  204. data/test/new_relic/fake_collector.rb +1 -0
  205. data/test/new_relic/helper_test.rb +7 -2
  206. data/test/new_relic/http_client_test_cases.rb +33 -1
  207. data/test/new_relic/local_environment_test.rb +0 -23
  208. data/test/new_relic/metric_data_test.rb +4 -0
  209. data/test/new_relic/rack/browser_monitoring_test.rb +31 -30
  210. data/test/performance/lib/performance/result.rb +15 -4
  211. data/test/performance/lib/performance/timer.rb +7 -1
  212. data/test/performance/script/baselines +102 -0
  213. data/test/performance/suites/rum_autoinsertion.rb +57 -0
  214. data/test/rum/basic.result.html +10 -0
  215. data/test/rum/basic.source.html +10 -0
  216. data/test/rum/comments1.result.html +24 -0
  217. data/test/rum/comments1.source.html +24 -0
  218. data/test/rum/comments2.result.html +24 -0
  219. data/test/rum/comments2.source.html +24 -0
  220. data/test/rum/gt_in_quotes1.result.html +27 -0
  221. data/test/rum/gt_in_quotes1.source.html +27 -0
  222. data/test/rum/gt_in_quotes2.result.html +24 -0
  223. data/test/rum/gt_in_quotes2.source.html +24 -0
  224. data/test/rum/gt_in_quotes_mismatch.result.html +24 -0
  225. data/test/rum/gt_in_quotes_mismatch.source.html +24 -0
  226. data/test/rum/gt_in_single_quotes1.result.html +25 -0
  227. data/test/rum/gt_in_single_quotes1.source.html +25 -0
  228. data/test/rum/gt_in_single_quotes_mismatch.result.html +25 -0
  229. data/test/rum/gt_in_single_quotes_mismatch.source.html +25 -0
  230. data/test/rum/incomplete_non_meta_tags.result.html +10 -0
  231. data/test/rum/incomplete_non_meta_tags.source.html +10 -0
  232. data/test/rum/no_body.result.html +21 -0
  233. data/test/rum/no_body.source.html +21 -0
  234. data/test/rum/no_header.result.html +7 -0
  235. data/test/rum/no_header.source.html +7 -0
  236. data/test/rum/no_start_header.result.html +9 -0
  237. data/test/rum/no_start_header.source.html +9 -0
  238. data/test/rum/script1.result.html +19 -0
  239. data/test/rum/script1.source.html +19 -0
  240. data/test/rum/script2.result.html +17 -0
  241. data/test/rum/script2.source.html +17 -0
  242. data/test/rum/x_ua_meta_tag.result.html +10 -0
  243. data/test/rum/x_ua_meta_tag.source.html +10 -0
  244. data/test/rum/x_ua_meta_tag_multiline.result.html +11 -0
  245. data/test/rum/x_ua_meta_tag_multiline.source.html +11 -0
  246. data/test/rum/x_ua_meta_tag_with_others.result.html +11 -0
  247. data/test/rum/x_ua_meta_tag_with_others.source.html +11 -0
  248. data/test/rum/x_ua_meta_tag_with_spaces.result.html +10 -0
  249. data/test/rum/x_ua_meta_tag_with_spaces.source.html +10 -0
  250. data/test/script/ci.sh +1 -12
  251. data/test/test_helper.rb +1 -0
  252. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +11 -0
  253. metadata +225 -32
  254. metadata.gz.sig +0 -0
  255. data/lib/new_relic/agent/configuration/defaults.rb +0 -157
  256. data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +0 -56
  257. data/lib/new_relic/agent/thread.rb +0 -37
  258. data/lib/new_relic/agent/thread_profiler.rb +0 -323
  259. data/lib/new_relic/agent/transaction_info.rb +0 -114
  260. data/lib/new_relic/command.rb +0 -89
  261. data/test/new_relic/agent/agent_test_controller_test.rb +0 -348
  262. data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +0 -70
  263. data/test/new_relic/agent/thread_profiler_test.rb +0 -586
  264. data/test/new_relic/agent/thread_test.rb +0 -93
  265. data/test/new_relic/agent/transaction_info_test.rb +0 -99
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+
5
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
6
+ require 'new_relic/agent/browser_token'
7
+
8
+ module NewRelic::Agent
9
+ class BrowserTokenTest < Test::Unit::TestCase
10
+ def assert_token(expected, cookies)
11
+ request = stub(:cookies => cookies)
12
+ assert_equal(expected, BrowserToken.get_token(request))
13
+ end
14
+
15
+ def test_get_token_safe_token_returned_untouched
16
+ assert_token("12345678", 'NRAGENT' => 'tk=12345678')
17
+ end
18
+
19
+ def test_get_token_with_embedded_tags_sanitized
20
+ assert_token("", 'NRAGENT' => 'tk=1234<tag>evil</tag>5678')
21
+ end
22
+
23
+ def test_get_token_with_embedded_utf8_js_sanitized
24
+ assert_token("1234&amp;#34&amp;#93&amp;#41&amp;#595678", 'NRAGENT' => "tk=1234&#34&#93&#41&#595678")
25
+ end
26
+
27
+ def test_get_token_replaces_double_quoted_token_with_empty_string
28
+ assert_token("", 'NRAGENT' => 'tk="""deadbeef"""')
29
+ end
30
+
31
+ def test_get_token_replaces_single_quoted_token_with_empty_string
32
+ assert_token("", 'NRAGENT' => "tk='''deadbeef'''")
33
+ end
34
+
35
+ def test_get_token_replaces_token_started_with_multiple_Lt_with_empty_string
36
+ assert_token("", 'NRAGENT' => 'tk=<<<deadbeef')
37
+ end
38
+
39
+ def test_get_token_replaces_token_started_with_multiple_gt_with_empty_string
40
+ assert_token("", 'NRAGENT' => 'tk=>>>deadbeef')
41
+ end
42
+
43
+ def test_get_token_bare_value_replaced_with_nil
44
+ assert_token(nil, 'NRAGENT' => 0xdeadbeef)
45
+ end
46
+
47
+ def test_get_token_nil_token_returns_nil_token
48
+ assert_token(nil, 'NRAGENT' => nil)
49
+ end
50
+
51
+ end
52
+ end
@@ -91,7 +91,7 @@ class NewRelic::Agent::BusyCalculatorTest < Test::Unit::TestCase
91
91
  end
92
92
 
93
93
  def test_finishing_without_starting_doesnt_raise
94
- Thread.current[:busy_entries] = nil
94
+ NewRelic::Agent::TransactionState.clear
95
95
  assert_nothing_raised do
96
96
  NewRelic::Agent::BusyCalculator.dispatcher_finish
97
97
  end
@@ -0,0 +1,98 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+
5
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
6
+ require 'new_relic/agent/commands/agent_command_router'
7
+
8
+ class AgentCommandRouterTest < Test::Unit::TestCase
9
+
10
+ DEFAULT_ARGS = {
11
+ "profile_id" => 42
12
+ }
13
+
14
+ BAZZLE_ID = 123
15
+ BAZZLE = [BAZZLE_ID,{
16
+ "name" => "bazzle",
17
+ "arguments" => DEFAULT_ARGS
18
+ }]
19
+
20
+ BOOM_ID = 666
21
+ BOOM = [BOOM_ID,{
22
+ "name" => "boom",
23
+ "arguments" => DEFAULT_ARGS
24
+ }]
25
+
26
+ UNRECOGNIZED_ID = 42
27
+ UNRECOGNIZED = [UNRECOGNIZED_ID, {
28
+ "name" => "JIBBERISH",
29
+ "arguments" => {}
30
+ }]
31
+
32
+ attr_reader :service, :agent_commands, :calls
33
+
34
+ def setup
35
+ @service = stub
36
+ @calls = []
37
+
38
+ @agent_commands = NewRelic::Agent::Commands::AgentCommandRouter.new(@service, nil)
39
+ @agent_commands.handlers["bazzle"] = Proc.new { |args| handle_bazzle_command(args) }
40
+ @agent_commands.handlers["boom"] = Proc.new { |args| handle_boom_command(args) }
41
+ end
42
+
43
+ def test_handle_agent_commands_dispatches_command
44
+ service.stubs(:get_agent_commands).returns([BAZZLE])
45
+ service.stubs(:agent_command_results)
46
+
47
+ agent_commands.handle_agent_commands
48
+
49
+ assert_equal [DEFAULT_ARGS], calls
50
+ end
51
+
52
+ def test_handle_agent_commands_generates_results
53
+ service.stubs(:get_agent_commands).returns([BAZZLE])
54
+ service.expects(:agent_command_results).with({ BAZZLE_ID.to_s => {} })
55
+
56
+ agent_commands.handle_agent_commands
57
+ end
58
+
59
+ def test_handle_agent_commands_dispatches_with_error
60
+ service.stubs(:get_agent_commands).returns([BOOM])
61
+ service.expects(:agent_command_results).with({ BOOM_ID.to_s => { "error" => "BOOOOOM" }})
62
+
63
+ agent_commands.handle_agent_commands
64
+ end
65
+
66
+ def test_handle_agent_commands_allows_multiple
67
+ service.stubs(:get_agent_commands).returns([BAZZLE, BOOM])
68
+ service.expects(:agent_command_results).with({ BAZZLE_ID.to_s => {},
69
+ BOOM_ID.to_s => { "error" => "BOOOOOM" }})
70
+ agent_commands.handle_agent_commands
71
+ end
72
+
73
+ def test_handle_agent_commands_doesnt_call_results_if_no_commands
74
+ service.stubs(:get_agent_commands).returns([])
75
+ service.expects(:agent_command_results).never
76
+
77
+ agent_commands.handle_agent_commands
78
+ end
79
+
80
+ def test_unrecognized_commands
81
+ service.stubs(:get_agent_commands).returns([UNRECOGNIZED])
82
+ service.stubs(:agent_command_results)
83
+
84
+ expects_logging(:debug, regexp_matches(/unrecognized/i))
85
+
86
+ agent_commands.handle_agent_commands
87
+ end
88
+
89
+ # Helpers
90
+
91
+ def handle_bazzle_command(command)
92
+ calls << command.arguments
93
+ end
94
+
95
+ def handle_boom_command(command)
96
+ raise NewRelic::Agent::Commands::AgentCommandRouter::AgentCommandError.new("BOOOOOM")
97
+ end
98
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+
5
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
6
+ require 'new_relic/agent/commands/agent_command'
7
+
8
+ module NewRelic::Agent::Commands
9
+ class AgentCommandTest < Test::Unit::TestCase
10
+ ID = 123
11
+ NAME = 'nuke_it_from_orbit'
12
+ ARGUMENTS = { "profile_id" => 42 }
13
+
14
+ NUKE_IT_FROM_ORBIT = [ID,{
15
+ "name" => NAME,
16
+ "arguments" => ARGUMENTS
17
+ }]
18
+
19
+ def test_destructures_name_from_collector_command
20
+ command = AgentCommand.new(NUKE_IT_FROM_ORBIT)
21
+ expected = NAME
22
+ assert_equal expected, command.name
23
+ end
24
+
25
+ def test_destructures_id_from_collector_command
26
+ command = AgentCommand.new(NUKE_IT_FROM_ORBIT)
27
+ expected = ID
28
+ assert_equal expected, command.id
29
+ end
30
+
31
+ def test_destructures_arguments_from_collector_command
32
+ command = AgentCommand.new(NUKE_IT_FROM_ORBIT)
33
+ expected = ARGUMENTS
34
+ assert_equal expected, command.arguments
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,177 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+
5
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
6
+ require 'base64'
7
+ require 'thread'
8
+ require 'timeout'
9
+ require 'zlib'
10
+ require 'new_relic/agent/threading/threaded_test_case'
11
+ require 'new_relic/agent/commands/thread_profiler'
12
+ #require 'test/new_relic/agent/commands/agent_command_test'
13
+
14
+ module ThreadProfilerTestHelpers
15
+ START = {
16
+ "profile_id" => 42,
17
+ "sample_period" => 0.02,
18
+ "duration" => 0.025,
19
+ "only_runnable_threads" => false,
20
+ "only_request_threads" => false,
21
+ "profile_agent_code" => false,
22
+ }
23
+ STOP = {
24
+ "profile_id" => 42,
25
+ "report_data" => true,
26
+ }
27
+
28
+ STOP_AND_DISCARD = {
29
+ "profile_id" => 42,
30
+ "report_data" => false,
31
+ }
32
+
33
+ def start_command
34
+ create_agent_command(START)
35
+ end
36
+
37
+ def stop_command
38
+ create_agent_command(STOP)
39
+ end
40
+
41
+ def stop_and_discard_command
42
+ create_agent_command(STOP_AND_DISCARD)
43
+ end
44
+ end
45
+
46
+ if !NewRelic::Agent::Commands::ThreadProfiler.is_supported?
47
+
48
+ class ThreadProfilerUnsupportedTest < Test::Unit::TestCase
49
+ include ThreadProfilerTestHelpers
50
+
51
+ def setup
52
+ @profiler = NewRelic::Agent::Commands::ThreadProfiler.new
53
+ end
54
+
55
+ def test_thread_profiling_isnt_supported
56
+ assert_equal false, NewRelic::Agent::Commands::ThreadProfiler.is_supported?
57
+ end
58
+
59
+ def test_stop_is_safe_when_not_supported
60
+ @profiler.start(start_command)
61
+ @profiler.stop(true)
62
+ end
63
+
64
+ def test_wont_start_and_reports_error
65
+ errors = nil
66
+ assert_raise NewRelic::Agent::Commands::AgentCommandRouter::AgentCommandError do
67
+ @profiler.handle_start_command(start_command)
68
+ end
69
+ assert_equal false, @profiler.running?
70
+ end
71
+
72
+ end
73
+
74
+ else
75
+
76
+ require 'json'
77
+
78
+ class ThreadProfilerTest < ThreadedTestCase
79
+ include ThreadProfilerTestHelpers
80
+
81
+ def setup
82
+ super
83
+ @profiler = NewRelic::Agent::Commands::ThreadProfiler.new
84
+ end
85
+
86
+ def test_is_supported
87
+ assert NewRelic::Agent::Commands::ThreadProfiler.is_supported?
88
+ end
89
+
90
+ def test_is_not_running
91
+ assert !@profiler.running?
92
+ end
93
+
94
+ def test_is_running
95
+ @profiler.start(start_command)
96
+ assert @profiler.running?
97
+ end
98
+
99
+ def test_is_not_finished_if_no_profile_started
100
+ assert !@profiler.finished?
101
+ end
102
+
103
+ def test_can_stop_a_running_profile
104
+ @profiler.start(start_command)
105
+ assert @profiler.running?
106
+
107
+ @profiler.stop(true)
108
+
109
+ assert @profiler.finished?
110
+ assert_not_nil @profiler.harvest
111
+ end
112
+
113
+ def test_can_stop_a_running_profile_and_discard
114
+ @profiler.start(start_command)
115
+ assert @profiler.running?
116
+
117
+ @profiler.stop(false)
118
+
119
+ assert_nil @profiler.harvest
120
+ end
121
+
122
+ def test_wont_crash_if_stopping_when_not_started
123
+ @profiler.stop(true)
124
+ assert_equal false, @profiler.running?
125
+ end
126
+
127
+ def test_handle_start_command_starts_running
128
+ @profiler.handle_start_command(start_command)
129
+ assert_equal true, @profiler.running?
130
+ end
131
+
132
+ def test_handle_stop_command
133
+ @profiler.start(start_command)
134
+ assert @profiler.running?
135
+
136
+ @profiler.handle_stop_command(stop_command)
137
+ assert_equal true, @profiler.finished?
138
+ end
139
+
140
+ def test_handle_stop_command_and_discard
141
+ @profiler.start(start_command)
142
+ assert @profiler.running?
143
+
144
+ @profiler.handle_stop_command(stop_and_discard_command)
145
+ assert_nil @profiler.harvest
146
+ end
147
+
148
+ def test_handle_start_command_wont_start_second_profile
149
+ @profiler.handle_start_command(start_command)
150
+ original_profile = @profiler.instance_variable_get(:@profile)
151
+
152
+ begin
153
+ @profiler.handle_start_command(start_command)
154
+ rescue NewRelic::Agent::Commands::AgentCommandRouter::AgentCommandError
155
+ end
156
+
157
+ assert_equal original_profile, @profiler.harvest
158
+ end
159
+
160
+ def test_start_command_sent_twice_raises_error
161
+ @profiler.handle_start_command(start_command)
162
+
163
+ assert_raise NewRelic::Agent::Commands::AgentCommandRouter::AgentCommandError do
164
+ @profiler.handle_start_command(start_command)
165
+ end
166
+ end
167
+
168
+ def test_command_attributes_passed_along
169
+ @profiler.handle_start_command(start_command)
170
+ profile = @profiler.harvest
171
+ assert_equal 42, profile.profile_id
172
+ assert_equal 0.02, profile.interval
173
+ assert_equal false, profile.profile_agent_code
174
+ end
175
+
176
+ end
177
+ end
@@ -0,0 +1,81 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+
5
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
6
+ require 'new_relic/agent/configuration/default_source'
7
+
8
+ module NewRelic::Agent::Configuration
9
+ class DefaultSourceTest < Test::Unit::TestCase
10
+ def setup
11
+ @default_source = DefaultSource.new
12
+ @defaults = ::NewRelic::Agent::Configuration::DEFAULTS
13
+ end
14
+
15
+ def test_default_values_have_a_public_setting
16
+ @defaults.each do |config_setting, config_value|
17
+ assert_not_nil config_value[:public], "Config setting: #{config_setting}"
18
+ end
19
+ end
20
+
21
+ def test_default_values_have_types
22
+ @defaults.each do |config_setting, config_value|
23
+ assert_not_nil config_value[:type], "Config setting: #{config_setting}"
24
+ end
25
+ end
26
+
27
+ def test_default_values_have_descriptions
28
+ @defaults.each do |config_setting, config_value|
29
+ assert_not_nil config_value[:description]
30
+ assert config_value[:description].length > 0, "Config setting: #{config_setting}"
31
+ end
32
+ end
33
+
34
+ def test_declared_types_match_default_values
35
+ NewRelic::Control.instance.local_env.stubs(:discovered_dispatcher).returns(:unicorn)
36
+
37
+ @default_source.keys.each do |key|
38
+ default_value_class = get_config_value_class(fetch_config_value(key))
39
+ assert_equal @defaults[key][:type], default_value_class, "Config setting #{key} does not have the correct type."
40
+ end
41
+ end
42
+
43
+ def test_default_values_maps_keys_to_their_default_values
44
+ default_values = @default_source.default_values
45
+
46
+ @defaults.each do |key, value|
47
+ assert_equal value[:default], default_values[key]
48
+ end
49
+ end
50
+
51
+ def fetch_config_value(key)
52
+ accessor = key.to_sym
53
+ config = @default_source
54
+
55
+ if config.has_key?(accessor)
56
+ if config[accessor].respond_to?(:call)
57
+ value = config[accessor]
58
+
59
+ while value.respond_to?(:call)
60
+ value = config.instance_eval(&value)
61
+ end
62
+
63
+ return value
64
+ else
65
+ return config[accessor]
66
+ end
67
+ end
68
+ nil
69
+ end
70
+
71
+ def get_config_value_class(value)
72
+ type = value.class
73
+
74
+ if type == TrueClass || type == FalseClass
75
+ Boolean
76
+ else
77
+ type
78
+ end
79
+ end
80
+ end
81
+ end