wd_newrelic_rpm 3.5.5 → 3.5.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/CHANGELOG +60 -0
- data/Rakefile +14 -18
- data/gem-public_cert.pem +20 -0
- data/lib/new_relic/agent.rb +3 -0
- data/lib/new_relic/agent/agent.rb +86 -97
- data/lib/new_relic/agent/agent_logger.rb +9 -1
- data/lib/new_relic/agent/busy_calculator.rb +5 -0
- data/lib/new_relic/agent/configuration/defaults.rb +3 -3
- data/lib/new_relic/agent/configuration/manager.rb +12 -0
- data/lib/new_relic/agent/configuration/mask_defaults.rb +1 -0
- data/lib/new_relic/agent/configuration/yaml_source.rb +5 -1
- data/lib/new_relic/agent/cross_process_monitoring.rb +164 -20
- data/lib/new_relic/agent/error_collector.rb +13 -2
- data/lib/new_relic/agent/event_listener.rb +39 -0
- data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +18 -8
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sinatra.rb +8 -1
- data/lib/new_relic/agent/new_relic_service.rb +90 -10
- data/lib/new_relic/agent/pipe_service.rb +9 -0
- data/lib/new_relic/agent/sql_sampler.rb +10 -3
- data/lib/new_relic/agent/stats_engine/transactions.rb +1 -0
- data/lib/new_relic/agent/thread_profiler.rb +20 -7
- data/lib/new_relic/agent/worker_loop.rb +2 -1
- data/lib/new_relic/coerce.rb +37 -0
- data/lib/new_relic/commands/deployments.rb +1 -1
- data/lib/new_relic/control/frameworks/rails.rb +29 -5
- data/lib/new_relic/control/frameworks/rails3.rb +2 -11
- data/lib/new_relic/control/instance_methods.rb +11 -7
- data/lib/new_relic/control/server_methods.rb +5 -37
- data/lib/new_relic/latest_changes.rb +31 -0
- data/lib/new_relic/local_environment.rb +1 -1
- data/lib/new_relic/metric_data.rb +13 -2
- data/lib/new_relic/noticed_error.rb +8 -1
- data/lib/new_relic/rack/agent_hooks.rb +20 -0
- data/lib/new_relic/rack/error_collector.rb +11 -1
- data/lib/new_relic/recipes.rb +32 -10
- data/lib/new_relic/transaction_sample.rb +12 -3
- data/lib/new_relic/transaction_sample/segment.rb +6 -3
- data/lib/new_relic/version.rb +10 -15
- data/newrelic.yml +12 -19
- data/newrelic_rpm.gemspec +22 -464
- data/test/multiverse/.gitignore +1 -0
- data/test/multiverse/lib/multiverse/environment.rb +1 -1
- data/test/multiverse/lib/multiverse/suite.rb +2 -0
- data/test/multiverse/suites/active_record/Envfile +3 -3
- data/test/multiverse/suites/active_record/ar_method_aliasing.rb +1 -1
- data/test/multiverse/suites/active_record/config/newrelic.yml +2 -2
- data/test/multiverse/suites/agent_only/Envfile +2 -1
- data/test/multiverse/suites/agent_only/config/newrelic.yml +3 -1
- data/test/multiverse/suites/agent_only/cross_process_test.rb +56 -0
- data/test/multiverse/suites/{logging → agent_only}/logging_test.rb +42 -22
- data/test/multiverse/suites/agent_only/no_dns_resolv.rb +17 -0
- data/test/multiverse/suites/{rum_auto_instrumentation/sanity_test.rb → agent_only/rum_instrumentation_test.rb} +25 -46
- data/test/multiverse/suites/agent_only/service_timeout_test.rb +6 -3
- data/test/multiverse/suites/agent_only/ssl_test.rb +22 -0
- data/test/multiverse/suites/{no_load → agent_only}/start_up_test.rb +9 -2
- data/test/multiverse/suites/agent_only/testing_app.rb +17 -0
- data/test/multiverse/suites/agent_only/thread_profiling_test.rb +6 -5
- data/test/multiverse/suites/datamapper/config/newrelic.yml +1 -1
- data/test/multiverse/suites/{rails_3_queue_time → rails}/Envfile +3 -0
- data/test/multiverse/suites/rails/app.rb +49 -0
- data/test/multiverse/suites/{rails_3_views → rails}/app/views/foos/_foo.html.haml +0 -0
- data/test/multiverse/suites/{rails_3_views/app/views/test → rails/app/views/views}/_a_partial.html.erb +0 -0
- data/test/multiverse/suites/{rails_3_views/app/views/test → rails/app/views/views}/_mid_partial.html.erb +0 -0
- data/test/multiverse/suites/{rails_3_views/app/views/test → rails/app/views/views}/_top_partial.html.erb +0 -0
- data/test/multiverse/suites/{rails_3_views/app/views/test → rails/app/views/views}/deep_partial.html.erb +0 -0
- data/test/multiverse/suites/{rails_3_views/app/views/test → rails/app/views/views}/haml_view.html.haml +0 -0
- data/test/multiverse/suites/{rails_3_views/app/views/test → rails/app/views/views}/index.html.erb +0 -0
- data/test/multiverse/suites/rails/config/newrelic.yml +32 -0
- data/test/multiverse/suites/{rails_3_error_tracing → rails}/error_tracing_test.rb +51 -88
- data/test/multiverse/suites/rails/gc_instrumentation_test.rb +79 -0
- data/test/multiverse/suites/{rails_3_queue_time → rails}/queue_time_test.rb +3 -23
- data/test/multiverse/suites/{rails_3_views → rails}/view_instrumentation_test.rb +21 -61
- data/test/multiverse/suites/resque/Envfile +7 -4
- data/test/multiverse/suites/resque/Rakefile +8 -0
- data/test/multiverse/suites/resque/config/newrelic.yml +1 -1
- data/test/multiverse/suites/resque/instrumentation_test.rb +118 -41
- data/test/multiverse/suites/resque/resque_setup.rb +15 -0
- data/test/multiverse/suites/sinatra/config/newrelic.yml +1 -2
- data/test/multiverse/suites/sinatra/sinatra_error_tracing_test.rb +38 -0
- data/test/multiverse/suites/sinatra/sinatra_test.rb +17 -0
- data/test/multiverse/test/suite_examples/one/a/config/newrelic.yml +1 -1
- data/test/multiverse/test/suite_examples/one/b/config/newrelic.yml +1 -1
- data/test/new_relic/agent/agent/connect_test.rb +24 -100
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +3 -3
- data/test/new_relic/agent/agent_test.rb +126 -31
- data/test/new_relic/agent/browser_monitoring_test.rb +1 -1
- data/test/new_relic/agent/busy_calculator_test.rb +8 -0
- data/test/new_relic/agent/configuration/manager_test.rb +28 -0
- data/test/new_relic/agent/configuration/yaml_source_test.rb +12 -2
- data/test/new_relic/agent/cross_process_monitoring_test.rb +144 -31
- data/test/new_relic/agent/error_collector_test.rb +16 -0
- data/test/new_relic/agent/event_listener_test.rb +46 -0
- data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +57 -30
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +1 -0
- data/test/new_relic/agent/new_relic_service_test.rb +95 -2
- data/test/new_relic/agent/pipe_channel_manager_test.rb +3 -3
- data/test/new_relic/agent/pipe_service_test.rb +21 -1
- data/test/new_relic/agent/rpm_agent_test.rb +1 -1
- data/test/new_relic/agent/sql_sampler_test.rb +20 -0
- data/test/new_relic/agent/thread_profiler_test.rb +53 -8
- data/test/new_relic/agent/worker_loop_test.rb +19 -16
- data/test/new_relic/agent_test.rb +1 -2
- data/test/new_relic/coerce_test.rb +65 -0
- data/test/new_relic/command/deployments_test.rb +1 -1
- data/test/new_relic/control_test.rb +23 -44
- data/test/new_relic/fake_collector.rb +34 -6
- data/test/new_relic/local_environment_test.rb +1 -1
- data/test/new_relic/metric_data_test.rb +29 -0
- data/test/new_relic/noticed_error_test.rb +8 -0
- data/test/new_relic/rack/agent_hooks_test.rb +30 -0
- data/test/new_relic/rack/error_collector_test.rb +16 -0
- data/test/new_relic/transaction_sample/segment_test.rb +7 -0
- data/test/new_relic/transaction_sample_test.rb +36 -8
- data/test/new_relic/version_number_test.rb +6 -30
- data/test/script/ci.sh +6 -5
- data/test/test_contexts.rb +2 -1
- data/test/test_helper.rb +23 -6
- data/ui/helpers/google_pie_chart.rb +1 -0
- metadata +68 -67
- data/newrelic_rpm.gemspec.erb +0 -54
- data/test/fixtures/gemspec_no_build.rb +0 -442
- data/test/fixtures/gemspec_with_build.rb +0 -442
- data/test/fixtures/gemspec_with_build_and_stage.rb +0 -442
- data/test/multiverse/suites/logging/Envfile +0 -4
- data/test/multiverse/suites/logging/config/newrelic.yml +0 -22
- data/test/multiverse/suites/monitor_mode_false/Envfile +0 -2
- data/test/multiverse/suites/monitor_mode_false/config/newrelic.yml +0 -25
- data/test/multiverse/suites/monitor_mode_false/no_dns_resolv.rb +0 -29
- data/test/multiverse/suites/no_load/Envfile +0 -2
- data/test/multiverse/suites/no_load/config/newrelic.yml +0 -22
- data/test/multiverse/suites/rails_3_error_tracing/Envfile +0 -15
- data/test/multiverse/suites/rails_3_error_tracing/config/newrelic.yml +0 -165
- data/test/multiverse/suites/rails_3_gc/Envfile +0 -8
- data/test/multiverse/suites/rails_3_gc/config/newrelic.yml +0 -167
- data/test/multiverse/suites/rails_3_gc/instrumentation_test.rb +0 -92
- data/test/multiverse/suites/rails_3_queue_time/config/newrelic.yml +0 -165
- data/test/multiverse/suites/rails_3_views/.gitignore +0 -3
- data/test/multiverse/suites/rails_3_views/Envfile +0 -16
- data/test/multiverse/suites/rails_3_views/config/newrelic.yml +0 -164
- data/test/multiverse/suites/resque/dump.rdb +0 -0
- data/test/multiverse/suites/rum_auto_instrumentation/Envfile +0 -4
- data/test/multiverse/suites/rum_auto_instrumentation/config/newrelic.yml +0 -24
- data/test/multiverse/suites/rum_auto_instrumentation/responses/worst_case_small.html +0 -5000
- data/test/new_relic/fake_service.rb +0 -53
@@ -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::
|
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
|
@@ -67,6 +31,10 @@ class NewRelic::ControlTest < Test::Unit::TestCase
|
|
67
31
|
control.local_env
|
68
32
|
end
|
69
33
|
|
34
|
+
def test_settings_accessor
|
35
|
+
assert_not_nil control.settings
|
36
|
+
end
|
37
|
+
|
70
38
|
def test_root
|
71
39
|
assert File.directory?(NewRelic::Control.newrelic_root), NewRelic::Control.newrelic_root
|
72
40
|
if defined?(Rails)
|
@@ -83,22 +51,30 @@ class NewRelic::ControlTest < Test::Unit::TestCase
|
|
83
51
|
end
|
84
52
|
|
85
53
|
def test_resolve_ip_for_localhost
|
86
|
-
|
54
|
+
with_config(:ssl => false, :verify_certificate => false) do
|
55
|
+
assert_equal nil, control.send(:convert_to_ip_address, 'localhost')
|
56
|
+
end
|
87
57
|
end
|
88
58
|
|
89
59
|
def test_resolve_ip_for_non_existent_domain
|
90
|
-
|
91
|
-
|
92
|
-
|
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
|
93
65
|
end
|
94
66
|
|
95
67
|
def test_resolves_valid_ip
|
96
|
-
|
97
|
-
|
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
|
98
72
|
end
|
99
73
|
|
100
74
|
def test_do_not_resolve_if_we_need_to_verify_a_cert
|
101
|
-
|
75
|
+
with_config(:ssl => false, :verify_certificate => false) do
|
76
|
+
assert_equal nil, control.send(:convert_to_ip_address, 'localhost')
|
77
|
+
end
|
102
78
|
with_config(:ssl => true, :verify_certificate => true) do
|
103
79
|
assert_equal 'localhost', control.send(:convert_to_ip_address, 'localhost')
|
104
80
|
end
|
@@ -140,7 +116,10 @@ class NewRelic::ControlTest < Test::Unit::TestCase
|
|
140
116
|
old_ipsocket = IPSocket
|
141
117
|
Object.instance_eval { remove_const :Resolv}
|
142
118
|
Object.instance_eval {remove_const:'IPSocket' }
|
143
|
-
|
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
|
144
123
|
|
145
124
|
Object.instance_eval {const_set('Resolv', old_resolv); const_set('IPSocket', old_ipsocket)}
|
146
125
|
# these are here to make sure that the constant tomfoolery above
|
@@ -71,20 +71,48 @@ module NewRelic
|
|
71
71
|
uri.query && uri.query.include?('marshal_format=json')
|
72
72
|
end
|
73
73
|
|
74
|
-
|
74
|
+
# We generate a "unique" port for ourselves based off our pid
|
75
|
+
# If this logic changes, look for multiverse newrelic.yml files to update
|
76
|
+
# with it duplicated (since we can't easily pull this ruby into a yml)
|
77
|
+
def self.determine_port
|
78
|
+
30_000 + ($$ % 10_000)
|
79
|
+
end
|
80
|
+
|
81
|
+
def determine_port
|
82
|
+
FakeCollector.determine_port
|
83
|
+
end
|
84
|
+
|
85
|
+
@seen_port_failure = false
|
86
|
+
|
87
|
+
def run(port=nil)
|
88
|
+
port ||= determine_port
|
75
89
|
return if @thread && @thread.alive?
|
76
90
|
serve_on_port(port) do
|
77
91
|
@thread = Thread.new do
|
92
|
+
begin
|
78
93
|
::Rack::Handler::WEBrick.run(self,
|
79
94
|
:Port => port,
|
80
|
-
:Logger => WEBrick::Log.new("/dev/null"),
|
81
|
-
:AccessLog => [
|
95
|
+
:Logger => ::WEBrick::Log.new("/dev/null"),
|
96
|
+
:AccessLog => [ ['/dev/null', ::WEBrick::AccessLog::COMMON_LOG_FORMAT] ]
|
97
|
+
)
|
98
|
+
rescue Errno::EADDRINUSE => ex
|
99
|
+
msg = "Port #{port} for FakeCollector was in use"
|
100
|
+
if !@seen_port_failure
|
101
|
+
# This is slow, so only do it the first collision we detect
|
102
|
+
lsof = `lsof | grep #{port}`
|
103
|
+
msg = msg + "\n#{lsof}"
|
104
|
+
@seen_port_failure = true
|
105
|
+
end
|
106
|
+
|
107
|
+
raise Errno::EADDRINUSE.new(msg)
|
108
|
+
end
|
82
109
|
end
|
83
110
|
@thread.abort_on_exception = true
|
84
111
|
end
|
85
112
|
end
|
86
113
|
|
87
114
|
def serve_on_port(port)
|
115
|
+
port ||= determine_port
|
88
116
|
if is_port_available?('127.0.0.1', port)
|
89
117
|
yield
|
90
118
|
loop do
|
@@ -127,7 +155,7 @@ module NewRelic
|
|
127
155
|
|
128
156
|
# might we need this? I'll just leave it here for now
|
129
157
|
class FakeCollectorProcess < FakeCollector
|
130
|
-
def run(port
|
158
|
+
def run(port)
|
131
159
|
serve_on_port(port) do
|
132
160
|
@pid = Process.fork do
|
133
161
|
::Rack::Handler::WEBrick.run(self, :Port => port)
|
@@ -262,9 +290,9 @@ if $0 == __FILE__
|
|
262
290
|
end
|
263
291
|
|
264
292
|
def invoke(method, post={}, code=200)
|
265
|
-
uri = URI.parse("http://127.0.0.1
|
293
|
+
uri = URI.parse("http://127.0.0.1:#{determine_port}/agent_listener/8/12345/#{method}")
|
266
294
|
request = Net::HTTP::Post.new("#{uri.path}?#{uri.query}")
|
267
|
-
if uri.query && uri.query.include?('
|
295
|
+
if uri.query && uri.query.include?('marshal_format=json')
|
268
296
|
request.body = JSON.dump(post)
|
269
297
|
else
|
270
298
|
request.body = Marshal.dump(post)
|
@@ -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\.
|
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)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
+
require 'new_relic/rack/agent_hooks'
|
3
|
+
|
4
|
+
class AgentHooksTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@app = stub_everything
|
8
|
+
@hooks = NewRelic::Rack::AgentHooks.new(@app)
|
9
|
+
@env = {:env => "env"}
|
10
|
+
|
11
|
+
NewRelic::Agent.instance.events.stubs(:notify)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_before_call
|
15
|
+
NewRelic::Agent.instance.events.expects(:notify).with(:before_call, @env)
|
16
|
+
|
17
|
+
@hooks.call(@env)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_after_call
|
21
|
+
result = stub
|
22
|
+
@app.stubs(:call).returns(result)
|
23
|
+
|
24
|
+
NewRelic::Agent.instance.events.expects(:notify).with(:after_call, @env, result)
|
25
|
+
|
26
|
+
@hooks.call(@env)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
@@ -66,6 +66,22 @@ module NewRelic::Rack
|
|
66
66
|
assert(NewRelic::Agent.instance.error_collector.errors.empty?,
|
67
67
|
'noticed an error that should have been ignored')
|
68
68
|
end
|
69
|
+
|
70
|
+
def test_handles_parameter_parsing_exceptions
|
71
|
+
bad_request = stub(:env => {}, :path => '/', :referer => '')
|
72
|
+
bad_request.stubs(:params).raises(TypeError, "can't convert nil into Hash")
|
73
|
+
Rack::Request.stubs(:new).returns(bad_request)
|
74
|
+
|
75
|
+
assert_raise RuntimeError do
|
76
|
+
get '/'
|
77
|
+
end
|
78
|
+
|
79
|
+
assert_equal('unhandled error',
|
80
|
+
NewRelic::Agent.instance.error_collector.errors[0].message)
|
81
|
+
assert_match(/failed to capture request parameters/i,
|
82
|
+
NewRelic::Agent.instance.error_collector.errors[0].params[:request_params]['error'])
|
83
|
+
end
|
84
|
+
|
69
85
|
end
|
70
86
|
end
|
71
87
|
|
@@ -51,6 +51,13 @@ class NewRelic::TransactionSample::SegmentTest < Test::Unit::TestCase
|
|
51
51
|
assert_equal(expected_array, parent.to_array)
|
52
52
|
end
|
53
53
|
|
54
|
+
def test_to_array_with_bad_values
|
55
|
+
segment = NewRelic::TransactionSample::Segment.new(nil, nil, nil)
|
56
|
+
segment.end_trace(Rational(10, 1))
|
57
|
+
expected = [0, 10_000.0, "<unknown>", {}, []]
|
58
|
+
assert_equal(expected, segment.to_array)
|
59
|
+
end
|
60
|
+
|
54
61
|
if RUBY_VERSION >= '1.9.2'
|
55
62
|
def test_to_json
|
56
63
|
parent = NewRelic::TransactionSample::Segment.new(1, 'Custom/test/parent', 1)
|
@@ -12,6 +12,12 @@ class NewRelic::TransactionSampleTest < Test::Unit::TestCase
|
|
12
12
|
|
13
13
|
NewRelic::Agent::Database.stubs(:get_connection).returns @connection_stub
|
14
14
|
@t = make_sql_transaction(::SQL_STATEMENT, ::SQL_STATEMENT)
|
15
|
+
|
16
|
+
if NewRelic::Agent::NewRelicService::JsonMarshaller.is_supported?
|
17
|
+
@marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
|
18
|
+
else
|
19
|
+
@marshaller = NewRelic::Agent::NewRelicService::PrubyMarshaller.new
|
20
|
+
end
|
15
21
|
end
|
16
22
|
|
17
23
|
def teardown
|
@@ -189,6 +195,13 @@ class NewRelic::TransactionSampleTest < Test::Unit::TestCase
|
|
189
195
|
assert_equal expected_array, @t.to_array
|
190
196
|
end
|
191
197
|
|
198
|
+
|
199
|
+
def test_to_array_with_bad_values
|
200
|
+
transaction = NewRelic::TransactionSample.new(nil)
|
201
|
+
expected = [0.0, {}, nil, [0, 0, "ROOT", {}, []]]
|
202
|
+
assert_equal expected, transaction.to_array
|
203
|
+
end
|
204
|
+
|
192
205
|
if RUBY_VERSION >= '1.9.2'
|
193
206
|
def test_to_json
|
194
207
|
expected_string = JSON.dump([@t.start_time.to_f,
|
@@ -200,20 +213,35 @@ class NewRelic::TransactionSampleTest < Test::Unit::TestCase
|
|
200
213
|
end
|
201
214
|
|
202
215
|
def test_to_collector_array
|
203
|
-
if NewRelic::Agent::NewRelicService::JsonMarshaller.is_supported?
|
204
|
-
marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
|
205
|
-
trace_tree = compress(@t.to_json)
|
206
|
-
else
|
207
|
-
marshaller = NewRelic::Agent::NewRelicService::PrubyMarshaller.new
|
208
|
-
trace_tree = @t.to_array
|
209
|
-
end
|
210
216
|
expected_array = [(@t.start_time.to_f * 1000).round,
|
211
217
|
(@t.duration * 1000).round,
|
212
218
|
@t.params[:path], @t.params[:uri],
|
213
219
|
trace_tree,
|
214
220
|
@t.guid, nil, !!@t.force_persist]
|
215
221
|
|
216
|
-
assert_equal expected_array, @t.to_collector_array(marshaller.default_encoder)
|
222
|
+
assert_equal expected_array, @t.to_collector_array(@marshaller.default_encoder)
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_to_collector_array_with_bad_values
|
226
|
+
transaction = NewRelic::TransactionSample.new(nil)
|
227
|
+
transaction.root_segment.end_trace(Rational(10, 1))
|
228
|
+
|
229
|
+
expected = [
|
230
|
+
0, 10_000,
|
231
|
+
nil, nil,
|
232
|
+
trace_tree(transaction),
|
233
|
+
transaction.guid,
|
234
|
+
nil, false]
|
235
|
+
|
236
|
+
assert_equal expected, transaction.to_collector_array(@marshaller.default_encoder)
|
237
|
+
end
|
238
|
+
|
239
|
+
def trace_tree(transaction=@t)
|
240
|
+
if NewRelic::Agent::NewRelicService::JsonMarshaller.is_supported?
|
241
|
+
trace_tree = compress(transaction.to_json)
|
242
|
+
else
|
243
|
+
trace_tree = transaction.to_array
|
244
|
+
end
|
217
245
|
end
|
218
246
|
|
219
247
|
def compress(string)
|
@@ -82,40 +82,16 @@ class NewRelic::VersionNumberTest < Test::Unit::TestCase
|
|
82
82
|
assert v0 < '1.2.0.1'
|
83
83
|
assert v0 > '1.1.0.1'
|
84
84
|
end
|
85
|
+
|
85
86
|
def test_string
|
86
87
|
assert_equal '1.2.0', NewRelic::VersionNumber.new('1.2.0').to_s
|
87
88
|
assert_equal '1.2', NewRelic::VersionNumber.new('1.2').to_s
|
88
89
|
end
|
89
90
|
|
90
|
-
def
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
assert_equal
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_gemspec_parse_no_build
|
98
|
-
version = NewRelic::VERSION.parse_build_from_gemspec(NewRelic.fixture_path('gemspec_no_build.rb'))
|
99
|
-
assert_nil version
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_gemspec_parse_with_build
|
103
|
-
version = NewRelic::VERSION.parse_build_from_gemspec(NewRelic.fixture_path('gemspec_with_build.rb'))
|
104
|
-
assert_equal '123', version
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_gemspec_parse_with_build_and_stage
|
108
|
-
version = NewRelic::VERSION.parse_build_from_gemspec(NewRelic.fixture_path('gemspec_with_build_and_stage.rb'))
|
109
|
-
assert_equal '123.dev', version
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_gemspec_parse_no_rubygems
|
113
|
-
Kernel.stubs(:const_defined?).with(:Gem).returns(false)
|
114
|
-
version = NewRelic::VERSION.parse_build_from_gemspec(NewRelic.fixture_path('gemspec_with_build_and_stage.rb'))
|
115
|
-
assert_equal '123.dev', version
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_gemspec_parse_nonexistent
|
119
|
-
assert_nil NewRelic::VERSION.parse_build_from_gemspec('/really/not/a/real/path')
|
91
|
+
def test_build_version_string
|
92
|
+
version_string = NewRelic::VERSION.build_version_string(1, 2, 3, '4.beta')
|
93
|
+
assert_equal('1.2.3.4.beta', version_string)
|
94
|
+
version_string = NewRelic::VERSION.build_version_string(1, 2, 3, nil)
|
95
|
+
assert_equal('1.2.3', version_string)
|
120
96
|
end
|
121
97
|
end
|
data/test/script/ci.sh
CHANGED
@@ -64,13 +64,10 @@ fi
|
|
64
64
|
|
65
65
|
echo `which ruby`
|
66
66
|
ruby -v
|
67
|
+
gem --version
|
67
68
|
|
68
69
|
rake -h > /dev/null || gem install rake
|
69
70
|
|
70
|
-
echo "generating gemspec"
|
71
|
-
rake gemspec
|
72
|
-
|
73
|
-
|
74
71
|
# make sure that we're in the project root
|
75
72
|
script_dirname=`dirname $0`
|
76
73
|
cd "$script_dirname/../../"
|
@@ -87,13 +84,17 @@ rpm_test_app_cache=~/workspace/.rpm_test_app_cache
|
|
87
84
|
echo "updating local cache of rpm_test_app in $rpm_test_app_cache"
|
88
85
|
git clone --mirror git://github.com/newrelic/rpm_test_app.git $rpm_test_app_cache || true
|
89
86
|
cd $rpm_test_app_cache
|
87
|
+
git fetch || true
|
90
88
|
)
|
91
89
|
|
92
90
|
git clone $rpm_test_app_cache rpm_test_app
|
93
91
|
cd rpm_test_app
|
94
92
|
|
93
|
+
git fetch || true
|
95
94
|
git checkout -t origin/$BRANCH || git checkout $BRANCH
|
96
|
-
|
95
|
+
if [ -x $HOME/.rbenv/plugins/rbenv-gemsets ]; then
|
96
|
+
echo "$RUBY-$BRANCH" > .rbenv-gemsets
|
97
|
+
fi
|
97
98
|
|
98
99
|
# Re-write database.yml to this here doc
|
99
100
|
( cat << "YAML" ) > config/database.yml
|