newrelic_rpm 3.7.1.188 → 3.7.2.190.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. data.tar.gz.sig +3 -2
  2. data/CHANGELOG +1 -1
  3. data/Guardfile +3 -3
  4. data/README.md +1 -1
  5. data/Rakefile +0 -2
  6. data/init.rb +2 -5
  7. data/lib/new_relic/agent.rb +3 -0
  8. data/lib/new_relic/agent/agent.rb +2 -0
  9. data/lib/new_relic/agent/configuration/default_source.rb +32 -14
  10. data/lib/new_relic/agent/configuration/environment_source.rb +1 -0
  11. data/lib/new_relic/agent/cross_app_monitor.rb +2 -2
  12. data/lib/new_relic/agent/cross_app_tracing.rb +2 -2
  13. data/lib/new_relic/agent/error_collector.rb +1 -1
  14. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +4 -1
  15. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +10 -8
  16. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +11 -6
  17. data/lib/new_relic/agent/javascript_instrumentor.rb +27 -36
  18. data/lib/new_relic/agent/method_tracer.rb +20 -2
  19. data/lib/new_relic/agent/new_relic_service.rb +35 -27
  20. data/lib/new_relic/agent/request_sampler.rb +20 -13
  21. data/lib/new_relic/agent/sampler_collection.rb +4 -0
  22. data/lib/new_relic/agent/stats_engine/stats_hash.rb +4 -4
  23. data/lib/new_relic/agent/system_info.rb +25 -15
  24. data/lib/new_relic/agent/transaction.rb +23 -4
  25. data/lib/new_relic/agent/transaction_sampler.rb +1 -1
  26. data/lib/new_relic/cli/install.rb +1 -1
  27. data/lib/new_relic/control.rb +1 -0
  28. data/lib/new_relic/helper.rb +1 -29
  29. data/lib/new_relic/json_wrapper.rb +92 -0
  30. data/lib/new_relic/language_support.rb +4 -0
  31. data/lib/new_relic/rack/agent_hooks.rb +4 -0
  32. data/lib/new_relic/rack/browser_monitoring.rb +4 -0
  33. data/lib/new_relic/rack/developer_mode.rb +4 -1
  34. data/lib/new_relic/rack/error_collector.rb +5 -0
  35. data/lib/new_relic/rack/transaction_reset.rb +20 -0
  36. data/lib/new_relic/version.rb +1 -1
  37. data/lib/tasks/install.rake +0 -1
  38. data/newrelic_rpm.gemspec +1 -1
  39. data/test/agent_helper.rb +7 -8
  40. data/test/environments/norails/Gemfile +2 -1
  41. data/test/environments/rails21/Gemfile +2 -2
  42. data/test/environments/rails21/config/environment.rb +1 -3
  43. data/test/environments/rails21/config/environments/development.rb +0 -6
  44. data/test/environments/rails22/Gemfile +2 -2
  45. data/test/environments/rails22/config/environment.rb +0 -2
  46. data/test/environments/rails22/config/environments/development.rb +0 -6
  47. data/test/environments/rails23/Gemfile +2 -3
  48. data/test/environments/rails23/config/environment.rb +0 -9
  49. data/test/environments/rails23/config/environments/development.rb +0 -5
  50. data/test/environments/rails30/Gemfile +2 -2
  51. data/test/environments/rails31/Gemfile +2 -2
  52. data/test/environments/rails32/Gemfile +2 -1
  53. data/test/environments/rails40/Gemfile +2 -1
  54. data/test/intentional_fail.rb +1 -2
  55. data/test/multiverse/lib/multiverse/envfile.rb +1 -5
  56. data/test/multiverse/lib/multiverse/suite.rb +10 -27
  57. data/test/multiverse/suites/active_record/ar_method_aliasing.rb +49 -67
  58. data/test/multiverse/suites/agent_only/encoding_handling_test.rb +128 -0
  59. data/test/multiverse/suites/agent_only/marshaling_test.rb +7 -9
  60. data/test/multiverse/suites/agent_only/script/loading.rb +20 -0
  61. data/test/multiverse/suites/agent_only/start_up_test.rb +7 -0
  62. data/test/multiverse/suites/bare/Envfile +3 -0
  63. data/test/multiverse/suites/bare/standalone_instrumentation_test.rb +43 -0
  64. data/test/multiverse/suites/rails/Envfile +0 -2
  65. data/test/multiverse/suites/rails/app/views/views/_a_partial.html.erb +1 -0
  66. data/test/multiverse/suites/rails/app/views/views/index.html.erb +1 -1
  67. data/test/multiverse/suites/rails/error_tracing_test.rb +1 -1
  68. data/test/multiverse/suites/rails/request_statistics_test.rb +9 -4
  69. data/test/multiverse/suites/rails/view_instrumentation_test.rb +111 -106
  70. data/test/multiverse/suites/typhoeus/Envfile +1 -1
  71. data/test/multiverse/suites/typhoeus/typhoeus_test.rb +16 -2
  72. data/test/multiverse/test/multiverse_test.rb +2 -2
  73. data/test/new_relic/agent/agent/connect_test.rb +1 -1
  74. data/test/new_relic/agent/agent/start_test.rb +1 -1
  75. data/test/new_relic/agent/agent/start_worker_thread_test.rb +1 -1
  76. data/test/new_relic/agent/agent_logger_test.rb +3 -7
  77. data/test/new_relic/agent/agent_test.rb +33 -57
  78. data/test/new_relic/agent/apdex_from_server_test.rb +1 -1
  79. data/test/new_relic/agent/audit_logger_test.rb +5 -8
  80. data/test/new_relic/agent/autostart_test.rb +1 -1
  81. data/test/new_relic/agent/browser_token_test.rb +1 -1
  82. data/test/new_relic/agent/busy_calculator_test.rb +2 -4
  83. data/test/new_relic/agent/commands/agent_command_router_test.rb +5 -5
  84. data/test/new_relic/agent/commands/agent_command_test.rb +1 -1
  85. data/test/new_relic/agent/commands/thread_profiler_session_test.rb +6 -6
  86. data/test/new_relic/agent/commands/xray_session_collection_test.rb +10 -10
  87. data/test/new_relic/agent/commands/xray_session_test.rb +1 -1
  88. data/test/new_relic/agent/configuration/default_source_test.rb +4 -4
  89. data/test/new_relic/agent/configuration/environment_source_test.rb +14 -2
  90. data/test/new_relic/agent/configuration/manager_test.rb +3 -3
  91. data/test/new_relic/agent/configuration/orphan_configuration_test.rb +1 -1
  92. data/test/new_relic/agent/configuration/server_source_test.rb +1 -1
  93. data/test/new_relic/agent/configuration/yaml_source_test.rb +2 -2
  94. data/test/new_relic/agent/cpu_sampler_test.rb +1 -1
  95. data/test/new_relic/agent/cross_app_monitor_test.rb +3 -3
  96. data/test/new_relic/agent/cross_app_tracing_test.rb +5 -4
  97. data/test/new_relic/agent/database_test.rb +1 -1
  98. data/test/new_relic/agent/datastores/mongo/metric_generator_test.rb +1 -1
  99. data/test/new_relic/agent/datastores/mongo/metric_translator_test.rb +1 -1
  100. data/test/new_relic/agent/datastores/mongo/obfuscator_test.rb +1 -1
  101. data/test/new_relic/agent/datastores/mongo/statement_formatter_test.rb +2 -2
  102. data/test/new_relic/agent/error_collector/notice_error_test.rb +1 -1
  103. data/test/new_relic/agent/error_collector_test.rb +5 -3
  104. data/test/new_relic/agent/event_listener_test.rb +1 -1
  105. data/test/new_relic/agent/harvester_test.rb +1 -1
  106. data/test/new_relic/agent/http_clients/uri_util_test.rb +1 -1
  107. data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +1 -1
  108. data/test/new_relic/agent/instrumentation/action_view_subscriber_test.rb +1 -1
  109. data/test/new_relic/agent/instrumentation/active_record_helper_test.rb +1 -1
  110. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +495 -495
  111. data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +2 -2
  112. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +1 -1
  113. data/test/new_relic/agent/instrumentation/instrumentation_test.rb +1 -1
  114. data/test/new_relic/agent/instrumentation/metric_frame_test.rb +1 -1
  115. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +4 -6
  116. data/test/new_relic/agent/instrumentation/queue_time_test.rb +1 -1
  117. data/test/new_relic/agent/instrumentation/rack_test.rb +1 -1
  118. data/test/new_relic/agent/instrumentation/sinatra/transaction_namer_test.rb +1 -1
  119. data/test/new_relic/agent/instrumentation/sinatra_test.rb +1 -1
  120. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +7 -7
  121. data/test/new_relic/agent/javascript_instrumentor_test.rb +47 -55
  122. data/test/new_relic/agent/memcache_instrumentation_test.rb +1 -1
  123. data/test/new_relic/agent/memory_logger_test.rb +1 -1
  124. data/test/new_relic/agent/method_interrobang_test.rb +2 -3
  125. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +4 -4
  126. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +1 -1
  127. data/test/new_relic/agent/method_tracer_test.rb +6 -7
  128. data/test/new_relic/agent/method_visibility_test.rb +1 -1
  129. data/test/new_relic/agent/new_relic_service_test.rb +129 -19
  130. data/test/new_relic/agent/obfuscator_test.rb +1 -1
  131. data/test/new_relic/agent/pipe_channel_manager_test.rb +143 -145
  132. data/test/new_relic/agent/pipe_service_test.rb +2 -4
  133. data/test/new_relic/agent/request_sampler_test.rb +23 -19
  134. data/test/new_relic/agent/rpm_agent_test.rb +3 -3
  135. data/test/new_relic/agent/rules_engine_test.rb +1 -1
  136. data/test/new_relic/agent/sampled_buffer_test.rb +1 -1
  137. data/test/new_relic/agent/sampler_collection_test.rb +3 -3
  138. data/test/new_relic/agent/sampler_test.rb +1 -1
  139. data/test/new_relic/agent/shim_agent_test.rb +1 -1
  140. data/test/new_relic/agent/sql_sampler_test.rb +4 -6
  141. data/test/new_relic/agent/stats_engine/gc_profiler_test.rb +1 -1
  142. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +5 -5
  143. data/test/new_relic/agent/stats_engine/samplers_test.rb +2 -2
  144. data/test/new_relic/agent/stats_engine_test.rb +3 -3
  145. data/test/new_relic/agent/stats_hash_test.rb +2 -2
  146. data/test/new_relic/agent/stats_test.rb +1 -1
  147. data/test/new_relic/agent/threading/agent_thread_test.rb +2 -4
  148. data/test/new_relic/agent/threading/backtrace_node_test.rb +1 -1
  149. data/test/new_relic/agent/threading/backtrace_service_test.rb +5 -5
  150. data/test/new_relic/agent/threading/thread_profile_test.rb +1 -1
  151. data/test/new_relic/agent/transaction/developer_mode_sample_buffer_test.rb +1 -1
  152. data/test/new_relic/agent/transaction/force_persist_sample_buffer_test.rb +1 -1
  153. data/test/new_relic/agent/transaction/pop_test.rb +1 -1
  154. data/test/new_relic/agent/transaction/slowest_sample_buffer_test.rb +1 -1
  155. data/test/new_relic/agent/transaction/xray_sample_buffer_test.rb +1 -1
  156. data/test/new_relic/agent/transaction_interrobang_test.rb +2 -3
  157. data/test/new_relic/agent/transaction_sample_builder_test.rb +16 -14
  158. data/test/new_relic/agent/transaction_sampler_test.rb +16 -21
  159. data/test/new_relic/agent/transaction_state_test.rb +1 -1
  160. data/test/new_relic/agent/transaction_test.rb +61 -1
  161. data/test/new_relic/agent/transaction_timings_test.rb +1 -1
  162. data/test/new_relic/agent/worker_loop_test.rb +1 -1
  163. data/test/new_relic/agent_test.rb +2 -3
  164. data/test/new_relic/cli/deployments_test.rb +3 -3
  165. data/test/new_relic/coerce_test.rb +1 -1
  166. data/test/new_relic/collection_helper_test.rb +1 -1
  167. data/test/new_relic/control/class_methods_test.rb +2 -2
  168. data/test/new_relic/control/frameworks/rails_test.rb +1 -1
  169. data/test/new_relic/control_test.rb +9 -4
  170. data/test/new_relic/dependency_detection_test.rb +1 -1
  171. data/test/new_relic/dispatcher_test.rb +1 -1
  172. data/test/new_relic/environment_report_test.rb +4 -6
  173. data/test/new_relic/fake_collector.rb +1 -158
  174. data/test/new_relic/framework_test.rb +2 -1
  175. data/test/new_relic/http_client_test_cases.rb +2 -3
  176. data/test/new_relic/json_wrapper_test.rb +77 -0
  177. data/test/new_relic/language_support_test.rb +1 -1
  178. data/test/new_relic/license_test.rb +2 -2
  179. data/test/new_relic/load_test.rb +2 -8
  180. data/test/new_relic/local_environment_test.rb +1 -1
  181. data/test/new_relic/metric_data_test.rb +1 -1
  182. data/test/new_relic/metric_parser/metric_parser_test.rb +1 -1
  183. data/test/new_relic/metric_spec_test.rb +1 -1
  184. data/test/new_relic/multiverse_helpers.rb +26 -30
  185. data/test/new_relic/noticed_error_test.rb +1 -1
  186. data/test/new_relic/rack/agent_hooks_test.rb +1 -1
  187. data/test/new_relic/rack/all_test.rb +1 -1
  188. data/test/new_relic/rack/browser_monitoring_test.rb +4 -2
  189. data/test/new_relic/rack/deferred_instrumentation_test.rb +3 -5
  190. data/test/new_relic/rack/developer_mode_helper_test.rb +1 -1
  191. data/test/new_relic/rack/developer_mode_test.rb +1 -1
  192. data/test/new_relic/rack/error_collector_test.rb +8 -8
  193. data/test/new_relic/rack/transaction_reset_test.rb +35 -0
  194. data/test/new_relic/transaction_analysis/segment_summary_test.rb +2 -2
  195. data/test/new_relic/transaction_analysis_test.rb +1 -1
  196. data/test/new_relic/transaction_sample/composite_segment_test.rb +1 -1
  197. data/test/new_relic/transaction_sample/fake_segment_test.rb +2 -4
  198. data/test/new_relic/transaction_sample/segment_test.rb +3 -7
  199. data/test/new_relic/transaction_sample/summary_segment_test.rb +1 -1
  200. data/test/new_relic/transaction_sample_subtest_test.rb +1 -1
  201. data/test/new_relic/transaction_sample_test.rb +4 -6
  202. data/test/new_relic/version_number_test.rb +1 -1
  203. data/test/performance/lib/performance/instrumentation/gc_stats.rb +1 -1
  204. data/test/performance/lib/performance/json_reporter.rb +1 -1
  205. data/test/performance/suites/marshalling.rb +76 -0
  206. data/test/test_helper.rb +6 -39
  207. metadata +19 -12
  208. metadata.gz.sig +0 -0
  209. data/test/new_relic/helper_test.rb +0 -32
@@ -2,7 +2,7 @@
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 MethodVisibilityTest < Test::Unit::TestCase
5
+ class MethodVisibilityTest < MiniTest::Unit::TestCase
6
6
 
7
7
  class InstrumentedClass
8
8
  include NewRelic::Agent::MethodTracer
@@ -8,7 +8,7 @@ require 'new_relic/agent/commands/thread_profiler_session'
8
8
 
9
9
  # Tests of HTTP Keep Alive implementation that require a different setup and
10
10
  # set of mocks.
11
- class NewRelicServiceKeepAliveTest < Test::Unit::TestCase
11
+ class NewRelicServiceKeepAliveTest < MiniTest::Unit::TestCase
12
12
  def setup
13
13
  @server = NewRelic::Control::Server.new('somewhere.example.com',
14
14
  30303, '10.10.10.10')
@@ -80,7 +80,7 @@ class NewRelicServiceKeepAliveTest < Test::Unit::TestCase
80
80
 
81
81
  end
82
82
 
83
- class NewRelicServiceTest < Test::Unit::TestCase
83
+ class NewRelicServiceTest < MiniTest::Unit::TestCase
84
84
  def initialize(*_)
85
85
  [ :HTTPSuccess,
86
86
  :HTTPUnauthorized,
@@ -330,7 +330,7 @@ class NewRelicServiceTest < Test::Unit::TestCase
330
330
  end
331
331
 
332
332
  def test_should_throw_received_errors
333
- assert_raise NewRelic::Agent::ServerConnectionException do
333
+ assert_raises NewRelic::Agent::ServerConnectionException do
334
334
  @service.send(:invoke_remote, :bogus_method)
335
335
  end
336
336
  end
@@ -356,7 +356,7 @@ class NewRelicServiceTest < Test::Unit::TestCase
356
356
  def test_should_raise_exception_on_401
357
357
  @http_handle.reset
358
358
  @http_handle.respond_to(:get_redirect_host, 'bad license', :code => 401)
359
- assert_raise NewRelic::Agent::LicenseException do
359
+ assert_raises NewRelic::Agent::LicenseException do
360
360
  @service.get_redirect_host
361
361
  end
362
362
  end
@@ -364,7 +364,7 @@ class NewRelicServiceTest < Test::Unit::TestCase
364
364
  # protocol 9
365
365
  def test_should_raise_exception_on_413
366
366
  @http_handle.respond_to(:metric_data, 'too big', :code => 413)
367
- assert_raise NewRelic::Agent::UnrecoverableServerException do
367
+ assert_raises NewRelic::Agent::UnrecoverableServerException do
368
368
  stats_hash = NewRelic::Agent::StatsHash.new
369
369
  @service.metric_data(stats_hash)
370
370
  end
@@ -373,13 +373,13 @@ class NewRelicServiceTest < Test::Unit::TestCase
373
373
  # protocol 9
374
374
  def test_should_raise_exception_on_415
375
375
  @http_handle.respond_to(:metric_data, 'too big', :code => 415)
376
- assert_raise NewRelic::Agent::UnrecoverableServerException do
376
+ assert_raises NewRelic::Agent::UnrecoverableServerException do
377
377
  stats_hash = NewRelic::Agent::StatsHash.new
378
378
  @service.metric_data(stats_hash)
379
379
  end
380
380
  end
381
381
 
382
- if NewRelic::LanguageSupport.using_version?('1.9')
382
+ if NewRelic::Agent::NewRelicService::JsonMarshaller.is_supported?
383
383
  def test_json_marshaller_handles_responses_from_collector
384
384
  marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
385
385
  assert_equal ['beep', 'boop'], marshaller.load('{"return_value": ["beep","boop"]}')
@@ -387,28 +387,93 @@ class NewRelicServiceTest < Test::Unit::TestCase
387
387
 
388
388
  def test_json_marshaller_handles_errors_from_collector
389
389
  marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
390
- assert_raise(NewRelic::Agent::NewRelicService::CollectorError,
390
+ assert_raises(NewRelic::Agent::NewRelicService::CollectorError,
391
391
  'JavaCrash: error message') do
392
392
  marshaller.load('{"exception": {"message": "error message", "error_type": "JavaCrash"}}')
393
393
  end
394
394
  end
395
395
 
396
- def test_use_pruby_marshaller_if_error_using_json
397
- json_marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
398
- @service.instance_variable_set(:@marshaller, json_marshaller)
399
- JSON.stubs(:dump).raises(RuntimeError.new('blah'))
400
- @http_handle.respond_to(:transaction_sample_data, 'ok', :format => :pruby)
396
+ def test_raises_serialization_error_if_json_serialization_fails
397
+ ::NewRelic::JSONWrapper.stubs(:dump).raises(RuntimeError.new('blah'))
398
+ assert_raises(NewRelic::Agent::SerializationError) do
399
+ @service.send(:invoke_remote, 'wiggle', {})
400
+ end
401
+ end
402
+
403
+ def test_raises_serialization_error_if_encoding_normalization_fails
404
+ @http_handle.respond_to(:wiggle, 'hi')
405
+ NewRelic::JSONWrapper.stubs(:normalize).raises('blah')
406
+ assert_raises(NewRelic::Agent::SerializationError) do
407
+ @service.send(:invoke_remote, 'wiggle', {})
408
+ end
409
+ end
410
+
411
+ def test_skips_normalization_if_configured_to
412
+ @http_handle.respond_to(:wiggle, 'hello')
413
+ with_config(:normalize_json_string_encodings => false) do
414
+ NewRelic::JSONWrapper.expects(:normalize).never
415
+ @service.send(:invoke_remote, 'wiggle', { 'foo' => 'bar' })
416
+ end
417
+ end
418
+
419
+ def test_json_marshaller_handles_binary_strings
420
+ input_string = (0..255).to_a.pack("C*")
421
+ roundtripped_string = roundtrip_data(input_string)
422
+
423
+ assert_equal(Encoding.find('ASCII-8BIT'), input_string.encoding)
424
+ expected = input_string.dup.force_encoding('ISO-8859-1').encode('UTF-8')
425
+ assert_equal(expected, roundtripped_string)
426
+ end
427
+
428
+ def test_json_marshaller_handles_strings_with_incorrect_encoding
429
+ input_string = (0..255).to_a.pack("C*").force_encoding("UTF-8")
430
+ roundtripped_string = roundtrip_data(input_string)
431
+
432
+ assert_equal(Encoding.find('UTF-8'), input_string.encoding)
433
+ expected = input_string.dup.force_encoding('ISO-8859-1').encode('UTF-8')
434
+ assert_equal(expected, roundtripped_string)
435
+ end
436
+
437
+ def test_json_marshaller_should_handle_crazy_strings
438
+ root = generate_object_graph_with_crazy_strings
439
+ result = roundtrip_data(root)
440
+
441
+ # Note that there's technically a possibility of collision here:
442
+ # if two of the randomly-generated key strings happen to normalize to the
443
+ # same value, we might see <100 results, but the chances of this seem
444
+ # vanishingly small.
445
+ assert_equal(100, result.length)
446
+ end
447
+
448
+ def test_normalization_should_account_for_to_collector_array
449
+ binary_string = generate_random_byte_sequence
450
+ data = DummyDataClass.new(binary_string, [])
451
+ result = roundtrip_data(data)
401
452
 
402
- @service.transaction_sample_data([])
453
+ expected_string = binary_string.force_encoding('ISO-8859-1').encode('UTF-8')
454
+ assert_equal(expected_string, result[0])
455
+ end
456
+
457
+ def test_normalization_should_account_for_to_collector_array_with_nested_encodings
458
+ binary_string = generate_random_byte_sequence
459
+ data = DummyDataClass.new(binary_string, [binary_string])
460
+ result = roundtrip_data(data)
461
+
462
+ expected_string = binary_string.force_encoding('ISO-8859-1').encode('UTF-8')
463
+ assert_equal(expected_string, result[0])
403
464
 
404
- assert_equal('NewRelic::Agent::NewRelicService::PrubyMarshaller',
405
- @service.marshaller.class.name)
465
+ base64_encoded_compressed_json_field = result[1]
466
+ compressed_json_field = Base64.decode64(base64_encoded_compressed_json_field)
467
+ json_field = Zlib::Inflate.inflate(compressed_json_field)
468
+ field = JSON.parse(json_field)
469
+
470
+ assert_equal([expected_string], field)
406
471
  end
407
472
  end
408
473
 
409
474
  def test_pruby_marshaller_handles_errors_from_collector
410
475
  marshaller = NewRelic::Agent::NewRelicService::PrubyMarshaller.new
411
- assert_raise(NewRelic::Agent::NewRelicService::CollectorError, 'error message') do
476
+ assert_raises(NewRelic::Agent::NewRelicService::CollectorError, 'error message') do
412
477
  marshaller.load(Marshal.dump({"exception" => {"message" => "error message",
413
478
  "error_type" => "JavaCrash"}}))
414
479
  end
@@ -533,6 +598,46 @@ class NewRelicServiceTest < Test::Unit::TestCase
533
598
  hash
534
599
  end
535
600
 
601
+ def generate_random_byte_sequence(length=255, encoding=nil)
602
+ bytes = []
603
+ alphabet = (0..255).to_a
604
+ length.times { bytes << alphabet.sample }
605
+ string = bytes.pack("C*")
606
+ string.force_encoding(encoding) if encoding
607
+ string
608
+ end
609
+
610
+ def generate_object_graph_with_crazy_strings
611
+ strings = {}
612
+ encodings = Encoding.list
613
+ 100.times do
614
+ key_string = generate_random_byte_sequence(255, encodings.sample)
615
+ value_string = generate_random_byte_sequence(255, encodings.sample)
616
+ strings[key_string] = value_string
617
+ end
618
+ strings
619
+ end
620
+
621
+ def roundtrip_data(data)
622
+ @http_handle.respond_to(:roundtrip, 'roundtrip')
623
+ @service.send(:invoke_remote, 'roundtrip', data)
624
+ @http_handle.last_request_payload[0]
625
+ end
626
+
627
+ class DummyDataClass
628
+ def initialize(string, object_graph)
629
+ @string = string
630
+ @object_graph = object_graph
631
+ end
632
+
633
+ def to_collector_array(encoder)
634
+ [
635
+ @string,
636
+ encoder.encode(@object_graph)
637
+ ]
638
+ end
639
+ end
640
+
536
641
  class HTTPHandle
537
642
  attr_accessor :read_timeout, :route_table
538
643
 
@@ -600,13 +705,18 @@ class NewRelicServiceTest < Test::Unit::TestCase
600
705
 
601
706
  def last_request_payload
602
707
  return nil unless @last_request && @last_request.body
708
+
709
+ body = @last_request.body
710
+ content_encoding = @last_request['Content-Encoding']
711
+ body = Zlib::Inflate.inflate(body) if content_encoding == 'deflate'
712
+
603
713
  uri = URI.parse(@last_request.path)
604
714
  params = CGI.parse(uri.query)
605
715
  format = params['marshal_format'].first
606
716
  if format == 'json'
607
- JSON.load(@last_request.body)
717
+ JSON.load(body)
608
718
  else
609
- Marshal.load(@last_request.body)
719
+ Marshal.load(body)
610
720
  end
611
721
  end
612
722
  end
@@ -5,7 +5,7 @@
5
5
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
6
6
  require "new_relic/agent/obfuscator"
7
7
 
8
- class NewRelic::Agent::ObfuscatorTest < Test::Unit::TestCase
8
+ class NewRelic::Agent::ObfuscatorTest < MiniTest::Unit::TestCase
9
9
 
10
10
  OBFUSCATION_KEY = (1..40).to_a.pack('c*')
11
11
  RUM_KEY_LENGTH = 13
@@ -6,148 +6,146 @@ require 'timeout'
6
6
  require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
7
7
  require 'new_relic/agent/pipe_channel_manager'
8
8
 
9
- class NewRelic::Agent::PipeChannelManagerTest < Test::Unit::TestCase
10
- include TransactionSampleTestHelper
11
-
12
- def setup
13
- @test_config = { :developer_mode => true }
14
- NewRelic::Agent.agent.drop_buffered_data
15
- NewRelic::Agent.config.apply_config(@test_config)
16
- NewRelic::Agent::PipeChannelManager.listener.close_all_pipes
17
- NewRelic::Agent.manual_start
18
- NewRelic::Agent::TransactionState.clear
19
- end
20
-
21
- def teardown
22
- NewRelic::Agent::PipeChannelManager.listener.stop
23
- NewRelic::Agent.shutdown
24
- NewRelic::Agent.config.remove_config(@test_config)
25
- end
26
-
27
- def test_registering_a_pipe
28
- NewRelic::Agent::PipeChannelManager.listener.wake.in.expects(:<<).with('.')
29
- NewRelic::Agent::PipeChannelManager.register_report_channel(1)
30
- pipe = NewRelic::Agent::PipeChannelManager.channels[1]
31
-
32
- assert pipe.out.kind_of?(IO)
33
- assert pipe.in.kind_of?(IO)
34
-
35
- NewRelic::Agent::PipeChannelManager.listener.close_all_pipes
36
- end
37
-
38
- if NewRelic::LanguageSupport.can_fork? && !NewRelic::LanguageSupport.using_version?('1.9.1')
39
- def test_listener_merges_timeslice_metrics
40
- metric = 'Custom/test/method'
41
- engine = NewRelic::Agent.agent.stats_engine
42
- engine.get_stats_no_scope(metric).record_data_point(1.0)
43
-
44
- listener = start_listener_with_pipe(666)
45
-
46
- pid = Process.fork do
47
- NewRelic::Agent.after_fork
48
- new_engine = NewRelic::Agent::StatsEngine.new
49
- new_engine.get_stats_no_scope(metric).record_data_point(2.0)
50
- listener.pipes[666].write(:stats => new_engine.harvest!)
51
- end
52
- Process.wait(pid)
53
- listener.stop
54
-
55
- assert_equal(3.0, engine.lookup_stats(metric).total_call_time)
56
- engine.reset!
57
- end
58
-
59
- def test_listener_merges_transaction_traces
60
- sampler = NewRelic::Agent.agent.transaction_sampler
61
- sample = run_sample_trace_on(sampler)
62
- assert_equal(1, sampler.count)
63
-
64
- listener = start_listener_with_pipe(667)
65
- pid = Process.fork do
66
- NewRelic::Agent.after_fork
67
- with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
68
- sample = run_sample_trace_on(sampler)
69
- listener.pipes[667].write(:transaction_traces => sampler.harvest!)
70
- end
71
- end
72
- Process.wait(pid)
73
- listener.stop
74
-
75
- assert_equal(2, sampler.count)
76
- end
77
-
78
- def test_listener_merges_error_traces
79
- sampler = NewRelic::Agent.agent.error_collector
80
- sampler.errors.clear
81
- sampler.notice_error(Exception.new("message"), :uri => '/myurl/',
82
- :metric => 'path', :referer => 'test_referer',
83
- :request_params => {:x => 'y'})
84
- NewRelic::Agent.agent.merge_data_from([nil, nil, sampler.errors])
85
-
86
- assert_equal(1, NewRelic::Agent.agent.error_collector.errors.size)
87
-
88
- listener = start_listener_with_pipe(668)
89
-
90
- pid = Process.fork do
91
- NewRelic::Agent.after_fork
92
- new_sampler = NewRelic::Agent::ErrorCollector.new
93
- new_sampler.notice_error(Exception.new("new message"), :uri => '/myurl/',
94
- :metric => 'path', :referer => 'test_referer',
95
- :request_params => {:x => 'y'})
96
- listener.pipes[668].write(:error_traces => new_sampler.harvest!)
97
- end
98
- Process.wait(pid)
99
- listener.stop
100
-
101
- assert_equal(2, NewRelic::Agent.agent.error_collector.errors.size)
102
- end
103
-
104
- def pipe_finished?(id)
105
- (!NewRelic::Agent::PipeChannelManager.channels[id] ||
106
- NewRelic::Agent::PipeChannelManager.channels[id].closed?)
107
- end
108
-
109
- def assert_pipe_finished(id)
110
- assert(pipe_finished?(id),
111
- "Expected pipe with ID #{id} to be nil or closed")
112
- end
113
-
114
- def test_close_pipe_on_child_explicit_close
115
- listener = start_listener_with_pipe(669)
116
- pid = Process.fork do
117
- NewRelic::Agent::PipeService.new(669)
118
- end
119
- Process.wait(pid)
120
- listener.stop_listener_thread
121
- assert_pipe_finished(669)
122
- end
123
-
124
- def test_close_pipe_on_child_exit
125
- listener = start_listener_with_pipe(669)
126
- pid = Process.fork do
127
- NewRelic::Agent::PipeService.new(669)
128
- exit!
129
- end
130
- Process.wait(pid)
131
- listener.stop_listener_thread
132
- assert_pipe_finished(669)
133
- end
134
-
135
- def test_manager_does_not_crash_when_given_bad_data
136
- listener = start_listener_with_pipe(670)
137
- assert_nothing_raised do
138
- pid = Process.fork do
139
- listener.pipes[670].in << 'some unloadable garbage'
140
- end
141
- Process.wait(pid)
142
- listener.stop
143
- end
144
- end
145
- end
146
-
147
- def start_listener_with_pipe(pipe_id)
148
- listener = NewRelic::Agent::PipeChannelManager.listener
149
- listener.start
150
- listener.register_pipe(pipe_id)
151
- listener
152
- end
153
- end
9
+ #class NewRelic::Agent::PipeChannelManagerTest < MiniTest::Unit::TestCase
10
+ # include TransactionSampleTestHelper
11
+ #
12
+ # def setup
13
+ # @test_config = { :developer_mode => true }
14
+ # NewRelic::Agent.agent.drop_buffered_data
15
+ # NewRelic::Agent.config.apply_config(@test_config)
16
+ # NewRelic::Agent::PipeChannelManager.listener.close_all_pipes
17
+ # NewRelic::Agent.manual_start
18
+ # NewRelic::Agent::TransactionState.clear
19
+ # end
20
+ #
21
+ # def teardown
22
+ # NewRelic::Agent::PipeChannelManager.listener.stop
23
+ # NewRelic::Agent.shutdown
24
+ # NewRelic::Agent.config.remove_config(@test_config)
25
+ # end
26
+ #
27
+ # def test_registering_a_pipe
28
+ # NewRelic::Agent::PipeChannelManager.listener.wake.in.expects(:<<).with('.')
29
+ # NewRelic::Agent::PipeChannelManager.register_report_channel(1)
30
+ # pipe = NewRelic::Agent::PipeChannelManager.channels[1]
31
+ #
32
+ # assert pipe.out.kind_of?(IO)
33
+ # assert pipe.in.kind_of?(IO)
34
+ #
35
+ # NewRelic::Agent::PipeChannelManager.listener.close_all_pipes
36
+ # end
37
+ #
38
+ # if NewRelic::LanguageSupport.can_fork? && !NewRelic::LanguageSupport.using_version?('1.9.1')
39
+ # def test_listener_merges_timeslice_metrics
40
+ # metric = 'Custom/test/method'
41
+ # engine = NewRelic::Agent.agent.stats_engine
42
+ # engine.get_stats_no_scope(metric).record_data_point(1.0)
43
+ #
44
+ # listener = start_listener_with_pipe(666)
45
+ #
46
+ # pid = Process.fork do
47
+ # NewRelic::Agent.after_fork
48
+ # new_engine = NewRelic::Agent::StatsEngine.new
49
+ # new_engine.get_stats_no_scope(metric).record_data_point(2.0)
50
+ # listener.pipes[666].write(:stats => new_engine.harvest!)
51
+ # end
52
+ # Process.wait(pid)
53
+ # listener.stop
54
+ #
55
+ # assert_equal(3.0, engine.lookup_stats(metric).total_call_time)
56
+ # engine.reset!
57
+ # end
58
+ #
59
+ # def test_listener_merges_transaction_traces
60
+ # sampler = NewRelic::Agent.agent.transaction_sampler
61
+ # sample = run_sample_trace_on(sampler)
62
+ # assert_equal(1, sampler.count)
63
+ #
64
+ # listener = start_listener_with_pipe(667)
65
+ # pid = Process.fork do
66
+ # NewRelic::Agent.after_fork
67
+ # with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
68
+ # sample = run_sample_trace_on(sampler)
69
+ # listener.pipes[667].write(:transaction_traces => sampler.harvest!)
70
+ # end
71
+ # end
72
+ # Process.wait(pid)
73
+ # listener.stop
74
+ #
75
+ # assert_equal(2, sampler.count)
76
+ # end
77
+ #
78
+ # def test_listener_merges_error_traces
79
+ # sampler = NewRelic::Agent.agent.error_collector
80
+ # sampler.errors.clear
81
+ # sampler.notice_error(Exception.new("message"), :uri => '/myurl/',
82
+ # :metric => 'path', :referer => 'test_referer',
83
+ # :request_params => {:x => 'y'})
84
+ # NewRelic::Agent.agent.merge_data_from([nil, nil, sampler.errors])
85
+ #
86
+ # assert_equal(1, NewRelic::Agent.agent.error_collector.errors.size)
87
+ #
88
+ # listener = start_listener_with_pipe(668)
89
+ #
90
+ # pid = Process.fork do
91
+ # NewRelic::Agent.after_fork
92
+ # new_sampler = NewRelic::Agent::ErrorCollector.new
93
+ # new_sampler.notice_error(Exception.new("new message"), :uri => '/myurl/',
94
+ # :metric => 'path', :referer => 'test_referer',
95
+ # :request_params => {:x => 'y'})
96
+ # listener.pipes[668].write(:error_traces => new_sampler.harvest!)
97
+ # end
98
+ # Process.wait(pid)
99
+ # listener.stop
100
+ #
101
+ # assert_equal(2, NewRelic::Agent.agent.error_collector.errors.size)
102
+ # end
103
+ #
104
+ # def pipe_finished?(id)
105
+ # (!NewRelic::Agent::PipeChannelManager.channels[id] ||
106
+ # NewRelic::Agent::PipeChannelManager.channels[id].closed?)
107
+ # end
108
+ #
109
+ # def assert_pipe_finished(id)
110
+ # assert(pipe_finished?(id),
111
+ # "Expected pipe with ID #{id} to be nil or closed")
112
+ # end
113
+ #
114
+ # def test_close_pipe_on_child_explicit_close
115
+ # listener = start_listener_with_pipe(669)
116
+ # pid = Process.fork do
117
+ # NewRelic::Agent::PipeService.new(669)
118
+ # end
119
+ # Process.wait(pid)
120
+ # listener.stop_listener_thread
121
+ # assert_pipe_finished(669)
122
+ # end
123
+ #
124
+ # def test_close_pipe_on_child_exit
125
+ # listener = start_listener_with_pipe(669)
126
+ # pid = Process.fork do
127
+ # NewRelic::Agent::PipeService.new(669)
128
+ # exit!
129
+ # end
130
+ # Process.wait(pid)
131
+ # listener.stop_listener_thread
132
+ # assert_pipe_finished(669)
133
+ # end
134
+ #
135
+ # def test_manager_does_not_crash_when_given_bad_data
136
+ # listener = start_listener_with_pipe(670)
137
+ # pid = Process.fork do
138
+ # listener.pipes[670].in << 'some unloadable garbage'
139
+ # end
140
+ # Process.wait(pid)
141
+ # listener.stop
142
+ # end
143
+ # end
144
+ #
145
+ # def start_listener_with_pipe(pipe_id)
146
+ # listener = NewRelic::Agent::PipeChannelManager.listener
147
+ # listener.start
148
+ # listener.register_pipe(pipe_id)
149
+ # listener
150
+ # end
151
+ #end