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
@@ -597,6 +597,29 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
597
597
  end
598
598
  end
599
599
 
600
+
601
+ class ActiveRecordQueryEncodingTest < Test::Unit::TestCase
602
+
603
+ class DatabaseAdapter
604
+ # we patch in here
605
+ def log(*args)
606
+ end
607
+ include ::NewRelic::Agent::Instrumentation::ActiveRecord
608
+ end
609
+
610
+ def test_should_not_bomb_out_if_a_query_is_in_an_invalid_encoding
611
+ # Contains invalid UTF8 Byte
612
+ query = "select ICS95095010000000000083320000BS01030000004100+\xFF00000000000000000"
613
+ if RUBY_VERSION >= '1.9'
614
+ # Force the query to an invalid encoding
615
+ query.force_encoding 'UTF-8'
616
+ assert_equal false, query.valid_encoding?
617
+ end
618
+ db = DatabaseAdapter.new
619
+ db.send(:log, query)
620
+ end
621
+ end
622
+
600
623
  else
601
624
  puts "Skipping tests in #{__FILE__} because Rails is unavailable"
602
625
  end
@@ -2,7 +2,9 @@
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
- if defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i >= 4 && !NewRelic::LanguageSupport.using_engine?('jruby')
5
+ MIN_RAILS_VERSION = 4
6
+
7
+ if defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i >= MIN_RAILS_VERSION && !NewRelic::LanguageSupport.using_engine?('jruby')
6
8
 
7
9
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
8
10
  require 'new_relic/agent/instrumentation/active_record_subscriber'
@@ -131,5 +133,5 @@ class NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest < Test::Unit:
131
133
  end
132
134
 
133
135
  else
134
- puts "Skipping tests in #{__FILE__} because Rails is unavailable"
136
+ puts "Skipping tests in #{__FILE__} because Rails >= #{MIN_RAILS_VERSION} is unavailable"
135
137
  end
@@ -12,4 +12,3 @@ class NewRelic::Agent::Instrumentation::InstrumentationTest < Test::Unit::TestCa
12
12
  require 'new_relic/delayed_job_injection'
13
13
  end
14
14
  end
15
-
@@ -6,19 +6,23 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'te
6
6
  class NewRelic::Agent::Instrumentation::QueueTimeTest < Test::Unit::TestCase
7
7
  include NewRelic::Agent::Instrumentation
8
8
 
9
+ def setup
10
+ freeze_time
11
+ end
12
+
9
13
  def test_parse_frontend_timestamp_given_queue_start_header
10
14
  header = { 'HTTP_X_QUEUE_START' => format_header_time(Time.now - 60) }
11
- assert_in_delta(seconds_ago(60), QueueTime.parse_frontend_timestamp(header), 0.1)
15
+ assert_in_delta(seconds_ago(60), QueueTime.parse_frontend_timestamp(header), 0.001)
12
16
  end
13
17
 
14
18
  def test_parse_frontend_timestamp_given_request_start_header
15
19
  header = { 'HTTP_X_REQUEST_START' => format_header_time(Time.now - 60) }
16
- assert_in_delta(seconds_ago(60), QueueTime.parse_frontend_timestamp(header), 0.1)
20
+ assert_in_delta(seconds_ago(60), QueueTime.parse_frontend_timestamp(header), 0.001)
17
21
  end
18
22
 
19
23
  def test_parse_frontend_timestamp_given_middleware_start_header
20
24
  header = { 'HTTP_X_MIDDLEWARE_START' => format_header_time(Time.now - 60) }
21
- assert_in_delta(seconds_ago(60), QueueTime.parse_frontend_timestamp(header), 0.1)
25
+ assert_in_delta(seconds_ago(60), QueueTime.parse_frontend_timestamp(header), 0.001)
22
26
  end
23
27
 
24
28
  def test_parse_frontend_timestamp_from_earliest_header
@@ -26,7 +30,7 @@ class NewRelic::Agent::Instrumentation::QueueTimeTest < Test::Unit::TestCase
26
30
  'HTTP_X_QUEUE_START' => format_header_time(Time.now - 62),
27
31
  'HTTP_X_MIDDLEWARE_START' => format_header_time(Time.now - 61)}
28
32
 
29
- assert_in_delta(seconds_ago(63), QueueTime.parse_frontend_timestamp(headers), 0.1)
33
+ assert_in_delta(seconds_ago(63), QueueTime.parse_frontend_timestamp(headers), 0.001)
30
34
  end
31
35
 
32
36
  def test_parse_frontend_timestamp_from_earliest_header_out_of_order
@@ -34,39 +38,40 @@ class NewRelic::Agent::Instrumentation::QueueTimeTest < Test::Unit::TestCase
34
38
  'HTTP_X_REQUEST_START' => format_header_time(Time.now - 62),
35
39
  'HTTP_X_QUEUE_START' => format_header_time(Time.now - 61) }
36
40
 
37
- assert_in_delta(seconds_ago(63), QueueTime.parse_frontend_timestamp(headers), 0.1)
41
+ assert_in_delta(seconds_ago(63), QueueTime.parse_frontend_timestamp(headers), 0.001)
38
42
  end
39
43
 
40
44
  def test_parse_frontend_timestamp_from_header_in_seconds
41
45
  header = { 'HTTP_X_QUEUE_START' => "t=#{Time.now.to_f - 60}" }
42
- assert_in_delta(seconds_ago(60), QueueTime.parse_frontend_timestamp(header), 0.1)
46
+ assert_in_delta(seconds_ago(60), QueueTime.parse_frontend_timestamp(header), 0.001)
43
47
  end
44
48
 
45
49
  def test_parse_frontend_timestamp_from_header_in_milliseconds
46
50
  header = { 'HTTP_X_QUEUE_START' => "t=#{(Time.now.to_f - 60) * 1_000}" }
47
- assert_in_delta(seconds_ago(60), QueueTime.parse_frontend_timestamp(header), 0.1)
51
+ assert_in_delta(seconds_ago(60), QueueTime.parse_frontend_timestamp(header), 0.001)
48
52
  end
49
53
 
50
54
  def test_parse_frontend_timestamp_from_header_with_multiple_servers
51
55
  now = Time.now.to_f
52
56
  header = { 'HTTP_X_QUEUE_START' => "servera t=#{now - 60}, serverb t=#{now - 30}" }
53
- assert_in_delta(seconds_ago(60), QueueTime.parse_frontend_timestamp(header), 0.1)
57
+ assert_in_delta(seconds_ago(60), QueueTime.parse_frontend_timestamp(header), 0.001)
54
58
  end
55
59
 
56
60
  def test_parse_frontend_timestamp_from_header_missing_t_equals
57
61
  header = { 'HTTP_X_REQUEST_START' => (Time.now.to_f - 60).to_s }
58
- assert_in_delta(seconds_ago(60), QueueTime.parse_frontend_timestamp(header), 0.1)
62
+ sleep 2
63
+ assert_in_delta(seconds_ago(60), QueueTime.parse_frontend_timestamp(header), 0.001)
59
64
  end
60
65
 
61
66
  def test_parse_frontend_timestamp_from_header_negative
62
67
  now = Time.now
63
68
  the_future = Time.at(now.to_f + 60)
64
69
  header = { 'HTTP_X_REQUEST_START' => the_future.to_f.to_s }
65
- assert_in_delta(now, QueueTime.parse_frontend_timestamp(header, now), 0.1)
70
+ assert_in_delta(now, QueueTime.parse_frontend_timestamp(header, now), 0.001)
66
71
  end
67
72
 
68
73
  def test_recording_queue_time_metric
69
- assert_metric_value_in_delta(60, 'WebFrontend/QueueTime', 0.1) do
74
+ assert_metric_value_in_delta(60, 'WebFrontend/QueueTime', 0.001) do
70
75
  QueueTime.record_frontend_metrics(Time.at(Time.now.to_f - 60))
71
76
  end
72
77
  end
@@ -36,4 +36,3 @@ class NewRelic::Agent::Instrumentation::RackTest < Test::Unit::TestCase
36
36
  assert_equal [404, {}, ["whee"]], x.call({})
37
37
  end
38
38
  end
39
-
@@ -29,11 +29,11 @@ end
29
29
 
30
30
  class NewRelic::Agent::MemcacheInstrumentationTest < Test::Unit::TestCase
31
31
  include NewRelic::Agent::Instrumentation::ControllerInstrumentation
32
-
32
+
33
33
  def setup
34
34
  NewRelic::Agent.manual_start
35
35
  @engine = NewRelic::Agent.instance.stats_engine
36
-
36
+
37
37
  case MEMCACHED_CLASS.name
38
38
  when 'Memcached'
39
39
  @cache = MEMCACHED_CLASS.new('localhost', :support_cas => true)
@@ -45,7 +45,7 @@ class NewRelic::Agent::MemcacheInstrumentationTest < Test::Unit::TestCase
45
45
  @key = 'schluessel'
46
46
  @cache.set('schluessel', 1)
47
47
  end
48
-
48
+
49
49
  def teardown
50
50
  if MEMCACHED_CLASS.name == 'Memcached'
51
51
  @cache.flush
@@ -56,7 +56,7 @@ class NewRelic::Agent::MemcacheInstrumentationTest < Test::Unit::TestCase
56
56
  @cache.flush_all
57
57
  end
58
58
  end
59
-
59
+
60
60
  def _call_test_method_in_web_transaction(method, *args)
61
61
  @engine.clear_stats
62
62
  perform_action_with_newrelic_trace(:name=>'action', :category => :controller) do
@@ -105,7 +105,7 @@ class NewRelic::Agent::MemcacheInstrumentationTest < Test::Unit::TestCase
105
105
  def test_reads__background
106
106
  commands = ['get']
107
107
  commands << 'get_multi' unless MEMCACHED_CLASS.name == 'Spymemcached'
108
- commands.each do |method|
108
+ commands.each do |method|
109
109
  if @cache.class.method_defined?(method)
110
110
  _call_test_method_in_background_task(method)
111
111
  compare_metrics ["Memcache/#{method}", "Memcache/allOther", "Memcache/#{method}:OtherTransaction/Background/NewRelic::Agent::MemcacheInstrumentationTest/bg_task"],
@@ -142,6 +142,6 @@ class NewRelic::Agent::MemcacheInstrumentationTest < Test::Unit::TestCase
142
142
  end
143
143
  compare_metrics expected_metrics, @engine.metrics.select{|m| m =~ /^memcache.*/i}
144
144
  assert_equal 3, @cache.get(@key)
145
- end
146
- end
145
+ end
146
+ end
147
147
  end if memcached_ready
@@ -2,12 +2,10 @@
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
-
6
5
  require 'test/unit'
7
6
  require 'newrelic_rpm'
8
7
  require 'new_relic/agent/method_tracer'
9
8
 
10
-
11
9
  class MethodInterrobangTest < Test::Unit::TestCase
12
10
  include NewRelic::Agent::MethodTracer
13
11
 
@@ -23,12 +21,12 @@ class MethodInterrobangTest < Test::Unit::TestCase
23
21
  add_method_tracer :mutate!
24
22
 
25
23
  def test_alias_method_ending_in_question_mark
26
- assert_respond_to self,:interrogate?
24
+ assert_respond_to self, :interrogate?
27
25
  assert_equal "say what?", interrogate?
28
26
  end
29
27
 
30
28
  def test_aliase_method_ending_in_exclamation_makr
31
- assert_respond_to self,:mutate!
32
- assert_equal "oh yeah!",mutate!
29
+ assert_respond_to self, :mutate!
30
+ assert_equal "oh yeah!", mutate!
33
31
  end
34
32
  end
@@ -219,7 +219,7 @@ class NewRelic::Agent::MethodTracer::InstanceMethods::TraceExecutionScopedTest <
219
219
  end
220
220
 
221
221
  def test_log_errors_with_error
222
- expects_logging(:error,
222
+ expects_logging(:error,
223
223
  includes("Caught exception in name."),
224
224
  instance_of(RuntimeError))
225
225
 
@@ -313,4 +313,3 @@ class NewRelic::Agent::MethodTracer::InstanceMethods::TraceExecutionScopedTest <
313
313
  mocked_object('control')
314
314
  end
315
315
  end
316
-
@@ -2,11 +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 'multiverse/color'
6
-
7
5
  class MethodVisibilityTest < Test::Unit::TestCase
8
- extend Multiverse::Color
9
-
6
+
10
7
  class InstrumentedClass
11
8
  include NewRelic::Agent::MethodTracer
12
9
  include NewRelic::Agent::Instrumentation::ControllerInstrumentation
@@ -68,35 +65,26 @@ class MethodVisibilityTest < Test::Unit::TestCase
68
65
  def setup
69
66
  @instance = InstrumentedClass.new
70
67
  end
71
-
72
- if NewRelic::VERSION::STRING >= '3.4.0.2'
73
- %w| public private protected |.each do |visibility|
74
- define_method "test_should_preserve_visibility_of_#{visibility}_traced_method" do
75
- assert @instance.send("#{visibility}_methods").map{|s|s.to_sym}.include?(:"#{visibility}_method!"), "Method #{visibility}_method should be #{visibility}"
76
- end
77
-
78
- define_method "test_should_preserve_visibility_of_#{visibility}_traced_transaction" do
79
- assert @instance.send("#{visibility}_methods").map{|s|s.to_sym}.include?(:"#{visibility}_transaction!"), "Transcation #{visibility}_transaction should be #{visibility}"
80
- end
81
- end
82
68
 
83
- def test_tracing_non_public_methods_doesnt_add_public_methods
84
- assert_equal [], ObjectWithTracers.public_instance_methods - ObjectWithInstrumentation.public_instance_methods
69
+ %w| public private protected |.each do |visibility|
70
+ define_method "test_should_preserve_visibility_of_#{visibility}_traced_method" do
71
+ assert @instance.send("#{visibility}_methods").map{|s|s.to_sym}.include?(:"#{visibility}_method!"), "Method #{visibility}_method should be #{visibility}"
85
72
  end
86
73
 
87
- # FIXME: Currently including MethodTracer and ControllerInstrumentation
88
- # adds a bunch of public methods to the class. It probably shouldn't do this.
89
- #def test_instrumentation_doesnt_add_any_public_methods
90
- # assert_equal [], ObjectWithInstrumentation.public_instance_methods - Object.public_instance_methods
91
- #end
92
- #
74
+ define_method "test_should_preserve_visibility_of_#{visibility}_traced_transaction" do
75
+ assert @instance.send("#{visibility}_methods").map{|s|s.to_sym}.include?(:"#{visibility}_transaction!"), "Transcation #{visibility}_transaction should be #{visibility}"
76
+ end
77
+ end
93
78
 
79
+ def test_tracing_non_public_methods_doesnt_add_public_methods
80
+ assert_equal [], ObjectWithTracers.public_instance_methods - ObjectWithInstrumentation.public_instance_methods
81
+ end
94
82
 
83
+ # FIXME: Currently including MethodTracer and ControllerInstrumentation
84
+ # adds a bunch of public methods to the class. It probably shouldn't do this.
85
+ #def test_instrumentation_doesnt_add_any_public_methods
86
+ # assert_equal [], ObjectWithInstrumentation.public_instance_methods - Object.public_instance_methods
87
+ #end
88
+ #
95
89
 
96
- else
97
- def test_truth
98
- assert true # jruby freaks out if there are no tests defined in the test class
99
- end
100
- puts yellow('SKIPPED! 3.4.0.1 and earlier fail preserve_visibility tests')
101
- end
102
90
  end
@@ -110,7 +110,7 @@ class NewRelicServiceTest < Test::Unit::TestCase
110
110
 
111
111
  # This test does not actually use the ruby agent in any way - it's
112
112
  # testing that the CA file we ship actually validates our server's
113
- # certificate. It's used for customers who enable verify_certificate
113
+ # certificate.
114
114
  def test_cert_file
115
115
  if internet_connection?
116
116
  require 'socket'
@@ -16,7 +16,7 @@ class PipeServiceTest < Test::Unit::TestCase
16
16
  end
17
17
 
18
18
  def test_connect_returns_nil
19
- assert_nil @service.connect({})
19
+ assert_nil @service.connect({})
20
20
  end
21
21
 
22
22
  # a #session method is required of services, though in the case of the
@@ -17,7 +17,7 @@ class NewRelic::Agent::RequestSamplerTest < Test::Unit::TestCase
17
17
  def test_samples_on_transaction_finished_event
18
18
  with_sampler_config do
19
19
  advance_time( 0.60 )
20
- @event_listener.notify( :transaction_finished, 'Controller/foo/bar', 0.095 )
20
+ @event_listener.notify( :transaction_finished, 'Controller/foo/bar', Time.now.to_f, 0.095 )
21
21
 
22
22
  assert_equal 1, @sampler.samples.length
23
23
  end
@@ -26,7 +26,7 @@ class NewRelic::Agent::RequestSamplerTest < Test::Unit::TestCase
26
26
  def test_samples_on_transaction_finished_event_include_options
27
27
  with_sampler_config do
28
28
  advance_time( 0.60 )
29
- @event_listener.notify( :transaction_finished, 'Controller/foo/bar', 0.095, :foo => :bar )
29
+ @event_listener.notify( :transaction_finished, 'Controller/foo/bar', Time.now.to_f, 0.095, :foo => :bar )
30
30
 
31
31
  assert_equal :bar, @sampler.samples.first[:foo]
32
32
  end
@@ -37,7 +37,7 @@ class NewRelic::Agent::RequestSamplerTest < Test::Unit::TestCase
37
37
  # 240 requests over 6 seconds => 120 samples
38
38
  # with_debug_logging do
39
39
  241.times do
40
- @event_listener.notify( :transaction_finished, 'Controller/foo/bar', 0.200 )
40
+ @event_listener.notify( :transaction_finished, 'Controller/foo/bar', Time.now.to_f, 0.200 )
41
41
  advance_time( 0.025 )
42
42
  end
43
43
  # end
@@ -57,14 +57,14 @@ class NewRelic::Agent::RequestSamplerTest < Test::Unit::TestCase
57
57
  def test_downsamples_and_reduces_sample_rate_when_throttled
58
58
  with_sampler_config( :'request_sampler.sample_rate_ms' => 50 ) do
59
59
  240.times do
60
- @event_listener.notify( :transaction_finished, 'Controller/foo/bar', 0.200 )
60
+ @event_listener.notify( :transaction_finished, 'Controller/foo/bar', Time.now.to_f, 0.200 )
61
61
  advance_time( 0.025 )
62
62
  end
63
63
 
64
64
  @sampler.throttle( 2 )
65
65
 
66
66
  241.times do
67
- @event_listener.notify( :transaction_finished, 'Controller/foo/bar', 0.200 )
67
+ @event_listener.notify( :transaction_finished, 'Controller/foo/bar', Time.now.to_f, 0.200 )
68
68
  advance_time( 0.025 )
69
69
  end
70
70
 
@@ -83,21 +83,21 @@ class NewRelic::Agent::RequestSamplerTest < Test::Unit::TestCase
83
83
  def test_downsamples_and_reduces_sample_rate_when_throttled_multiple_times
84
84
  with_sampler_config( :'request_sampler.sample_rate_ms' => 50 ) do
85
85
  240.times do
86
- @event_listener.notify( :transaction_finished, 'Controller/foo/bar', 0.200 )
86
+ @event_listener.notify( :transaction_finished, 'Controller/foo/bar', Time.now.to_f, 0.200 )
87
87
  advance_time( 0.025 )
88
88
  end
89
89
 
90
90
  @sampler.throttle( 2 )
91
91
 
92
92
  240.times do
93
- @event_listener.notify( :transaction_finished, 'Controller/foo/bar', 0.200 )
93
+ @event_listener.notify( :transaction_finished, 'Controller/foo/bar', Time.now.to_f, 0.200 )
94
94
  advance_time( 0.025 )
95
95
  end
96
96
 
97
97
  @sampler.throttle( 3 )
98
98
 
99
99
  241.times do
100
- @event_listener.notify( :transaction_finished, 'Controller/foo/bar', 0.200 )
100
+ @event_listener.notify( :transaction_finished, 'Controller/foo/bar', Time.now.to_f, 0.200 )
101
101
  advance_time( 0.025 )
102
102
  end
103
103
 
@@ -115,7 +115,7 @@ class NewRelic::Agent::RequestSamplerTest < Test::Unit::TestCase
115
115
 
116
116
  def test_can_disable_sampling
117
117
  with_sampler_config( :'request_sampler.enabled' => false ) do
118
- @event_listener.notify( :transaction_finished, 'Controller/foo/bar', 0.200 )
118
+ @event_listener.notify( :transaction_finished, 'Controller/foo/bar', Time.now.to_f, 0.200 )
119
119
  assert @sampler.samples.empty?
120
120
  end
121
121
  end
@@ -136,7 +136,7 @@ class NewRelic::Agent::RequestSamplerTest < Test::Unit::TestCase
136
136
  freeze_time
137
137
  with_sampler_config( :'request_sampler.sample_rate_ms' => 60_000 ) do
138
138
  15.times do
139
- @event_listener.notify( :transaction_finished, 'Controller/foo/bar', 0.1)
139
+ @event_listener.notify( :transaction_finished, 'Controller/foo/bar', Time.now.to_f, 0.1)
140
140
  advance_time(60.001)
141
141
  end
142
142
  assert_equal(10, @sampler.samples.size)
@@ -2,10 +2,9 @@
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
- ENV['SKIP_RAILS'] = 'true'
6
5
  require File.expand_path('../../../test_helper', __FILE__)
7
6
 
8
- class NewRelic::Agent::RpmAgentTest < Test::Unit::TestCase # ActiveSupport::TestCase
7
+ class NewRelic::Agent::RpmAgentTest < Test::Unit::TestCase
9
8
  def setup
10
9
  NewRelic::Agent.manual_start
11
10
  @agent = NewRelic::Agent.instance
@@ -7,6 +7,7 @@ require File.expand_path(File.join(File.dirname(__FILE__),'..', '..','test_helpe
7
7
  class NewRelic::Agent::StatsHashTest < Test::Unit::TestCase
8
8
  def setup
9
9
  @hash = NewRelic::Agent::StatsHash.new
10
+ NewRelic::Agent.instance.error_collector.errors.clear
10
11
  end
11
12
 
12
13
  def test_creates_default_entries
@@ -109,10 +110,87 @@ class NewRelic::Agent::StatsHashTest < Test::Unit::TestCase
109
110
  end
110
111
 
111
112
  def test_marshal_dump
112
- hash = NewRelic::Agent::StatsHash.new()
113
- hash.record('foo', 1)
114
- hash.record('bar', 2)
115
- copy = Marshal.load(Marshal.dump(hash))
116
- assert_equal(hash, copy)
113
+ @hash.record('foo', 1)
114
+ @hash.record('bar', 2)
115
+ copy = Marshal.load(Marshal.dump(@hash))
116
+ assert_equal(@hash, copy)
117
117
  end
118
+
119
+ def test_borked_default_proc_can_record_metric
120
+ fake_borked_default_proc(@hash)
121
+
122
+ @hash.record(DEFAULT_SPEC, 1)
123
+
124
+ assert_equal(1, @hash.fetch(DEFAULT_SPEC, nil).call_count)
125
+ end
126
+
127
+ def test_borked_default_proc_notices_agent_error
128
+ fake_borked_default_proc(@hash)
129
+
130
+ @hash.record(DEFAULT_SPEC, 1)
131
+
132
+ assert_has_error NewRelic::Agent::StatsHash::CorruptedDefaultProcError
133
+ end
134
+
135
+ # We can only fix up the default proc on Rubies that let us set it
136
+ if {}.respond_to?(:default_proc=)
137
+ def test_borked_default_proc_heals_thyself
138
+ fake_borked_default_proc(@hash)
139
+
140
+ @hash.record(DEFAULT_SPEC, 1)
141
+ NewRelic::Agent.instance.error_collector.errors.clear
142
+
143
+ @hash.record(NewRelic::MetricSpec.new('something/else/entirely'), 1)
144
+ assert_equal 0, NewRelic::Agent.instance.error_collector.errors.size
145
+ end
146
+ end
147
+
148
+ STAT_SETTERS = [:call_count=, :min_call_time=, :max_call_time=, :total_call_time=, :total_exclusive_time=, :sum_of_squares=]
149
+ DEFAULT_SPEC = NewRelic::MetricSpec.new('foo')
150
+
151
+ STAT_SETTERS.each do |setter|
152
+ define_method("test_merge_allows_nil_destination_for_#{setter.to_s.gsub('=', '')}") do
153
+ dest = NewRelic::Agent::Stats.new
154
+ dest.send(setter, nil)
155
+ expected = dest.dup
156
+
157
+ @hash[DEFAULT_SPEC] = dest
158
+
159
+ incoming = NewRelic::Agent::StatsHash.new
160
+ incoming[DEFAULT_SPEC] = NewRelic::Agent::Stats.new
161
+
162
+ @hash.merge!(incoming)
163
+
164
+ assert_equal expected, @hash[DEFAULT_SPEC]
165
+ assert_has_error NewRelic::Agent::StatsHash::StatsMergerError
166
+ end
167
+ end
168
+
169
+ STAT_SETTERS.each do |setter|
170
+ define_method("test_merge_allows_nil_source_for_#{setter.to_s.gsub('=', '')}") do
171
+ dest = NewRelic::Agent::Stats.new
172
+ expected = dest.dup
173
+
174
+ @hash[DEFAULT_SPEC] = dest
175
+
176
+ source = NewRelic::Agent::Stats.new
177
+ source.send(setter, nil)
178
+ incoming = NewRelic::Agent::StatsHash.new
179
+ incoming[DEFAULT_SPEC] = source
180
+
181
+ @hash.merge!(incoming)
182
+
183
+ assert_equal expected, @hash[DEFAULT_SPEC]
184
+ end
185
+ end
186
+
187
+ def fake_borked_default_proc(hash)
188
+ exception = NoMethodError.new("borked default proc gives a NoMethodError on `yield'")
189
+ if hash.respond_to?(:default_proc=)
190
+ hash.default_proc = Proc.new { raise exception }
191
+ else
192
+ hash.stubs(:[]).raises(exception)
193
+ end
194
+ end
195
+
118
196
  end