newrelic_rpm 3.6.5.130 → 3.6.6.147

Sign up to get free protection for your applications and to get access to all the features.
Files changed (240) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +27 -3
  3. data/Gemfile +1 -14
  4. data/Rakefile +15 -5
  5. data/config.dot +1 -1
  6. data/lib/new_relic/agent/agent.rb +15 -0
  7. data/lib/new_relic/agent/agent_logger.rb +19 -14
  8. data/lib/new_relic/agent/configuration/defaults.rb +4 -3
  9. data/lib/new_relic/agent/configuration/environment_source.rb +6 -4
  10. data/lib/new_relic/agent/configuration/manager.rb +7 -2
  11. data/lib/new_relic/agent/configuration/mask_defaults.rb +1 -2
  12. data/lib/new_relic/agent/cross_app_monitor.rb +5 -4
  13. data/lib/new_relic/agent/cross_app_tracing.rb +0 -1
  14. data/lib/new_relic/agent/error_collector.rb +30 -1
  15. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +67 -0
  16. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +59 -0
  17. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +12 -0
  18. data/lib/new_relic/agent/instrumentation/active_merchant.rb +3 -3
  19. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +3 -3
  20. data/lib/new_relic/agent/instrumentation/authlogic.rb +3 -3
  21. data/lib/new_relic/agent/instrumentation/curb.rb +179 -0
  22. data/lib/new_relic/agent/instrumentation/data_mapper.rb +3 -3
  23. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +35 -26
  24. data/lib/new_relic/agent/instrumentation/httpclient.rb +46 -0
  25. data/lib/new_relic/agent/instrumentation/merb/controller.rb +3 -3
  26. data/lib/new_relic/agent/instrumentation/puma.rb +23 -0
  27. data/lib/new_relic/agent/instrumentation/rack.rb +40 -0
  28. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +4 -4
  29. data/lib/new_relic/agent/instrumentation/rails/errors.rb +0 -1
  30. data/lib/new_relic/agent/instrumentation/sequel.rb +0 -1
  31. data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
  32. data/lib/new_relic/agent/internal_agent_error.rb +18 -0
  33. data/lib/new_relic/agent/new_relic_service.rb +2 -8
  34. data/lib/new_relic/agent/request_sampler.rb +4 -6
  35. data/lib/new_relic/agent/samplers/cpu_sampler.rb +0 -1
  36. data/lib/new_relic/agent/stats.rb +9 -0
  37. data/lib/new_relic/agent/stats_engine/stats_hash.rb +44 -6
  38. data/lib/new_relic/agent/system_info.rb +1 -1
  39. data/lib/new_relic/agent/thread_profiler.rb +6 -6
  40. data/lib/new_relic/agent/transaction.rb +1 -1
  41. data/lib/new_relic/agent/transaction_info.rb +0 -1
  42. data/lib/new_relic/agent/transaction_sample_builder.rb +6 -5
  43. data/lib/new_relic/agent/transaction_sampler.rb +1 -1
  44. data/lib/new_relic/commands/deployments.rb +6 -0
  45. data/lib/new_relic/commands/install.rb +2 -2
  46. data/lib/new_relic/control/frameworks/rails.rb +1 -2
  47. data/lib/new_relic/control/instrumentation.rb +2 -2
  48. data/lib/new_relic/control/server_methods.rb +1 -2
  49. data/lib/new_relic/delayed_job_injection.rb +0 -40
  50. data/lib/new_relic/helper.rb +0 -1
  51. data/lib/new_relic/latest_changes.rb +1 -1
  52. data/lib/new_relic/local_environment.rb +9 -4
  53. data/lib/new_relic/metric_spec.rb +19 -3
  54. data/lib/new_relic/noticed_error.rb +2 -1
  55. data/lib/new_relic/rack/agent_hooks.rb +0 -1
  56. data/lib/new_relic/rack/developer_mode.rb +1 -1
  57. data/lib/new_relic/rack/error_collector.rb +42 -21
  58. data/lib/new_relic/recipes.rb +0 -1
  59. data/lib/new_relic/transaction_analysis.rb +0 -1
  60. data/lib/new_relic/transaction_sample/segment.rb +4 -4
  61. data/lib/new_relic/version.rb +1 -1
  62. data/lib/sequel/extensions/newrelic_instrumentation.rb +6 -7
  63. data/lib/sequel/plugins/newrelic_instrumentation.rb +0 -1
  64. data/lib/tasks/install.rake +2 -2
  65. data/newrelic_rpm.gemspec +11 -1
  66. data/test/active_record_fixtures.rb +2 -2
  67. data/test/agent_helper.rb +46 -3
  68. data/test/config/newrelic.yml +2 -2
  69. data/test/multiverse/.gitignore +2 -0
  70. data/test/multiverse/lib/multiverse/envfile.rb +6 -9
  71. data/test/multiverse/lib/multiverse/environment.rb +0 -1
  72. data/test/multiverse/lib/multiverse/output_collector.rb +43 -11
  73. data/test/multiverse/lib/multiverse/runner.rb +37 -5
  74. data/test/multiverse/lib/multiverse/suite.rb +149 -67
  75. data/test/multiverse/script/run_one +4 -2
  76. data/test/multiverse/script/runner +1 -5
  77. data/test/multiverse/suites/active_record/Envfile +3 -2
  78. data/test/multiverse/suites/active_record/ar_method_aliasing.rb +13 -12
  79. data/test/multiverse/suites/active_record/config/newrelic.yml +0 -3
  80. data/test/multiverse/suites/agent_only/audit_log_test.rb +30 -34
  81. data/test/multiverse/suites/agent_only/before_suite.rb +7 -0
  82. data/test/multiverse/suites/agent_only/config/newrelic.yml +1 -7
  83. data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +12 -20
  84. data/test/multiverse/suites/agent_only/http_response_code_test.rb +16 -34
  85. data/test/multiverse/suites/agent_only/key_transactions_test.rb +18 -28
  86. data/test/multiverse/suites/agent_only/logging_test.rb +25 -49
  87. data/test/multiverse/suites/agent_only/marshaling_test.rb +30 -38
  88. data/test/multiverse/suites/agent_only/pipe_manager_test.rb +12 -6
  89. data/test/multiverse/suites/agent_only/rename_rule_test.rb +30 -38
  90. data/test/multiverse/suites/agent_only/rum_instrumentation_test.rb +16 -18
  91. data/test/multiverse/suites/agent_only/service_timeout_test.rb +6 -7
  92. data/test/multiverse/suites/agent_only/set_transaction_name_test.rb +26 -32
  93. data/test/multiverse/suites/agent_only/ssl_test.rb +10 -14
  94. data/test/multiverse/suites/agent_only/start_up_test.rb +1 -1
  95. data/test/multiverse/suites/agent_only/testing_app.rb +2 -0
  96. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +23 -24
  97. data/test/multiverse/suites/config_file_loading/Envfile +6 -2
  98. data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +8 -4
  99. data/test/multiverse/suites/curb/Envfile +19 -0
  100. data/test/multiverse/suites/curb/config/newrelic.yml +19 -0
  101. data/test/multiverse/suites/curb/curb_test.rb +195 -0
  102. data/test/multiverse/suites/datamapper/Envfile +2 -0
  103. data/test/multiverse/suites/datamapper/config/newrelic.yml +0 -2
  104. data/test/multiverse/suites/datamapper/datamapper_test.rb +6 -10
  105. data/test/multiverse/suites/deferred_instrumentation/Envfile +19 -0
  106. data/test/multiverse/suites/deferred_instrumentation/config/newrelic.yml +22 -0
  107. data/test/multiverse/suites/deferred_instrumentation/sinatra_test.rb +103 -0
  108. data/test/multiverse/suites/excon/config/newrelic.yml +0 -2
  109. data/test/multiverse/suites/excon/excon_test.rb +3 -3
  110. data/test/multiverse/suites/httpclient/Envfile +15 -0
  111. data/test/multiverse/suites/httpclient/config/newrelic.yml +19 -0
  112. data/test/multiverse/suites/httpclient/httpclient_test.rb +70 -0
  113. data/test/multiverse/suites/net_http/config/newrelic.yml +0 -2
  114. data/test/multiverse/suites/net_http/net_http_test.rb +9 -4
  115. data/test/multiverse/suites/padrino/Envfile +2 -0
  116. data/test/multiverse/suites/padrino/config/newrelic.yml +0 -3
  117. data/test/multiverse/suites/padrino/padrino_test.rb +5 -4
  118. data/test/multiverse/suites/rails/Envfile +3 -0
  119. data/test/multiverse/suites/rails/app.rb +1 -0
  120. data/test/multiverse/suites/rails/bad_instrumentation_test.rb +31 -0
  121. data/test/multiverse/suites/rails/config/newrelic.yml +2 -3
  122. data/test/multiverse/suites/rails/error_tracing_test.rb +32 -41
  123. data/test/multiverse/suites/rails/gc_instrumentation_test.rb +6 -16
  124. data/test/multiverse/suites/rails/queue_time_test.rb +4 -20
  125. data/test/multiverse/suites/rails/request_statistics_test.rb +7 -32
  126. data/test/multiverse/suites/rails/view_instrumentation_test.rb +6 -10
  127. data/test/multiverse/suites/resque/config/newrelic.yml +1 -3
  128. data/test/multiverse/suites/resque/instrumentation_test.rb +10 -7
  129. data/test/multiverse/suites/sequel/Envfile +8 -0
  130. data/test/multiverse/suites/sequel/config/newrelic.yml +0 -3
  131. data/test/multiverse/suites/sequel/sequel_test.rb +1 -2
  132. data/test/multiverse/suites/sidekiq/Envfile +0 -12
  133. data/test/multiverse/suites/sidekiq/config/newrelic.yml +1 -3
  134. data/test/multiverse/suites/sidekiq/sidekiq_instrumentation_test.rb +44 -100
  135. data/test/multiverse/suites/sinatra/config/newrelic.yml +0 -3
  136. data/test/multiverse/suites/sinatra/ignoring_test.rb +8 -5
  137. data/test/multiverse/suites/sinatra/sinatra_classic_test.rb +8 -1
  138. data/test/multiverse/suites/sinatra/sinatra_error_tracing_test.rb +9 -12
  139. data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +9 -8
  140. data/test/multiverse/suites/sinatra/sinatra_modular_test.rb +1 -1
  141. data/test/multiverse/suites/sinatra/sinatra_routes_test.rb +6 -5
  142. data/test/multiverse/suites/sinatra/sinatra_test_cases.rb +10 -13
  143. data/test/multiverse/suites/typhoeus/config/newrelic.yml +0 -2
  144. data/test/multiverse/suites/typhoeus/typhoeus_test.rb +7 -4
  145. data/test/multiverse/test/suite_examples/one/a/a_test.rb +0 -1
  146. data/test/multiverse/test/suite_examples/one/a/config/newrelic.yml +0 -1
  147. data/test/multiverse/test/suite_examples/one/b/b_test.rb +0 -1
  148. data/test/multiverse/test/suite_examples/one/b/config/newrelic.yml +0 -1
  149. data/test/new_relic/agent/agent/connect_test.rb +1 -1
  150. data/test/new_relic/agent/agent/start_test.rb +0 -1
  151. data/test/new_relic/agent/agent/start_worker_thread_test.rb +0 -1
  152. data/test/new_relic/agent/agent_logger_test.rb +37 -3
  153. data/test/new_relic/agent/agent_test.rb +23 -1
  154. data/test/new_relic/agent/browser_monitoring_test.rb +0 -1
  155. data/test/new_relic/agent/busy_calculator_test.rb +2 -2
  156. data/test/new_relic/agent/configuration/environment_source_test.rb +22 -0
  157. data/test/new_relic/agent/error_collector/notice_error_test.rb +1 -1
  158. data/test/new_relic/agent/error_collector_test.rb +95 -13
  159. data/test/new_relic/agent/event_listener_test.rb +0 -1
  160. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +23 -0
  161. data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +4 -2
  162. data/test/new_relic/agent/instrumentation/instrumentation_test.rb +0 -1
  163. data/test/new_relic/agent/instrumentation/queue_time_test.rb +16 -11
  164. data/test/new_relic/agent/instrumentation/rack_test.rb +0 -1
  165. data/test/new_relic/agent/memcache_instrumentation_test.rb +7 -7
  166. data/test/{multiverse/suites/agent_only/test_trace_method_with_punctuation.rb → new_relic/agent/method_interrobang_test.rb} +3 -5
  167. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +1 -2
  168. data/test/{multiverse/suites/agent_only → new_relic/agent}/method_visibility_test.rb +17 -29
  169. data/test/new_relic/agent/new_relic_service_test.rb +1 -1
  170. data/test/new_relic/agent/pipe_service_test.rb +1 -1
  171. data/test/new_relic/agent/request_sampler_test.rb +10 -10
  172. data/test/new_relic/agent/rpm_agent_test.rb +1 -2
  173. data/test/new_relic/agent/stats_hash_test.rb +83 -5
  174. data/test/new_relic/agent/stats_test.rb +0 -1
  175. data/test/new_relic/agent/thread_profiler_test.rb +7 -7
  176. data/test/new_relic/agent/threaded_test.rb +1 -2
  177. data/test/new_relic/agent/transaction/pop_test.rb +0 -1
  178. data/test/{multiverse/suites/agent_only/test_trace_transaction_with_punctuation.rb → new_relic/agent/transaction_interrobang_test.rb} +2 -4
  179. data/test/new_relic/agent/transaction_sample_builder_test.rb +13 -0
  180. data/test/new_relic/agent/transaction_test.rb +7 -5
  181. data/test/new_relic/agent/worker_loop_test.rb +0 -1
  182. data/test/new_relic/agent_test.rb +0 -27
  183. data/test/new_relic/collection_helper_test.rb +17 -17
  184. data/test/new_relic/control/class_methods_test.rb +1 -1
  185. data/test/new_relic/control_test.rb +6 -6
  186. data/test/new_relic/dependency_detection_test.rb +28 -0
  187. data/test/new_relic/evil_server.rb +0 -1
  188. data/test/new_relic/fake_collector.rb +20 -2
  189. data/test/new_relic/fake_server.rb +0 -12
  190. data/test/new_relic/http_client_test_cases.rb +20 -24
  191. data/test/new_relic/metric_spec_test.rb +18 -0
  192. data/test/new_relic/multiverse_helpers.rb +164 -0
  193. data/test/new_relic/rack/agent_hooks_test.rb +0 -1
  194. data/test/new_relic/rack/all_test.rb +0 -1
  195. data/test/new_relic/rack/deferred_instrumentation_test.rb +35 -0
  196. data/test/new_relic/rack/developer_mode_helper_test.rb +8 -9
  197. data/test/new_relic/rack/developer_mode_test.rb +0 -2
  198. data/test/new_relic/rack/error_collector_test.rb +52 -8
  199. data/test/new_relic/transaction_sample/composite_segment_test.rb +0 -1
  200. data/test/new_relic/transaction_sample/fake_segment_test.rb +0 -1
  201. data/test/new_relic/transaction_sample/segment_test.rb +0 -1
  202. data/test/new_relic/transaction_sample/summary_segment_test.rb +0 -1
  203. data/test/performance/README.md +162 -0
  204. data/test/performance/lib/performance.rb +28 -0
  205. data/test/performance/lib/performance/console_reporter.rb +51 -0
  206. data/test/performance/lib/performance/hako_client.rb +31 -0
  207. data/test/performance/lib/performance/hako_reporter.rb +26 -0
  208. data/test/performance/lib/performance/instrumentation/cpu_usage.rb +26 -0
  209. data/test/performance/lib/performance/instrumentation/gc_stats.rb +53 -0
  210. data/test/performance/lib/performance/instrumentation/perf_tools.rb +30 -0
  211. data/test/performance/lib/performance/instrumentor.rb +110 -0
  212. data/test/performance/lib/performance/json_reporter.rb +15 -0
  213. data/test/performance/lib/performance/result.rb +80 -0
  214. data/test/performance/lib/performance/runner.rb +207 -0
  215. data/test/performance/lib/performance/test_case.rb +65 -0
  216. data/test/performance/lib/performance/timer.rb +38 -0
  217. data/test/performance/script/mega-runner +37 -0
  218. data/test/performance/script/runner +81 -0
  219. data/test/performance/suites/startup.rb +12 -0
  220. data/test/performance/suites/transaction_tracing.rb +66 -0
  221. data/test/script/ci_agent-tests_runner.sh +4 -4
  222. data/test/script/ci_multiverse_runner.sh +3 -3
  223. data/test/test_helper.rb +0 -11
  224. data/ui/helpers/developer_mode_helper.rb +1 -1
  225. data/ui/views/layouts/newrelic_default.rhtml +1 -1
  226. data/ui/views/newrelic/_segment.rhtml +2 -2
  227. data/ui/views/newrelic/_segment_limit_message.rhtml +1 -1
  228. data/ui/views/newrelic/_show_sample_detail.rhtml +1 -1
  229. data/ui/views/newrelic/_show_sample_sql.rhtml +4 -4
  230. data/ui/views/newrelic/_stack_trace.rhtml +2 -2
  231. data/ui/views/newrelic/file/javascript/transaction_sample.js +3 -3
  232. data/ui/views/newrelic/file/stylesheets/style.css +13 -13
  233. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +18 -4
  234. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +0 -1
  235. metadata +186 -17
  236. metadata.gz.sig +0 -0
  237. data/test/multiverse/suites/active_record/encoding_test.rb +0 -30
  238. data/test/multiverse/suites/agent_only/no_dns_resolv.rb +0 -21
  239. data/test/multiverse/suites/sidekiq/app.rb +0 -25
  240. data/test/new_relic/delayed_job_injection_test.rb +0 -25
@@ -2,9 +2,16 @@
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
- class SetTransactionNameTest < Test::Unit::TestCase
5
+ require 'multiverse_helpers'
6
+
7
+ class SetTransactionNameTest < MiniTest::Unit::TestCase
6
8
  include NewRelic::Agent::MethodTracer
7
9
 
10
+ include MultiverseHelpers
11
+
12
+ setup_and_teardown_agent(:browser_key => 'browserKey', :application_id => 'appId',
13
+ :beacon => 'beacon', :episodes_file => 'this_is_my_file')
14
+
8
15
  class TestTransactor
9
16
  include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
10
17
  def parent_txn
@@ -25,46 +32,33 @@ class SetTransactionNameTest < Test::Unit::TestCase
25
32
  end
26
33
  end
27
34
 
28
- def setup
29
- NewRelic::Agent.manual_start(:browser_key => 'browserKey', :application_id => 'appId',
30
- :beacon => 'beacon', :episodes_file => 'this_is_my_file')
31
- @transactor = TestTransactor.new
32
- @stats_engine = NewRelic::Agent.instance.stats_engine
33
- end
34
-
35
- def teardown
36
- NewRelic::Agent.shutdown
37
- end
38
-
39
35
  def test_apply_to_metric_names
40
- @transactor.parent_txn
41
- [ 'Controller/TestTransactor/parent',
36
+ TestTransactor.new.parent_txn
37
+
38
+ assert_metrics_recorded([
39
+ 'Controller/TestTransactor/parent',
42
40
  'OtherTransaction/Background/TestTransactor/child',
43
- [ 'OtherTransaction/Background/TestTransactor/child',
44
- 'Controller/TestTransactor/parent'],
45
- 'Apdex/TestTransactor/parent' ].each do |metric|
46
- assert(@stats_engine.lookup_stats(*metric),
47
- "Expected to find #{metric} in stats hash #{NewRelic::Agent.instance.stats_engine.instance_variable_get(:@stats_hash)}")
48
- end
41
+ [ 'OtherTransaction/Background/TestTransactor/child', 'Controller/TestTransactor/parent'],
42
+ 'Apdex/TestTransactor/parent'])
49
43
  end
50
44
 
51
45
  def test_apply_to_metric_scopes
52
- @transactor.parent_txn do
46
+ TestTransactor.new.parent_txn do
53
47
  trace_execution_scoped('Custom/something') {}
54
48
  end
55
- assert @stats_engine.lookup_stats('Custom/something',
56
- 'Controller/TestTransactor/parent')
49
+ assert_metrics_recorded(['Custom/something',
50
+ 'Controller/TestTransactor/parent'])
57
51
  end
58
52
 
59
53
  def test_apply_to_traced_transactions
60
- @transactor.parent_txn
54
+ TestTransactor.new.parent_txn
61
55
  assert_equal('Controller/TestTransactor/parent',
62
56
  NewRelic::Agent.instance.transaction_sampler.last_sample \
63
57
  .params[:path])
64
58
  end
65
59
 
66
60
  def test_apply_to_traced_errors
67
- @transactor.parent_txn do
61
+ TestTransactor.new.parent_txn do
68
62
  NewRelic::Agent.notice_error(RuntimeError.new('toot'))
69
63
  end
70
64
  assert_equal('Controller/TestTransactor/parent',
@@ -75,22 +69,22 @@ class SetTransactionNameTest < Test::Unit::TestCase
75
69
  rule = NewRelic::Agent::RulesEngine::Rule.new('match_expression' => 'parent',
76
70
  'replacement' => 'dad')
77
71
  NewRelic::Agent.instance.transaction_rules << rule
78
- @transactor.parent_txn
79
- assert @stats_engine.lookup_stats('Controller/TestTransactor/dad')
72
+ TestTransactor.new.parent_txn
73
+ assert_metrics_recorded(['Controller/TestTransactor/dad'])
80
74
  end
81
75
 
82
76
  def test_does_not_overwrite_name_when_set_by_RUM
83
- @transactor.parent_txn do
77
+ TestTransactor.new.parent_txn do
84
78
  NewRelic::Agent.browser_timing_header
85
79
  NewRelic::Agent.browser_timing_footer
86
80
  NewRelic::Agent.set_transaction_name('this/should/not/work')
87
81
  end
88
- assert_nil @stats_engine.lookup_stats('Controller/this/should/not/work')
89
- assert @stats_engine.lookup_stats('Controller/TestTransactor/parent')
82
+ assert_metrics_not_recorded(['Controller/this/should/not/work'])
83
+ assert_metrics_recorded(['Controller/TestTransactor/parent'])
90
84
  end
91
85
 
92
86
  def test_ignoring_action
93
- @transactor.ignored_txn
94
- assert_nil @stats_engine.lookup_stats('Controller/Ignore/me')
87
+ TestTransactor.new.ignored_txn
88
+ assert_metrics_not_recorded(['Controller/Ignore/me'])
95
89
  end
96
90
  end
@@ -2,25 +2,21 @@
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
- class SSLTest < Test::Unit::TestCase
5
+ require 'multiverse_helpers'
6
+
7
+ class SSLTest < MiniTest::Unit::TestCase
8
+
9
+ include MultiverseHelpers
6
10
 
7
11
  def setup
8
- # This is similar to how jruby 1.6.8 behaves when jruby-openssl isn't
9
- # installed
10
- @original_ssl_config = NewRelic::Agent.config[:ssl]
11
- NewRelic::Agent.config.apply_config(:ssl => true)
12
- NewRelic::Agent.agent = NewRelic::Agent::Agent.new
12
+ # Similar to how jruby 1.6.8 behaves when jruby-openssl isn't installed
13
13
  Net::HTTPSession.any_instance.stubs('use_ssl=').raises(LoadError)
14
14
  end
15
15
 
16
- def teardown
17
- NewRelic::Agent.config.apply_config(:ssl => @original_ssl_config)
18
- end
19
-
20
16
  def test_agent_shuts_down_when_ssl_is_on_but_unavailable
21
- ::NewRelic::Agent.agent.expects(:shutdown)
22
- ::NewRelic::Agent.expects(:finish_setup).never
23
- ::NewRelic::Agent.agent.connect_in_foreground
24
- ensure
17
+ NewRelic::Agent.agent.expects(:shutdown).at_least_once
18
+ NewRelic::Agent.expects(:finish_setup).never
19
+
20
+ run_agent(:ssl => true)
25
21
  end
26
22
  end
@@ -5,7 +5,7 @@
5
5
  # RUBY-839 make sure there is no STDOUT chatter
6
6
  require 'open3'
7
7
 
8
- class StartUpTest < Test::Unit::TestCase
8
+ class StartUpTest < MiniTest::Unit::TestCase
9
9
  def test_should_not_print_to_stdout_when_logging_available
10
10
  ruby = 'require "newrelic_rpm"; NewRelic::Agent.manual_start; NewRelic::Agent.shutdown'
11
11
  cmd = "bundle exec ruby -e '#{ruby}'"
@@ -2,6 +2,8 @@
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
+ require 'new_relic/agent/instrumentation/rack'
6
+
5
7
  class TestingApp
6
8
 
7
9
  attr_accessor :response, :headers
@@ -6,28 +6,28 @@
6
6
  # https://newrelic.atlassian.net/browse/RUBY-917
7
7
 
8
8
  if RUBY_VERSION >= '1.9'
9
- class ThreadProfilingTest < Test::Unit::TestCase
10
- def setup
11
- $collector ||= NewRelic::FakeCollector.new
12
- $collector.reset
13
- $collector.mock['connect'] = [200, {'return_value' => {"agent_run_id" => 666 }}]
14
- $collector.mock['get_agent_commands'] = [200, {'return_value' => START_COMMAND}]
15
- $collector.mock['agent_command_results'] = [200, {'return_value' => []}]
16
- $collector.run
17
-
18
- NewRelic::Agent::Agent.instance_variable_set(:@instance, nil)
19
- NewRelic::Agent.manual_start(:'thread_profiler.enabled' => true, :force_send => true)
20
- NewRelic::Agent.instance.service.request_timeout = 0.5
21
- NewRelic::Agent.instance.service.agent_id = 666
22
-
23
- @agent = NewRelic::Agent.instance
24
- @thread_profiler = @agent.thread_profiler
25
- @threads = []
9
+
10
+ require 'multiverse_helpers'
11
+
12
+ class ThreadProfilingTest < MiniTest::Unit::TestCase
13
+
14
+ include MultiverseHelpers
15
+
16
+ setup_and_teardown_agent(:'thread_profiler.enabled' => true, :force_send => true) do |collector|
17
+ collector.stub('connect', {"agent_run_id" => 666 })
18
+ collector.stub('get_agent_commands', START_COMMAND)
19
+ collector.stub('agent_command_results', [])
26
20
  end
27
21
 
28
- def teardown
29
- $collector.reset
22
+ def after_setup
23
+ agent.service.request_timeout = 0.5
24
+ agent.service.agent_id = 666
30
25
 
26
+ @thread_profiler = agent.thread_profiler
27
+ @threads = []
28
+ end
29
+
30
+ def after_teardown
31
31
  @threads.each { |t| t.kill }
32
32
  @threads = nil
33
33
  end
@@ -60,7 +60,7 @@ class ThreadProfilingTest < Test::Unit::TestCase
60
60
  # go only let a few cycles through, so we check less than 10
61
61
 
62
62
  def test_thread_profiling
63
- @agent.send(:check_for_agent_commands)
63
+ agent.send(:check_for_agent_commands)
64
64
 
65
65
  run_thread { NewRelic::Agent::Transaction.start(:controller, :request => stub) }
66
66
  run_thread { NewRelic::Agent::Transaction.start(:task) }
@@ -78,10 +78,10 @@ class ThreadProfilingTest < Test::Unit::TestCase
78
78
  end
79
79
 
80
80
  def test_thread_profiling_can_stop
81
- @agent.send(:check_for_agent_commands)
81
+ agent.send(:check_for_agent_commands)
82
82
 
83
83
  $collector.mock['get_agent_commands'] = [200, {'return_value' => STOP_COMMAND}]
84
- @agent.send(:check_for_agent_commands)
84
+ agent.send(:check_for_agent_commands)
85
85
 
86
86
  let_it_finish
87
87
 
@@ -105,7 +105,7 @@ class ThreadProfilingTest < Test::Unit::TestCase
105
105
  end
106
106
  end
107
107
 
108
- @agent.send(:transmit_data, true)
108
+ agent.send(:transmit_data, true)
109
109
  end
110
110
 
111
111
  def assert_saw_traces(profile_data, type)
@@ -114,4 +114,3 @@ class ThreadProfilingTest < Test::Unit::TestCase
114
114
 
115
115
  end
116
116
  end
117
-
@@ -1,9 +1,13 @@
1
- # don't start the agent
2
- self.newrelic_gemfile_options=(':require => false')
1
+ omit_collector!
2
+
3
3
  gemfile <<-RB
4
4
  # stub file system so we can test that newrelic.yml can be loaded from
5
5
  # various places.
6
6
  gem 'fakefs', :require => 'fakefs/safe'
7
7
 
8
+ # Because we delay the agent, order of jruby-openssl matters
8
9
  gem 'jruby-openssl', :platforms => [:jruby]
10
+
11
+ # don't start the agent
12
+ gem 'newrelic_rpm', :require => false, :path => File.expand_path('../../../../')
9
13
  RB
@@ -13,7 +13,11 @@
13
13
  #
14
14
  # If this fails the agent will attempt to dial Lew Cirne's cell phone and ask
15
15
  # that he verbally describe how it should be configured.
16
- class ConfigFileLoadingTest < Test::Unit::TestCase
16
+
17
+ require 'multiverse_helpers'
18
+
19
+ class ConfigFileLoadingTest < MiniTest::Unit::TestCase
20
+ include MultiverseHelpers
17
21
 
18
22
  def setup
19
23
  # While FakeFS stubs out all the File system related libraries (i.e. File,
@@ -45,7 +49,8 @@ class ConfigFileLoadingTest < Test::Unit::TestCase
45
49
  end
46
50
 
47
51
  def setup_config(path, manual_config_options = {})
48
- NewRelic::Agent.shutdown
52
+ teardown_agent
53
+
49
54
  FileUtils.mkdir_p(File.dirname(path))
50
55
  Dir.chdir @cwd
51
56
  File.open(path, 'w') do |f|
@@ -58,8 +63,7 @@ bazbangbarn:
58
63
  i_am: "bazbangbarn"
59
64
  YAML
60
65
  end
61
- NewRelic::Agent.reset_config
62
- NewRelic::Agent.manual_start(manual_config_options)
66
+ setup_agent(manual_config_options)
63
67
  end
64
68
 
65
69
  def assert_config_read_from(path)
@@ -0,0 +1,19 @@
1
+ suite_condition("Curb is not useful on JRuby") do
2
+ RUBY_PLATFORM != 'java'
3
+ end
4
+
5
+ gemfile <<-RB
6
+ gem 'curb', '0.8.1'
7
+ gem 'rack'
8
+ if RUBY_VERSION < '1.9.0'
9
+ gem 'json'
10
+ end
11
+ RB
12
+
13
+ gemfile <<-RB
14
+ gem 'curb', '~> 0.8.4'
15
+ gem 'rack'
16
+ if RUBY_VERSION < '1.9.0'
17
+ gem 'json'
18
+ end
19
+ RB
@@ -0,0 +1,19 @@
1
+ ---
2
+ development:
3
+ error_collector:
4
+ capture_source: true
5
+ enabled: true
6
+ apdex_t: 0.5
7
+ ssl: false
8
+ monitor_mode: true
9
+ license_key: bootstrap_newrelic_admin_license_key_000
10
+ developer_mode: false
11
+ app_name: test
12
+ host: 127.0.0.1
13
+ api_host: 127.0.0.1
14
+ transaction_tracer:
15
+ record_sql: obfuscated
16
+ enabled: true
17
+ stack_trace_threshold: 0.5
18
+ transaction_threshold: 1.0
19
+ capture_params: false
@@ -0,0 +1,195 @@
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 'curb'
6
+
7
+ require 'newrelic_rpm'
8
+ require 'test/unit'
9
+ require 'http_client_test_cases'
10
+ require 'new_relic/agent/http_clients/curb_wrappers'
11
+
12
+ require File.join(File.dirname(__FILE__), "..", "..", "..", "agent_helper")
13
+
14
+ class CurbTest < MiniTest::Unit::TestCase
15
+
16
+ #
17
+ # Tests
18
+ #
19
+
20
+ include HttpClientTestCases
21
+
22
+
23
+ def test_shouldnt_clobber_existing_header_callback
24
+ headers = []
25
+ Curl::Easy.http_get( default_url ) do |handle|
26
+ handle.on_header do |header|
27
+ headers << header
28
+ header.length
29
+ end
30
+ end
31
+
32
+ assert !headers.empty?
33
+ end
34
+
35
+ def test_shouldnt_clobber_existing_completion_callback
36
+ completed = false
37
+ Curl::Easy.http_get( default_url ) do |handle|
38
+ handle.on_complete do
39
+ completed = true
40
+ end
41
+ end
42
+
43
+ assert completed, "completion block was never run"
44
+ end
45
+
46
+ def test_get_works_with_the_shortcut_api
47
+ # Override the mechanism for getting a response and run the test_get test
48
+ # again
49
+ @get_response_proc = Proc.new do |url|
50
+ Curl.get( url || default_url )
51
+ end
52
+ test_get
53
+ ensure
54
+ @get_response_proc = nil
55
+ end
56
+
57
+ def test_background_works_with_the_shortcut_api
58
+ # Override the mechanism for getting a response and run test_background again
59
+ @get_response_proc = Proc.new do |url|
60
+ Curl.get( url || default_url )
61
+ end
62
+ test_background
63
+ ensure
64
+ @get_response_proc = nil
65
+ end
66
+
67
+ def test_get_via_shortcut_api_preserves_header_str
68
+ rsp = Curl.get( default_url )
69
+ header_str = rsp.header_str
70
+
71
+ # Make sure that we got something that looks like a header string
72
+ assert_match(/^HTTP\/1\.1 200 OK\s+$/, header_str)
73
+ assert_match(/^Content-Length: \d+\s+$/, header_str)
74
+
75
+ # Make sure there are no lines that appear multiple times, which would
76
+ # happen if we installed callbacks repeatedly on one request.
77
+ header_lines = header_str.split
78
+ assert_equal(header_lines.uniq.size, header_lines.size,
79
+ "Found some header lines appearing multiple times in header_str:\n#{header_str}")
80
+ end
81
+
82
+ def test_get_doesnt_destroy_ability_to_call_status
83
+ status_code = Curl.get( default_url ).status.to_i
84
+ assert_equal(200, status_code)
85
+ end
86
+
87
+
88
+ # Curl.head is broken in 0.8.4 (https://github.com/taf2/curb/pull/148), but if
89
+ # it ever gets fixed, then this test should be uncommented.
90
+
91
+ # def test_head_works_with_the_shortcut_api
92
+ # # Override the mechanism for getting a response and run the test_get test
93
+ # # again
94
+ # def self.head_response
95
+ # Curl.head( default_url )
96
+ # end
97
+ #
98
+ # test_head
99
+ # end
100
+
101
+ def test_doesnt_propagate_errors_in_instrumentation
102
+ NewRelic::Agent::CrossAppTracing.stubs( :start_trace ).
103
+ raises( StandardError, "something bad happened" )
104
+
105
+ res = Curl::Easy.http_get( default_url )
106
+
107
+ assert_kind_of Curl::Easy, res
108
+ end
109
+
110
+
111
+ def test_works_with_parallel_fetches
112
+ results = []
113
+ other_url = "http://localhost:#{$fake_server.port}/"
114
+
115
+ in_transaction("test") do
116
+ Curl::Multi.get( [default_url,other_url] ) do |easy|
117
+ results << easy.body_str
118
+ end
119
+
120
+ results.each do |res|
121
+ assert_match %r/<head>/i, res
122
+ end
123
+
124
+ last_segment = find_last_transaction_segment()
125
+ assert_equal "External/Multiple/Curb::Multi/perform", last_segment.metric_name
126
+ end
127
+ end
128
+
129
+ def test_block_passed_to_multi_perform_should_be_called
130
+ successes = 0
131
+ num_requests = 2
132
+ perform_block_called = false
133
+
134
+ in_transaction("test") do
135
+ multi = Curl::Multi.new
136
+
137
+ num_requests.times do |i|
138
+ req = Curl::Easy.new(default_url) do |easy|
139
+ easy.on_success { |curl| successes += 1 }
140
+ end
141
+ multi.add(req)
142
+ end
143
+
144
+ multi.perform { perform_block_called = true }
145
+
146
+ assert_equal(num_requests, successes)
147
+ assert(perform_block_called, "Block passed to Curl::Multi.perform should have been called")
148
+ last_segment = find_last_transaction_segment()
149
+ assert_equal "External/Multiple/Curb::Multi/perform", last_segment.metric_name
150
+ end
151
+ end
152
+
153
+ #
154
+ # Helper functions
155
+ #
156
+
157
+ def client_name
158
+ "Curb"
159
+ end
160
+
161
+ def get_response(url=nil)
162
+ if @get_response_proc
163
+ @get_response_proc.call(url)
164
+ else
165
+ Curl::Easy.http_get( url || default_url )
166
+ end
167
+ end
168
+
169
+ def head_response
170
+ Curl::Easy.http_head( default_url )
171
+ end
172
+
173
+ def post_response
174
+ Curl::Easy.http_post( default_url, '' )
175
+ end
176
+
177
+ def body(res)
178
+ res.body_str
179
+ end
180
+
181
+ def request_instance
182
+ NewRelic::Agent::HTTPClients::CurbRequest.new(Curl::Easy.new)
183
+ end
184
+
185
+ def response_instance( headers={} )
186
+ res = NewRelic::Agent::HTTPClients::CurbResponse.new(Curl::Easy.new)
187
+ headers.each do |hdr, val|
188
+ res.append_header_data( "#{hdr}: #{val}")
189
+ end
190
+
191
+ return res
192
+ end
193
+
194
+ end
195
+