newrelic_rpm 3.5.6.48.beta → 3.5.6.55

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.gitignore +1 -0
  3. data/CHANGELOG +52 -0
  4. data/gem-public_cert.pem +20 -0
  5. data/lib/new_relic/agent.rb +3 -0
  6. data/lib/new_relic/agent/agent.rb +21 -14
  7. data/lib/new_relic/agent/agent_logger.rb +9 -1
  8. data/lib/new_relic/agent/configuration/defaults.rb +3 -3
  9. data/lib/new_relic/agent/configuration/mask_defaults.rb +1 -0
  10. data/lib/new_relic/agent/error_collector.rb +11 -2
  11. data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +2 -2
  12. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +1 -1
  13. data/lib/new_relic/agent/instrumentation/sinatra.rb +10 -2
  14. data/lib/new_relic/agent/new_relic_service.rb +90 -10
  15. data/lib/new_relic/agent/pipe_service.rb +9 -0
  16. data/lib/new_relic/agent/sql_sampler.rb +10 -3
  17. data/lib/new_relic/agent/thread_profiler.rb +20 -7
  18. data/lib/new_relic/coerce.rb +37 -0
  19. data/lib/new_relic/commands/deployments.rb +1 -1
  20. data/lib/new_relic/control/frameworks/rails.rb +12 -2
  21. data/lib/new_relic/control/frameworks/rails3.rb +2 -11
  22. data/lib/new_relic/control/instance_methods.rb +10 -6
  23. data/lib/new_relic/control/server_methods.rb +5 -37
  24. data/lib/new_relic/local_environment.rb +1 -1
  25. data/lib/new_relic/metric_data.rb +13 -2
  26. data/lib/new_relic/noticed_error.rb +8 -1
  27. data/lib/new_relic/transaction_sample.rb +12 -3
  28. data/lib/new_relic/transaction_sample/segment.rb +6 -3
  29. data/newrelic.yml +6 -19
  30. data/newrelic_rpm.gemspec +7 -0
  31. data/test/multiverse/lib/multiverse/environment.rb +1 -1
  32. data/test/multiverse/suites/agent_only/logging_test.rb +19 -0
  33. data/test/multiverse/suites/agent_only/ssl_test.rb +22 -0
  34. data/test/multiverse/suites/rails/config/newrelic.yml +3 -136
  35. data/test/multiverse/suites/rails/error_tracing_test.rb +39 -21
  36. data/test/multiverse/suites/rails/gc_instrumentation_test.rb +26 -24
  37. data/test/multiverse/suites/resque/Rakefile +6 -0
  38. data/test/multiverse/suites/resque/instrumentation_test.rb +18 -5
  39. data/test/multiverse/suites/sinatra/sinatra_error_tracing_test.rb +38 -0
  40. data/test/multiverse/suites/sinatra/sinatra_test.rb +17 -0
  41. data/test/new_relic/agent/agent/connect_test.rb +7 -26
  42. data/test/new_relic/agent/agent_test.rb +27 -31
  43. data/test/new_relic/agent/browser_monitoring_test.rb +1 -1
  44. data/test/new_relic/agent/error_collector_test.rb +16 -0
  45. data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +1 -1
  46. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +1 -0
  47. data/test/new_relic/agent/new_relic_service_test.rb +95 -2
  48. data/test/new_relic/agent/pipe_channel_manager_test.rb +3 -3
  49. data/test/new_relic/agent/pipe_service_test.rb +21 -1
  50. data/test/new_relic/agent/rpm_agent_test.rb +1 -1
  51. data/test/new_relic/agent/sql_sampler_test.rb +20 -0
  52. data/test/new_relic/agent/thread_profiler_test.rb +53 -8
  53. data/test/new_relic/agent/worker_loop_test.rb +4 -8
  54. data/test/new_relic/agent_test.rb +1 -2
  55. data/test/new_relic/coerce_test.rb +65 -0
  56. data/test/new_relic/command/deployments_test.rb +1 -1
  57. data/test/new_relic/control_test.rb +19 -44
  58. data/test/new_relic/fake_collector.rb +3 -2
  59. data/test/new_relic/local_environment_test.rb +1 -1
  60. data/test/new_relic/metric_data_test.rb +29 -0
  61. data/test/new_relic/noticed_error_test.rb +8 -0
  62. data/test/new_relic/transaction_sample/segment_test.rb +7 -0
  63. data/test/new_relic/transaction_sample_test.rb +36 -8
  64. data/test/test_contexts.rb +1 -1
  65. data/test/test_helper.rb +21 -2
  66. data/ui/helpers/google_pie_chart.rb +1 -0
  67. metadata +68 -10
  68. metadata.gz.sig +0 -0
  69. data/test/new_relic/fake_service.rb +0 -53
@@ -14,7 +14,27 @@ class PipeServiceTest < Test::Unit::TestCase
14
14
  def test_connect_returns_nil
15
15
  assert_nil @service.connect({})
16
16
  end
17
-
17
+
18
+ # a #session method is required of services, though in the case of the
19
+ # PipeService all it does is invoke the block it's passed.
20
+ def test_session_invokes_block
21
+ block_ran = false
22
+ @service.session do
23
+ block_ran = true
24
+ end
25
+ assert(block_ran)
26
+ end
27
+
28
+ def test_write_to_missing_pipe_logs_error
29
+ service = NewRelic::Agent::PipeService.new(:non_existant)
30
+ ::NewRelic::Agent.logger.expects(:error) \
31
+ .with(regexp_matches(/Unable to send data to parent process/)).once
32
+
33
+ assert_nothing_raised do
34
+ service.metric_data(Time.now, Time.now, {})
35
+ end
36
+ end
37
+
18
38
  if NewRelic::LanguageSupport.can_fork? &&
19
39
  !NewRelic::LanguageSupport.using_version?('1.9.1')
20
40
 
@@ -1,5 +1,6 @@
1
1
  ENV['SKIP_RAILS'] = 'true'
2
2
  require File.expand_path('../../../test_helper', __FILE__)
3
+ require File.expand_path('../../../test_contexts', __FILE__)
3
4
 
4
5
  class NewRelic::Agent::RpmAgentTest < Test::Unit::TestCase # ActiveSupport::TestCase
5
6
  extend TestContexts
@@ -85,7 +86,6 @@ class NewRelic::Agent::RpmAgentTest < Test::Unit::TestCase # ActiveSupport::Test
85
86
  should "send_timeslice_data" do
86
87
  # this test fails due to a rubinius bug
87
88
  return if NewRelic::LanguageSupport.using_engine?('rbx')
88
- @agent.service = NewRelic::FakeService.new
89
89
  @agent.service.expects(:metric_data).returns([ [{'name' => '/A/b/c'}, 1],
90
90
  [{'name' => '/A/b/c', 'scope' => '/X'}, 2],
91
91
  [{'name' => '/A/b/d'}, 3] ])
@@ -214,4 +214,24 @@ class NewRelic::Agent::SqlSamplerTest < Test::Unit::TestCase
214
214
  assert_equal expected, sql_traces[0].to_collector_array(marshaller.default_encoder)
215
215
  end
216
216
  end
217
+
218
+ def test_to_collector_array_with_bad_values
219
+ slow = NewRelic::Agent::SlowSql.new("query", "transaction", {}, Rational(12, 1))
220
+ trace = NewRelic::Agent::SqlTrace.new("query", slow, "path", "uri")
221
+ trace.call_count = Rational(10, 1)
222
+ trace.instance_variable_set(:@sql_id, "1234")
223
+
224
+ if NewRelic::Agent::NewRelicService::JsonMarshaller.is_supported?
225
+ marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
226
+ else
227
+ marshaller = NewRelic::Agent::NewRelicService::PrubyMarshaller.new
228
+ end
229
+
230
+ params = RUBY_VERSION >= '1.9.2' ? "eJyrrgUAAXUA+Q==\n" : {}
231
+ expected = [ "path", "uri", 1234, "query", "transaction",
232
+ 10, 12000, 12000, 12000, params]
233
+
234
+ assert_equal expected, trace.to_collector_array(marshaller.default_encoder)
235
+ end
236
+
217
237
  end
@@ -210,7 +210,11 @@ class ThreadProfileTest < ThreadedTest
210
210
  "irb:12:in `<main>'"
211
211
  ]
212
212
 
213
- @profile = NewRelic::Agent::ThreadProfile.new(-1, 0.029, 0.01, true)
213
+ # Run the worker_loop for the thread profile based on two iterations
214
+ # This takes time fussiness out of the equation and keeps the tests stable
215
+ ignored_duration = 666
216
+ @profile = NewRelic::Agent::ThreadProfile.new(-1, ignored_duration, 0.01, true)
217
+ @profile.instance_variable_set(:@worker_loop, NewRelic::Agent::WorkerLoop.new(:limit => 2))
214
218
  end
215
219
 
216
220
  # Running Tests
@@ -426,12 +430,7 @@ class ThreadProfileTest < ThreadedTest
426
430
  assert_equal [], @profile.traces[:other][0].children
427
431
  end
428
432
 
429
- def test_to_collector_array
430
- @profile.instance_variable_set(:@start_time, 1350403938892.524)
431
- @profile.instance_variable_set(:@stop_time, 1350403939904.375)
432
- @profile.instance_variable_set(:@poll_count, 10)
433
- @profile.instance_variable_set(:@sample_count, 2)
434
-
433
+ def build_well_known_trace
435
434
  trace = ["thread_profiler.py:1:in `<module>'"]
436
435
  10.times { @profile.aggregate(trace, @profile.traces[:other]) }
437
436
 
@@ -443,13 +442,24 @@ class ThreadProfileTest < ThreadedTest
443
442
  "thread_profiler.py:103:in `_run_profiler'",
444
443
  "thread_profiler.py:165:in `collect_thread_stacks'"]
445
444
  10.times { @profile.aggregate(trace, @profile.traces[:agent]) }
445
+ end
446
+
447
+ WELL_KNOWN_TRACE_ENCODED = "eJy9klFPwjAUhf/LfW7WDQTUGBPUiYkGdAxelqXZRpGGrm1uS8xi/O924JQX\n9Un7dm77ndN7c19hlt7FCZxnWQZug7xYMYN6LSTHwDRA4KLWq53kl0CinEQh\nCUmW5zmBJH5axPPUk16MJ/E0/cGk0lLyyrGPS+uKamu943DQeX5HMtypz5In\nwv6vRCeZ1NoAGQ2PCDpvrOM1fRAlFtjQWyxq/qJxa+lj4zZaBeuuQpccrdDK\n0l4wolKU1OxftOoQLNTzIdL/EcjJafjnQYyVWjvrsDBMKNVOZBD1/jO27fPs\naBG+DoGr8fX9JJktpjftVry9A9unzGo=\n"
448
+
449
+ def test_to_collector_array
450
+ @profile.instance_variable_set(:@start_time, 1350403938892.524)
451
+ @profile.instance_variable_set(:@stop_time, 1350403939904.375)
452
+ @profile.instance_variable_set(:@poll_count, 10)
453
+ @profile.instance_variable_set(:@sample_count, 2)
454
+
455
+ build_well_known_trace
446
456
 
447
457
  expected = [[
448
458
  -1,
449
459
  1350403938892.524,
450
460
  1350403939904.375,
451
461
  10,
452
- "eJy9klFPwjAUhf/LfW7WDQTUGBPUiYkGdAxelqXZRpGGrm1uS8xi/O924JQX\n9Un7dm77ndN7c19hlt7FCZxnWQZug7xYMYN6LSTHwDRA4KLWq53kl0CinEQh\nCUmW5zmBJH5axPPUk16MJ/E0/cGk0lLyyrGPS+uKamu943DQeX5HMtypz5In\nwv6vRCeZ1NoAGQ2PCDpvrOM1fRAlFtjQWyxq/qJxa+lj4zZaBeuuQpccrdDK\n0l4wolKU1OxftOoQLNTzIdL/EcjJafjnQYyVWjvrsDBMKNVOZBD1/jO27fPs\naBG+DoGr8fX9JJktpjftVry9A9unzGo=\n",
462
+ WELL_KNOWN_TRACE_ENCODED,
453
463
  2,
454
464
  0
455
465
  ]]
@@ -457,6 +467,29 @@ class ThreadProfileTest < ThreadedTest
457
467
  marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
458
468
  assert_equal expected, @profile.to_collector_array(marshaller.default_encoder)
459
469
  end
470
+
471
+ def test_to_collector_array_with_bad_values
472
+ @profile.instance_variable_set(:@profile_id, "-1")
473
+ @profile.instance_variable_set(:@start_time, "")
474
+ @profile.instance_variable_set(:@stop_time, nil)
475
+ @profile.instance_variable_set(:@poll_count, Rational(10, 1))
476
+ @profile.instance_variable_set(:@sample_count, nil)
477
+
478
+ build_well_known_trace
479
+
480
+ expected = [[
481
+ -1,
482
+ 0.0,
483
+ 0.0,
484
+ 10,
485
+ WELL_KNOWN_TRACE_ENCODED,
486
+ 0,
487
+ 0
488
+ ]]
489
+
490
+ marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
491
+ assert_equal expected, @profile.to_collector_array(marshaller.default_encoder)
492
+ end
460
493
  end
461
494
 
462
495
  class ThreadProfileNodeTest < Test::Unit::TestCase
@@ -492,6 +525,18 @@ class ThreadProfileNodeTest < Test::Unit::TestCase
492
525
  node.to_array)
493
526
  end
494
527
 
528
+ def test_gracefully_handle_bad_values_in_to_array
529
+ node = NewRelic::Agent::ThreadProfile::Node.new(SINGLE_LINE)
530
+ node.instance_variable_set(:@line_no, "blarg")
531
+ node.runnable_count = Rational(10, 1)
532
+
533
+ assert_equal([
534
+ ["irb.rb", "catch", 0],
535
+ 10, 0,
536
+ []],
537
+ node.to_array)
538
+ end
539
+
495
540
  def test_add_child_twice
496
541
  parent = NewRelic::Agent::ThreadProfile::Node.new(SINGLE_LINE)
497
542
  child = NewRelic::Agent::ThreadProfile::Node.new(SINGLE_LINE)
@@ -32,16 +32,12 @@ class NewRelic::Agent::WorkerLoopTest < Test::Unit::TestCase
32
32
  end
33
33
 
34
34
  def test_duration_clock_starts_with_run
35
- # Purposefully testing time, but shouldn't be particularly fragile
35
+ # This test is a little on the nose, but any timing based test WILL fail in CI
36
36
  worker_loop = NewRelic::Agent::WorkerLoop.new(:duration => 0.01)
37
- sleep 0.02
37
+ assert_nil worker_loop.instance_variable_get(:@deadline)
38
38
 
39
- called = false
40
- worker_loop.run(0.001) do
41
- called = true
42
- end
43
-
44
- assert(called, "Didn't run the loop even once")
39
+ worker_loop.run(0.001) {}
40
+ assert !worker_loop.instance_variable_get(:@deadline).nil?
45
41
  end
46
42
 
47
43
  def test_loop_limit
@@ -31,6 +31,7 @@ module NewRelic
31
31
 
32
32
  def test_shutdown_removes_server_config
33
33
  NewRelic::Agent.manual_start
34
+ NewRelic::Agent.instance.service = default_service
34
35
  NewRelic::Agent.instance.finish_setup('agent_config' =>
35
36
  { :some_absurd_setting => true })
36
37
  assert NewRelic::Agent.config[:some_absurd_setting]
@@ -70,7 +71,6 @@ module NewRelic
70
71
  def test_timeslice_harvest_with_after_fork_report_to_channel
71
72
  with_config(:agent_enabled => true, :monitor_mode => true) do
72
73
  NewRelic::Agent.shutdown # make sure the agent is not already started
73
- NewRelic::Agent::Agent.instance.service = NewRelic::FakeService.new
74
74
  NewRelic::Agent.manual_start(:license_key => ('1234567890' * 4),
75
75
  :start_channel_listener => true)
76
76
 
@@ -120,7 +120,6 @@ module NewRelic
120
120
 
121
121
  def test_manual_start_starts_channel_listener
122
122
  NewRelic::Agent::PipeChannelManager.listener.stop
123
- NewRelic::Agent.agent.service = NewRelic::FakeService.new
124
123
  NewRelic::Agent.manual_start(:start_channel_listener => true)
125
124
  assert NewRelic::Agent::PipeChannelManager.listener.started?
126
125
  NewRelic::Agent::PipeChannelManager.listener.stop
@@ -0,0 +1,65 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
2
+ require 'new_relic/coerce'
3
+
4
+ class CoerceTest < Test::Unit::TestCase
5
+
6
+ include NewRelic::Coerce
7
+
8
+ def test_int_coerce
9
+ assert_equal 1, int(1)
10
+ assert_equal 1, int("1")
11
+ assert_equal 1, int(1.0)
12
+ assert_equal 1, int(Rational(1, 1))
13
+ assert_equal 0, int("invalid")
14
+ assert_equal 0, int(nil)
15
+
16
+ # http://ruby-doc.org/core-1.8.7/Symbol.html#method-i-to_i
17
+ assert_equal 0, int(:wat) unless RUBY_VERSION < '1.9'
18
+ end
19
+
20
+ def test_int_coerce_logs
21
+ expects_logging(:warn, Not(includes("context")), any_parameters)
22
+ int("not valid")
23
+ end
24
+
25
+ def test_int_coerce_logs_with_context
26
+ expects_logging(:warn, all_of(includes("HERE"), includes("Integer")), anything)
27
+ int("not valid", "HERE")
28
+ end
29
+
30
+
31
+ def test_float_coerce
32
+ assert_equal 1.0, float(1.0)
33
+ assert_equal 1.0, float("1.0")
34
+ assert_equal 1.0, float(1)
35
+ assert_equal 1.0, float(Rational(1, 1))
36
+ assert_equal 0.0, float("invalid")
37
+ assert_equal 0.0, float(nil)
38
+ assert_equal 0.0, float(:symbols_are_fun)
39
+ end
40
+
41
+ def test_float_coerce_logs_with_context
42
+ expects_logging(:warn, all_of(includes("HERE"), includes("Float")), anything)
43
+ float("not valid", "HERE")
44
+ end
45
+
46
+
47
+ def test_string_coerce
48
+ assert_equal "1", string(1)
49
+ assert_equal "1.0", string(1.0)
50
+ assert_equal "string", string("string")
51
+ assert_equal "1/100", string(Rational(1, 100))
52
+ assert_equal "yeah", string(:yeah)
53
+ assert_equal nil, string(nil)
54
+ assert_equal "", string(Unstringable.new)
55
+ end
56
+
57
+ def test_string_coerce_logs_with_context
58
+ expects_logging(:warn, all_of(includes("HERE"), includes("String")), anything)
59
+ string(Unstringable.new, "HERE")
60
+ end
61
+
62
+ class Unstringable
63
+ undef :to_s
64
+ end
65
+ end
@@ -79,6 +79,6 @@ class NewRelic::Command::DeploymentsTest < Test::Unit::TestCase
79
79
  @mock_response = mock()
80
80
  @mock_response.expects(:is_a?).with(Net::HTTPSuccess).returns(true)
81
81
  mock_connection.expects(:request).returns(@mock_response)
82
- NewRelic::Control.instance.stubs(:http_connection).returns(mock_connection)
82
+ NewRelic::Agent::NewRelicService.any_instance.stubs(:http_connection).returns(mock_connection)
83
83
  end
84
84
  end
@@ -12,42 +12,6 @@ class NewRelic::ControlTest < Test::Unit::TestCase
12
12
  NewRelic::Agent.shutdown
13
13
  end
14
14
 
15
- def test_cert_file_path
16
- assert @control.cert_file_path
17
- assert_equal File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'cert', 'cacert.pem')), @control.cert_file_path
18
- end
19
-
20
- # This test does not actually use the ruby agent in any way - it's
21
- # testing that the CA file we ship actually validates our server's
22
- # certificate. It's used for customers who enable verify_certificate
23
- def test_cert_file
24
- require 'socket'
25
- require 'openssl'
26
-
27
- s = TCPSocket.new 'collector.newrelic.com', 443
28
- ctx = OpenSSL::SSL::SSLContext.new
29
- ctx.ca_file = @control.cert_file_path
30
- ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
31
- s = OpenSSL::SSL::SSLSocket.new s, ctx
32
- s.connect
33
- # should not raise an error
34
- end
35
-
36
- # see above, but for staging, as well. This allows us to test new
37
- # certificates in a non-customer-facing place before setting them
38
- # live.
39
- def test_staging_cert_file
40
- require 'socket'
41
- require 'openssl'
42
-
43
- s = TCPSocket.new 'staging-collector.newrelic.com', 443
44
- ctx = OpenSSL::SSL::SSLContext.new
45
- ctx.ca_file = @control.cert_file_path
46
- ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
47
- s = OpenSSL::SSL::SSLSocket.new s, ctx
48
- s.connect
49
- # should not raise an error
50
- end
51
15
 
52
16
  def test_test_config
53
17
  if defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i == 4
@@ -87,22 +51,30 @@ class NewRelic::ControlTest < Test::Unit::TestCase
87
51
  end
88
52
 
89
53
  def test_resolve_ip_for_localhost
90
- assert_equal nil, control.send(:convert_to_ip_address, 'localhost')
54
+ with_config(:ssl => false, :verify_certificate => false) do
55
+ assert_equal nil, control.send(:convert_to_ip_address, 'localhost')
56
+ end
91
57
  end
92
58
 
93
59
  def test_resolve_ip_for_non_existent_domain
94
- Resolv.stubs(:getaddress).raises(Resolv::ResolvError)
95
- IPSocket.stubs(:getaddress).raises(SocketError)
96
- assert_equal nil, control.send(:convert_to_ip_address, 'q1239988737.us')
60
+ with_config(:ssl => false, :verify_certificate => false) do
61
+ Resolv.stubs(:getaddress).raises(Resolv::ResolvError)
62
+ IPSocket.stubs(:getaddress).raises(SocketError)
63
+ assert_equal nil, control.send(:convert_to_ip_address, 'q1239988737.us')
64
+ end
97
65
  end
98
66
 
99
67
  def test_resolves_valid_ip
100
- Resolv.stubs(:getaddress).with('collector.newrelic.com').returns('204.93.223.153')
101
- assert_equal '204.93.223.153', control.send(:convert_to_ip_address, 'collector.newrelic.com')
68
+ with_config(:ssl => false, :verify_certificate => false) do
69
+ Resolv.stubs(:getaddress).with('collector.newrelic.com').returns('204.93.223.153')
70
+ assert_equal '204.93.223.153', control.send(:convert_to_ip_address, 'collector.newrelic.com')
71
+ end
102
72
  end
103
73
 
104
74
  def test_do_not_resolve_if_we_need_to_verify_a_cert
105
- assert_equal nil, control.send(:convert_to_ip_address, 'localhost')
75
+ with_config(:ssl => false, :verify_certificate => false) do
76
+ assert_equal nil, control.send(:convert_to_ip_address, 'localhost')
77
+ end
106
78
  with_config(:ssl => true, :verify_certificate => true) do
107
79
  assert_equal 'localhost', control.send(:convert_to_ip_address, 'localhost')
108
80
  end
@@ -144,7 +116,10 @@ class NewRelic::ControlTest < Test::Unit::TestCase
144
116
  old_ipsocket = IPSocket
145
117
  Object.instance_eval { remove_const :Resolv}
146
118
  Object.instance_eval {remove_const:'IPSocket' }
147
- assert_equal(nil, control.send(:convert_to_ip_address, 'collector.newrelic.com'), "DNS is down, should be no IP for server")
119
+
120
+ with_config(:ssl => false, :verify_certificate => false) do
121
+ assert_equal(nil, control.send(:convert_to_ip_address, 'collector.newrelic.com'), "DNS is down, should be no IP for server")
122
+ end
148
123
 
149
124
  Object.instance_eval {const_set('Resolv', old_resolv); const_set('IPSocket', old_ipsocket)}
150
125
  # these are here to make sure that the constant tomfoolery above
@@ -92,8 +92,9 @@ module NewRelic
92
92
  begin
93
93
  ::Rack::Handler::WEBrick.run(self,
94
94
  :Port => port,
95
- :Logger => WEBrick::Log.new("/dev/null"),
96
- :AccessLog => [nil, nil])
95
+ :Logger => ::WEBrick::Log.new("/dev/null"),
96
+ :AccessLog => [ ['/dev/null', ::WEBrick::AccessLog::COMMON_LOG_FORMAT] ]
97
+ )
97
98
  rescue Errno::EADDRINUSE => ex
98
99
  msg = "Port #{port} for FakeCollector was in use"
99
100
  if !@seen_port_failure
@@ -53,7 +53,7 @@ class NewRelic::LocalEnvironmentTest < Test::Unit::TestCase
53
53
  assert_equal 0, s.size
54
54
  e.gather_environment_info
55
55
  s = e.snapshot
56
- assert_match /1\.(8\.[67]|9\.\d)/, s.assoc('Ruby version').last, s.inspect
56
+ assert_match /1\.8\.[67]|1\.9\.|2\.0/, s.assoc('Ruby version').last, s.inspect
57
57
  assert_equal 'test', s.assoc('Framework').last, s.inspect
58
58
  # Make sure the processor count is determined on linux systems
59
59
  if File.exists? '/proc/cpuinfo'
@@ -151,4 +151,33 @@ class NewRelic::MetricDataTest < Test::Unit::TestCase
151
151
  expected = [ 1234, [2, 3.0, 2.0, 1.0, 2.0, 5.0] ]
152
152
  assert_equal expected, md.to_collector_array
153
153
  end
154
+
155
+ # Rationals in metric data? -- https://support.newrelic.com/tickets/28053
156
+ def test_to_collector_array_with_rationals
157
+ stats = NewRelic::MethodTraceStats.new
158
+ stats.call_count = Rational(1, 1)
159
+ stats.total_call_time = Rational(2, 1)
160
+ stats.total_exclusive_time = Rational(3, 1)
161
+ stats.min_call_time = Rational(4, 1)
162
+ stats.max_call_time = Rational(5, 1)
163
+ stats.sum_of_squares = Rational(6, 1)
164
+
165
+ md = NewRelic::MetricData.new(nil, stats, 1234)
166
+ expected = [1234, [1, 2.0, 3.0, 4.0, 5.0, 6.0]]
167
+ assert_equal expected, md.to_collector_array
168
+ end
169
+
170
+ def test_to_collector_array_with_bad_values
171
+ stats = NewRelic::MethodTraceStats.new
172
+ stats.call_count = nil
173
+ stats.total_call_time = "junk"
174
+ stats.total_exclusive_time = Object.new
175
+ stats.min_call_time = []
176
+ stats.max_call_time = {}
177
+ stats.sum_of_squares = Exception.new("Boo")
178
+
179
+ md = NewRelic::MetricData.new(nil, stats, 1234)
180
+ expected = [1234, [0, 0, 0, 0, 0, 0]]
181
+ assert_equal expected, md.to_collector_array
182
+ end
154
183
  end
@@ -16,6 +16,14 @@ class NewRelic::Agent::NoticedErrorTest < Test::Unit::TestCase
16
16
  assert_equal expected, error.to_collector_array
17
17
  end
18
18
 
19
+ def test_to_collector_array_with_bad_values
20
+ error = NewRelic::NoticedError.new(@path, @params, nil, Rational(10, 1))
21
+ expected = [
22
+ 10_000.0, @path, "<no message>", "Error", @params
23
+ ]
24
+ assert_equal expected, error.to_collector_array
25
+ end
26
+
19
27
  def test_handles_non_string_exception_messages
20
28
  e = Exception.new({ :non => :string })
21
29
  error = NewRelic::NoticedError.new(@path, @params, e, @time)