wd_newrelic_rpm 3.5.5 → 3.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -373,7 +373,7 @@ var e=document.createElement("script");'
|
|
373
373
|
end
|
374
374
|
|
375
375
|
def test_place_beacon_payload_head_when_given_mobile_request_header
|
376
|
-
Time.stubs(:now).returns(6)
|
376
|
+
Time.stubs(:now).returns(Time.at(6))
|
377
377
|
response = mobile_transaction
|
378
378
|
txn_name = obfuscate(NewRelic::Agent.instance.beacon_configuration,
|
379
379
|
browser_monitoring_transaction_name)
|
@@ -85,4 +85,12 @@ class NewRelic::Agent::BusyCalculatorTest < Test::Unit::TestCase
|
|
85
85
|
assert_equal 0, @instance_busy.call_count
|
86
86
|
end
|
87
87
|
end
|
88
|
+
|
89
|
+
def test_finishing_without_starting_doesnt_raise
|
90
|
+
Thread.current[:busy_entries] = nil
|
91
|
+
assert_nothing_raised do
|
92
|
+
NewRelic::Agent::BusyCalculator.dispatcher_finish
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
88
96
|
end
|
@@ -182,6 +182,34 @@ module NewRelic::Agent::Configuration
|
|
182
182
|
assert_equal 'right', state
|
183
183
|
end
|
184
184
|
|
185
|
+
def test_finished_configuring
|
186
|
+
@manager.apply_config(:layer => "yo")
|
187
|
+
assert_equal false, @manager.finished_configuring?
|
188
|
+
|
189
|
+
@manager.apply_config(ServerSource.new({}))
|
190
|
+
assert_equal true, @manager.finished_configuring?
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_notifies_finished_configuring
|
194
|
+
called = false
|
195
|
+
NewRelic::Agent.instance.events.subscribe(:finished_configuring) { called = true }
|
196
|
+
@manager.apply_config(ServerSource.new({}))
|
197
|
+
|
198
|
+
assert_equal true, called
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_doesnt_notify_unless_finished
|
202
|
+
called = false
|
203
|
+
NewRelic::Agent.instance.events.subscribe(:finished_configuring) { called = true }
|
204
|
+
|
205
|
+
@manager.apply_config(:fake => "config")
|
206
|
+
@manager.apply_config(ManualSource.new(:manual => true))
|
207
|
+
@manager.apply_config(YamlSource.new("", "test"))
|
208
|
+
|
209
|
+
assert_equal false, called
|
210
|
+
end
|
211
|
+
|
212
|
+
|
185
213
|
def test_should_log_when_applying
|
186
214
|
expects_logging(:debug, anything, includes("asdf"))
|
187
215
|
@manager.apply_config(:test => "asdf")
|
@@ -4,10 +4,10 @@ require 'new_relic/agent/configuration/yaml_source'
|
|
4
4
|
module NewRelic::Agent::Configuration
|
5
5
|
class YamlSourceTest < Test::Unit::TestCase
|
6
6
|
def setup
|
7
|
-
test_yml_path = File.expand_path(File.join(File.dirname(__FILE__),
|
7
|
+
@test_yml_path = File.expand_path(File.join(File.dirname(__FILE__),
|
8
8
|
'..','..','..',
|
9
9
|
'config','newrelic.yml'))
|
10
|
-
@source = YamlSource.new(test_yml_path, 'test')
|
10
|
+
@source = YamlSource.new(@test_yml_path, 'test')
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_should_load_given_yaml_file
|
@@ -48,11 +48,21 @@ module NewRelic::Agent::Configuration
|
|
48
48
|
assert_equal 1.1, @source[:apdex_t]
|
49
49
|
end
|
50
50
|
|
51
|
+
def test_should_not_log_error_by_default
|
52
|
+
expects_no_logging(:error)
|
53
|
+
YamlSource.new(@test_yml_path, 'test')
|
54
|
+
end
|
55
|
+
|
51
56
|
def test_should_log_if_no_file_is_found
|
52
57
|
expects_logging(:error, any_parameters)
|
53
58
|
source = YamlSource.new('no_such_file.yml', 'test')
|
54
59
|
end
|
55
60
|
|
61
|
+
def test_should_log_if_environment_is_not_present
|
62
|
+
expects_logging(:error, any_parameters)
|
63
|
+
source = YamlSource.new(@test_yml_path, 'nonsense')
|
64
|
+
end
|
65
|
+
|
56
66
|
def test_should_not_fail_to_log_missing_file_during_startup
|
57
67
|
without_logger do
|
58
68
|
::NewRelic::Agent::StartupLogger.any_instance.expects(:error)
|
@@ -1,69 +1,181 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
2
|
|
3
3
|
module NewRelic::Agent
|
4
|
-
class
|
4
|
+
class CrossProcessMonitorTest < Test::Unit::TestCase
|
5
5
|
AGENT_CROSS_PROCESS_ID = "qwerty"
|
6
|
-
REQUEST_CROSS_PROCESS_ID = "
|
6
|
+
REQUEST_CROSS_PROCESS_ID = "42#1234"
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
NewRelic::Agent.instance.stubs(:cross_process_encoding_bytes).returns([0])
|
8
|
+
ENCODING_KEY_NOOP = "\0"
|
9
|
+
TRUSTED_ACCOUNT_IDS = [42,13]
|
11
10
|
|
12
|
-
|
13
|
-
|
11
|
+
CROSS_PROCESS_ID_POSITION = 0
|
12
|
+
TRANSACTION_NAME_POSITION = 1
|
13
|
+
QUEUE_TIME_POSITION = 2
|
14
|
+
APP_TIME_POSITION = 3
|
15
|
+
CONTENT_LENGTH_POSITION = 4
|
14
16
|
|
17
|
+
def setup
|
15
18
|
@response = {}
|
19
|
+
|
20
|
+
@monitor = NewRelic::Agent::CrossProcessMonitor.new()
|
21
|
+
@monitor.finish_setup(
|
22
|
+
:cross_process_id => AGENT_CROSS_PROCESS_ID,
|
23
|
+
:encoding_key => ENCODING_KEY_NOOP,
|
24
|
+
:trusted_account_ids => TRUSTED_ACCOUNT_IDS)
|
25
|
+
end
|
26
|
+
|
27
|
+
def when_request_runs(request=for_id(REQUEST_CROSS_PROCESS_ID))
|
28
|
+
@monitor.save_client_cross_process_id(request)
|
29
|
+
@monitor.set_transaction_custom_parameters
|
30
|
+
@monitor.insert_response_header(request, @response)
|
31
|
+
end
|
32
|
+
|
33
|
+
def when_request_has_error(request=for_id(REQUEST_CROSS_PROCESS_ID))
|
34
|
+
options = {}
|
35
|
+
@monitor.save_client_cross_process_id(request)
|
36
|
+
@monitor.set_error_custom_parameters(options)
|
37
|
+
@monitor.insert_response_header(request, @response)
|
38
|
+
|
39
|
+
options
|
16
40
|
end
|
17
41
|
|
18
42
|
def test_adds_response_header
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
43
|
+
with_default_timings
|
44
|
+
|
45
|
+
when_request_runs
|
46
|
+
|
47
|
+
assert_equal ["qwerty", "transaction", 1000, 2000, -1], unpacked_response
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_strips_bad_characters_in_transaction_name
|
51
|
+
NewRelic::Agent::BrowserMonitoring.stubs(:timings).returns(stub(
|
52
|
+
:transaction_name => "\"'goo",
|
53
|
+
:queue_time_in_seconds => 1000,
|
54
|
+
:app_time_in_seconds => 2000))
|
55
|
+
|
56
|
+
when_request_runs
|
23
57
|
|
24
|
-
|
58
|
+
assert_equal "goo", unpacked_response[TRANSACTION_NAME_POSITION]
|
59
|
+
end
|
25
60
|
|
26
|
-
|
61
|
+
def test_doesnt_write_response_header_if_id_blank
|
62
|
+
with_default_timings
|
27
63
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
64
|
+
when_request_runs(for_id(''))
|
65
|
+
assert_nil response_app_data
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_doesnt_write_response_header_if_untrusted_id
|
69
|
+
with_default_timings
|
70
|
+
|
71
|
+
when_request_runs(for_id("4#1234"))
|
72
|
+
assert_nil response_app_data
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_doesnt_write_response_header_if_improperly_formatted_id
|
76
|
+
with_default_timings
|
77
|
+
|
78
|
+
when_request_runs(for_id("42"))
|
79
|
+
assert_nil response_app_data
|
32
80
|
end
|
33
81
|
|
34
82
|
def test_doesnt_add_header_if_no_id_in_request
|
35
|
-
|
83
|
+
when_request_runs({})
|
36
84
|
assert_nil response_app_data
|
37
85
|
end
|
38
86
|
|
39
87
|
def test_doesnt_add_header_if_no_id_on_agent
|
40
|
-
|
88
|
+
@monitor.finish_setup(
|
89
|
+
:cross_process_id => nil,
|
90
|
+
:encoding_key => ENCODING_KEY_NOOP,
|
91
|
+
:trusted_account_ids => TRUSTED_ACCOUNT_IDS)
|
41
92
|
|
42
|
-
|
93
|
+
when_request_runs
|
43
94
|
assert_nil response_app_data
|
44
95
|
end
|
45
96
|
|
46
97
|
def test_doesnt_add_header_if_config_disabled
|
47
98
|
with_config(:'cross_process.enabled' => false) do
|
48
|
-
|
99
|
+
when_request_runs
|
49
100
|
assert_nil response_app_data
|
50
101
|
end
|
51
102
|
end
|
52
103
|
|
53
|
-
def
|
54
|
-
|
55
|
-
|
104
|
+
def test_includes_content_length
|
105
|
+
with_default_timings
|
106
|
+
|
107
|
+
when_request_runs(for_id(REQUEST_CROSS_PROCESS_ID).merge("Content-Length" => 3000))
|
108
|
+
assert_equal 3000, unpacked_response[CONTENT_LENGTH_POSITION]
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_finds_content_length_from_headers
|
112
|
+
%w{Content-Length HTTP_CONTENT_LENGTH CONTENT_LENGTH cOnTeNt-LeNgTh}.each do |key|
|
113
|
+
request = { key => 42 }
|
56
114
|
|
57
|
-
assert_equal(
|
58
|
-
REQUEST_CROSS_PROCESS_ID, \
|
59
|
-
CrossProcessMonitoring.id_from_request(request),
|
115
|
+
assert_equal(42, @monitor.content_length_from_request(request), \
|
60
116
|
"Failed to find header on key #{key}")
|
61
117
|
end
|
62
118
|
end
|
63
119
|
|
64
|
-
def
|
65
|
-
|
66
|
-
|
120
|
+
def test_writes_custom_parameters
|
121
|
+
with_default_timings
|
122
|
+
|
123
|
+
NewRelic::Agent.expects(:add_custom_parameters).once
|
124
|
+
|
125
|
+
when_request_runs
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_error_writes_custom_parameters
|
129
|
+
with_default_timings
|
130
|
+
|
131
|
+
options = when_request_has_error
|
132
|
+
|
133
|
+
assert_equal REQUEST_CROSS_PROCESS_ID, options[:client_cross_process_id]
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_error_doesnt_write_custom_parameters_if_no_id
|
137
|
+
with_default_timings
|
138
|
+
|
139
|
+
options = when_request_has_error(for_id(''))
|
140
|
+
|
141
|
+
assert_equal false, options.key?(:client_cross_process_id)
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_writes_metric
|
145
|
+
with_default_timings
|
146
|
+
|
147
|
+
metric = mock()
|
148
|
+
metric.expects(:record_data_point).with(2000)
|
149
|
+
NewRelic::Agent.instance.stats_engine.stubs(:get_stats_no_scope).returns(metric)
|
150
|
+
|
151
|
+
when_request_runs
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_doesnt_write_metric_if_id_blank
|
155
|
+
with_default_timings
|
156
|
+
NewRelic::Agent.instance.stats_engine.expects(:get_stats_no_scope).never
|
157
|
+
|
158
|
+
when_request_runs(for_id(''))
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_decoding_blank
|
162
|
+
assert_equal "", @monitor.decode_with_key("")
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_get_bytes_with_nil
|
166
|
+
assert_equal [], @monitor.send(:get_bytes, nil)
|
167
|
+
end
|
168
|
+
|
169
|
+
def with_default_timings
|
170
|
+
NewRelic::Agent::BrowserMonitoring.stubs(:timings).returns(stub(
|
171
|
+
:transaction_name => "transaction",
|
172
|
+
:queue_time_in_seconds => 1000,
|
173
|
+
:app_time_in_seconds => 2000))
|
174
|
+
end
|
175
|
+
|
176
|
+
def for_id(id)
|
177
|
+
encoded_id = id == "" ? "" : Base64.encode64(id)
|
178
|
+
{ 'X-NewRelic-ID' => encoded_id }
|
67
179
|
end
|
68
180
|
|
69
181
|
def response_app_data
|
@@ -71,7 +183,8 @@ module NewRelic::Agent
|
|
71
183
|
end
|
72
184
|
|
73
185
|
def unpacked_response
|
74
|
-
|
186
|
+
# Assumes array is valid JSON and Ruby, which is currently is
|
187
|
+
eval(Base64.decode64(response_app_data))
|
75
188
|
end
|
76
189
|
end
|
77
190
|
end
|
@@ -186,7 +186,23 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
|
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
189
|
+
def test_increments_count_on_errors
|
190
|
+
expects_error_count_increase(1) do
|
191
|
+
@error_collector.notice_error(StandardError.new("Boo"))
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
189
195
|
private
|
196
|
+
|
197
|
+
def expects_error_count_increase(increase)
|
198
|
+
count = get_error_stats
|
199
|
+
yield
|
200
|
+
assert_equal increase, get_error_stats - count
|
201
|
+
end
|
202
|
+
|
203
|
+
def get_error_stats
|
204
|
+
NewRelic::Agent.get_stats("Errors/all").call_count
|
205
|
+
end
|
190
206
|
|
191
207
|
def wrapped_filter_proc
|
192
208
|
Proc.new do |e|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
+
|
3
|
+
class EventListenerTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@events = NewRelic::Agent::EventListener.new
|
7
|
+
|
8
|
+
@called = false
|
9
|
+
@called_with = nil
|
10
|
+
|
11
|
+
@check_method = Proc.new do |*args|
|
12
|
+
@called = true
|
13
|
+
@called_with = args
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_notifies
|
18
|
+
@events.subscribe(:before_call, &@check_method)
|
19
|
+
@events.notify(:before_call, :env => "env")
|
20
|
+
|
21
|
+
assert_was_called
|
22
|
+
assert_equal([{:env => "env"}], @called_with)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_failure_during_notify_doesnt_block_other_hooks
|
26
|
+
@events.subscribe(:after_call) { raise "Boo!" }
|
27
|
+
@events.subscribe(:after_call, &@check_method)
|
28
|
+
|
29
|
+
@events.notify(:after_call)
|
30
|
+
|
31
|
+
assert_was_called
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_runaway_events
|
35
|
+
@events.runaway_threshold = 0
|
36
|
+
expects_logging(:debug, includes("my_event"))
|
37
|
+
@events.subscribe(:my_event) {}
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def assert_was_called
|
42
|
+
assert @called, "Event wasn't called"
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
@@ -1,39 +1,66 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
def setup
|
6
|
-
Time.stubs(:now).returns(2000)
|
7
|
-
@transaction = stub(
|
8
|
-
:transaction_name => "Name",
|
9
|
-
:start_time => 0
|
10
|
-
)
|
11
|
-
end
|
3
|
+
module NewRelic::Agent::Instrumentation
|
4
|
+
class BrowserMonitoringTimingsTest < Test::Unit::TestCase
|
12
5
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
6
|
+
def setup
|
7
|
+
Time.stubs(:now).returns(Time.at(2000))
|
8
|
+
@transaction = stub(
|
9
|
+
:transaction_name => "Name",
|
10
|
+
:start_time => 0
|
11
|
+
)
|
12
|
+
end
|
17
13
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
def test_queue_time_in_millis
|
15
|
+
t = BrowserMonitoringTimings.new(1000.1234, @transaction)
|
16
|
+
assert_equal 1_000_123, t.queue_time_in_millis
|
17
|
+
end
|
22
18
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
19
|
+
def test_queue_time_in_seconds
|
20
|
+
t = BrowserMonitoringTimings.new(1000.1234, @transaction)
|
21
|
+
assert_equal 1_000.1234, t.queue_time_in_seconds
|
22
|
+
end
|
27
23
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
def test_queue_time_clamps_to_positive
|
25
|
+
t = BrowserMonitoringTimings.new(-1000, @transaction)
|
26
|
+
assert_equal 0, t.queue_time_in_millis
|
27
|
+
end
|
32
28
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
29
|
+
def test_queue_time_clamps_to_positive_in_seconds
|
30
|
+
t = BrowserMonitoringTimings.new(-1000, @transaction)
|
31
|
+
assert_equal 0, t.queue_time_in_seconds
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_app_time_in_millis
|
35
|
+
t = BrowserMonitoringTimings.new(nil, @transaction)
|
36
|
+
assert_equal 2_000_000, t.app_time_in_millis
|
37
|
+
end
|
38
38
|
|
39
|
+
def test_app_time_in_seconds
|
40
|
+
t = BrowserMonitoringTimings.new(nil, @transaction)
|
41
|
+
assert_equal 2_000, t.app_time_in_seconds
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_locks_time_at_instantiation
|
45
|
+
t = BrowserMonitoringTimings.new(1000, @transaction)
|
46
|
+
original = t.app_time_in_seconds
|
47
|
+
|
48
|
+
Time.stubs(:now).returns(3000)
|
49
|
+
later = t.app_time_in_seconds
|
50
|
+
|
51
|
+
assert_equal original, later
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_transaction_name
|
55
|
+
t = BrowserMonitoringTimings.new(nil, @transaction)
|
56
|
+
assert_equal "Name", t.transaction_name
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_defaults_to_transaction_info
|
60
|
+
t = BrowserMonitoringTimings.new(1000, nil)
|
61
|
+
assert_equal nil, t.transaction_name
|
62
|
+
assert_equal 0.0, t.start_time_in_millis
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
39
66
|
end
|