newrelic_rpm 3.0.1 → 3.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of newrelic_rpm might be problematic. Click here for more details.
- data/CHANGELOG +2 -3
- data/README.rdoc +3 -3
- data/lib/new_relic/agent.rb +19 -7
- data/lib/new_relic/agent/agent.rb +83 -19
- data/lib/new_relic/agent/beacon_configuration.rb +8 -12
- data/lib/new_relic/agent/browser_monitoring.rb +8 -8
- data/lib/new_relic/agent/error_collector.rb +13 -13
- data/lib/new_relic/agent/instrumentation.rb +9 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +10 -2
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +41 -35
- data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +92 -0
- data/lib/new_relic/agent/method_tracer.rb +0 -2
- data/lib/new_relic/agent/shim_agent.rb +2 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +89 -60
- data/lib/new_relic/agent/stats_engine/transactions.rb +1 -1
- data/lib/new_relic/agent/worker_loop.rb +1 -1
- data/lib/new_relic/collection_helper.rb +0 -2
- data/lib/new_relic/control/class_methods.rb +25 -12
- data/lib/new_relic/control/logging_methods.rb +30 -17
- data/lib/new_relic/data_serialization.rb +81 -0
- data/lib/new_relic/local_environment.rb +1 -1
- data/lib/new_relic/metric_data.rb +9 -5
- data/lib/new_relic/metric_spec.rb +7 -1
- data/lib/new_relic/rack/browser_monitoring.rb +1 -7
- data/lib/new_relic/stats.rb +4 -0
- data/lib/new_relic/transaction_analysis.rb +45 -88
- data/lib/new_relic/transaction_analysis/segment_summary.rb +47 -0
- data/lib/new_relic/transaction_sample.rb +15 -332
- data/lib/new_relic/transaction_sample/composite_segment.rb +27 -0
- data/lib/new_relic/transaction_sample/fake_segment.rb +9 -0
- data/lib/new_relic/transaction_sample/segment.rb +250 -0
- data/lib/new_relic/transaction_sample/summary_segment.rb +21 -0
- data/lib/new_relic/version.rb +3 -3
- data/newrelic.yml +3 -3
- data/newrelic_rpm.gemspec +27 -4
- data/test/active_record_fixtures.rb +31 -13
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +1 -3
- data/test/new_relic/agent/agent_test.rb +73 -28
- data/test/new_relic/agent/agent_test_controller_test.rb +11 -10
- data/test/new_relic/agent/beacon_configuration_test.rb +37 -20
- data/test/new_relic/agent/browser_monitoring_test.rb +17 -28
- data/test/new_relic/agent/error_collector/notice_error_test.rb +9 -7
- data/test/new_relic/agent/error_collector_test.rb +6 -7
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +12 -5
- data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +195 -0
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +60 -58
- data/test/new_relic/agent/instrumentation/queue_time_test.rb +14 -0
- data/test/new_relic/agent/instrumentation/rack_test.rb +35 -0
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +0 -1
- data/test/new_relic/agent/method_tracer_test.rb +8 -8
- data/test/new_relic/agent/sampler_test.rb +19 -0
- data/test/new_relic/agent/shim_agent_test.rb +20 -0
- data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +150 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +1 -0
- data/test/new_relic/agent/stats_engine/samplers_test.rb +4 -3
- data/test/new_relic/agent/{stats_engine/stats_engine_test.rb → stats_engine_test.rb} +8 -8
- data/test/new_relic/agent/transaction_sampler_test.rb +1 -1
- data/test/new_relic/agent/worker_loop_test.rb +2 -2
- data/test/new_relic/control/class_methods_test.rb +62 -0
- data/test/new_relic/control/logging_methods_test.rb +157 -0
- data/test/new_relic/control_test.rb +10 -10
- data/test/new_relic/data_serialization_test.rb +50 -0
- data/test/new_relic/local_environment_test.rb +13 -13
- data/test/new_relic/metric_data_test.rb +125 -0
- data/test/new_relic/metric_spec_test.rb +8 -0
- data/test/new_relic/transaction_analysis/segment_summary_test.rb +77 -0
- data/test/new_relic/transaction_analysis_test.rb +121 -0
- data/test/new_relic/transaction_sample/composite_segment_test.rb +35 -0
- data/test/new_relic/transaction_sample/fake_segment_test.rb +17 -0
- data/test/new_relic/transaction_sample/segment_test.rb +454 -0
- data/test/new_relic/transaction_sample/summary_segment_test.rb +31 -0
- data/test/new_relic/transaction_sample_test.rb +51 -0
- data/test/test_helper.rb +4 -14
- metadata +32 -7
@@ -60,15 +60,13 @@ class NewRelic::Agent::Agent::StartWorkerThreadTest < Test::Unit::TestCase
|
|
60
60
|
def test_create_and_run_worker_loop
|
61
61
|
@report_period = 30
|
62
62
|
@should_send_samples = true
|
63
|
-
fake_collector = mock('error collector')
|
64
|
-
self.expects(:error_collector).returns(fake_collector)
|
65
63
|
wl = mock('worker loop')
|
66
64
|
NewRelic::Agent::WorkerLoop.expects(:new).returns(wl)
|
67
65
|
wl.expects(:run).with(30).yields
|
68
66
|
self.expects(:harvest_and_send_timeslice_data)
|
69
67
|
self.expects(:harvest_and_send_slowest_sample)
|
70
|
-
fake_collector.expects(:enabled).returns(true)
|
71
68
|
self.expects(:harvest_and_send_errors)
|
69
|
+
NewRelic::Agent.expects(:load_data)
|
72
70
|
create_and_run_worker_loop
|
73
71
|
end
|
74
72
|
|
@@ -2,81 +2,126 @@ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper
|
|
2
2
|
module NewRelic
|
3
3
|
module Agent
|
4
4
|
class AgentTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
@agent = NewRelic::Agent::Agent.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_serialize
|
12
|
+
assert_equal([{}, [], []], @agent.send(:serialize), "should return nil when shut down")
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_harvest_transaction_traces
|
16
|
+
assert_equal([], @agent.send(:harvest_transaction_traces), 'should return transaction traces')
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_harvest_timeslice_data
|
20
|
+
assert_equal({}, @agent.send(:harvest_timeslice_data), 'should return timeslice data')
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_harvest_errors
|
24
|
+
assert_equal([], @agent.send(:harvest_errors), 'should return errors')
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_merge_data_from_empty
|
28
|
+
unsent_timeslice_data = mock('unsent timeslice data')
|
29
|
+
unsent_errors = mock('unsent errors')
|
30
|
+
unsent_traces = mock('unsent traces')
|
31
|
+
@agent.instance_eval {
|
32
|
+
@unsent_errors = unsent_errors
|
33
|
+
@unsent_timeslice_data = unsent_timeslice_data
|
34
|
+
@traces = unsent_traces
|
35
|
+
}
|
36
|
+
# nb none of the others should receive merge requests
|
37
|
+
@agent.merge_data_from([{}])
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_merge_data_from_all_three_empty
|
41
|
+
unsent_timeslice_data = mock('unsent timeslice data')
|
42
|
+
unsent_errors = mock('unsent errors')
|
43
|
+
unsent_traces = mock('unsent traces')
|
44
|
+
@agent.instance_eval {
|
45
|
+
@unsent_errors = unsent_errors
|
46
|
+
@unsent_timeslice_data = unsent_timeslice_data
|
47
|
+
@traces = unsent_traces
|
48
|
+
}
|
49
|
+
unsent_errors.expects(:+).with([])
|
50
|
+
unsent_traces.expects(:+).with([])
|
51
|
+
@agent.merge_data_from([{}, [], []])
|
52
|
+
end
|
53
|
+
|
5
54
|
def test_sql_normalization
|
6
55
|
|
7
56
|
# basic statement
|
8
57
|
assert_equal "INSERT INTO X values(?,?, ? , ?)",
|
9
|
-
|
58
|
+
@agent.send(:default_sql_obfuscator, "INSERT INTO X values('test',0, 1 , 2)")
|
10
59
|
|
11
60
|
# escaped literals
|
12
61
|
assert_equal "INSERT INTO X values(?, ?,?, ? , ?)",
|
13
|
-
|
62
|
+
@agent.send(:default_sql_obfuscator, "INSERT INTO X values('', 'jim''s ssn',0, 1 , 'jim''s son''s son')")
|
14
63
|
|
15
64
|
# multiple string literals
|
16
65
|
assert_equal "INSERT INTO X values(?,?,?, ? , ?)",
|
17
|
-
|
66
|
+
@agent.send(:default_sql_obfuscator, "INSERT INTO X values('jim''s ssn','x',0, 1 , 2)")
|
18
67
|
|
19
68
|
# empty string literal
|
20
69
|
# NOTE: the empty string literal resolves to empty string, which for our purposes is acceptable
|
21
70
|
assert_equal "INSERT INTO X values(?,?,?, ? , ?)",
|
22
|
-
|
71
|
+
@agent.send(:default_sql_obfuscator, "INSERT INTO X values('','x',0, 1 , 2)")
|
23
72
|
|
24
73
|
# try a select statement
|
25
74
|
assert_equal "select * from table where name=? and ssn=?",
|
26
|
-
|
75
|
+
@agent.send(:default_sql_obfuscator, "select * from table where name='jim gochee' and ssn=0012211223")
|
27
76
|
|
28
77
|
# number literals embedded in sql - oh well
|
29
78
|
assert_equal "select * from table_? where name=? and ssn=?",
|
30
|
-
|
79
|
+
@agent.send(:default_sql_obfuscator, "select * from table_007 where name='jim gochee' and ssn=0012211223")
|
31
80
|
end
|
32
81
|
|
33
82
|
def test_sql_normalization__single_quotes
|
34
83
|
assert_equal "INSERT ? into table",
|
35
|
-
|
84
|
+
@agent.send(:default_sql_obfuscator, "INSERT 'this isn''t a real value' into table")
|
36
85
|
assert_equal "INSERT ? into table",
|
37
|
-
|
86
|
+
@agent.send(:default_sql_obfuscator, %q[INSERT '"' into table])
|
38
87
|
assert_equal "INSERT ? into table",
|
39
|
-
|
88
|
+
@agent.send(:default_sql_obfuscator, %q[INSERT ' "some text" \" ' into table])
|
40
89
|
# could not get this one licked. no biggie
|
41
90
|
# assert_equal "INSERT ? into table",
|
42
|
-
#
|
91
|
+
# @agent.send(:default_sql_obfuscator, %q[INSERT '\'' into table])
|
43
92
|
assert_equal "INSERT ? into table",
|
44
|
-
|
93
|
+
@agent.send(:default_sql_obfuscator, %q[INSERT ''' ' into table])
|
45
94
|
end
|
46
95
|
def test_sql_normalization__double_quotes
|
47
96
|
assert_equal "INSERT ? into table",
|
48
|
-
|
97
|
+
@agent.send(:default_sql_obfuscator, %q[INSERT "this isn't a real value" into table])
|
49
98
|
assert_equal "INSERT ? into table",
|
50
|
-
|
99
|
+
@agent.send(:default_sql_obfuscator, %q[INSERT "'" into table])
|
51
100
|
assert_equal "INSERT ? into table",
|
52
|
-
|
101
|
+
@agent.send(:default_sql_obfuscator, %q[INSERT " \" " into table])
|
53
102
|
assert_equal "INSERT ? into table",
|
54
|
-
|
103
|
+
@agent.send(:default_sql_obfuscator, %q[INSERT " 'some text' " into table])
|
55
104
|
end
|
56
105
|
def test_sql_obfuscation_filters
|
57
|
-
|
58
|
-
|
59
|
-
NewRelic::Agent.set_sql_obfuscator(:replace) do |sql|
|
60
|
-
sql = "1" + sql
|
106
|
+
@agent.set_sql_obfuscator(:replace) do |string|
|
107
|
+
"1" + string
|
61
108
|
end
|
62
109
|
|
63
110
|
sql = "SELECT * FROM TABLE 123 'jim'"
|
64
111
|
|
65
|
-
assert_equal "1" + sql,
|
112
|
+
assert_equal "1" + sql, @agent.obfuscator.call(sql)
|
66
113
|
|
67
|
-
|
68
|
-
|
114
|
+
@agent.set_sql_obfuscator(:before) do |string|
|
115
|
+
"2" + string
|
69
116
|
end
|
70
117
|
|
71
|
-
assert_equal "12" + sql,
|
118
|
+
assert_equal "12" + sql, @agent.obfuscator.call(sql)
|
72
119
|
|
73
|
-
|
74
|
-
|
120
|
+
@agent.set_sql_obfuscator(:after) do |string|
|
121
|
+
string + "3"
|
75
122
|
end
|
76
123
|
|
77
|
-
assert_equal "12" + sql + "3",
|
78
|
-
|
79
|
-
NewRelic::Agent.agent.set_sql_obfuscator(:replace, &orig)
|
124
|
+
assert_equal "12" + sql + "3", @agent.obfuscator.call(sql)
|
80
125
|
end
|
81
126
|
|
82
127
|
|
@@ -232,12 +232,12 @@ class NewRelic::Agent::AgentTestControllerTest < ActionController::TestCase
|
|
232
232
|
engine = @agent.stats_engine
|
233
233
|
get :entry_action
|
234
234
|
assert_nil Thread.current[:newrelic_ignore_controller]
|
235
|
-
assert_nil engine.
|
236
|
-
assert_nil engine.
|
237
|
-
assert_nil engine.
|
238
|
-
assert_nil engine.
|
239
|
-
assert_nil engine.
|
240
|
-
assert_not_nil engine.
|
235
|
+
assert_nil engine.lookup_stats('Controller/agent_test/entry_action')
|
236
|
+
assert_nil engine.lookup_stats('Controller/agent_test_controller/entry_action')
|
237
|
+
assert_nil engine.lookup_stats('Controller/AgentTestController/entry_action')
|
238
|
+
assert_nil engine.lookup_stats('Controller/NewRelic::Agent::AgentTestController/internal_action')
|
239
|
+
assert_nil engine.lookup_stats('Controller/NewRelic::Agent::AgentTestController_controller/internal_action')
|
240
|
+
assert_not_nil engine.lookup_stats('Controller/NewRelic::Agent::AgentTestController/internal_traced_action')
|
241
241
|
end
|
242
242
|
def test_action_instrumentation
|
243
243
|
begin
|
@@ -271,23 +271,24 @@ class NewRelic::Agent::AgentTestControllerTest < ActionController::TestCase
|
|
271
271
|
engine.clear_stats
|
272
272
|
|
273
273
|
assert_equal 0, NewRelic::Agent::BusyCalculator.busy_count
|
274
|
-
get :index, 'social_security_number' => "001-555-1212", 'wait' => '
|
274
|
+
get :index, 'social_security_number' => "001-555-1212", 'wait' => '0.05'
|
275
275
|
NewRelic::Agent::BusyCalculator.harvest_busy
|
276
276
|
|
277
277
|
assert_equal 1, stats('Instance/Busy').call_count
|
278
278
|
assert_equal 1, stats('HttpDispatcher').call_count
|
279
279
|
# We are probably busy about 99% of the time, but lets make sure it's at least 50
|
280
|
-
assert stats('Instance/Busy').total_call_time > 0.5, stats('Instance/Busy').inspect
|
280
|
+
assert stats('Instance/Busy').total_call_time > (0.5 * 0.05), stats('Instance/Busy').inspect
|
281
281
|
assert_equal 0, stats('WebFrontend/Mongrel/Average Queue Time').call_count
|
282
282
|
end
|
283
283
|
|
284
284
|
def test_histogram
|
285
285
|
engine.clear_stats
|
286
286
|
get :index, 'social_security_number' => "001-555-1212"
|
287
|
+
stats_engine = NewRelic::Agent.instance.stats_engine
|
287
288
|
bucket = NewRelic::Agent.instance.stats_engine.metrics.find { | m | m =~ /^Response Times/ }
|
288
|
-
assert_not_nil bucket
|
289
|
+
assert_not_nil bucket, "Bucket contents: #{bucket.inspect}, #{stats_engine.metrics.inspect}"
|
289
290
|
bucket_stats = stats(bucket)
|
290
|
-
assert_equal 1, bucket_stats.call_count
|
291
|
+
assert_equal 1, bucket_stats.call_count, "expected the bucket to have a call, but instead got: #{bucket_stats.inspect}"
|
291
292
|
end
|
292
293
|
|
293
294
|
def test_queue_headers_no_header
|
@@ -19,7 +19,7 @@ class NewRelic::Agent::BeaconConfigurationTest < Test::Unit::TestCase
|
|
19
19
|
assert_equal 'a browser monitoring key', bc.browser_monitoring_key
|
20
20
|
assert_equal 'an application id', bc.application_id
|
21
21
|
assert_equal 'a beacon', bc.beacon
|
22
|
-
assert_equal
|
22
|
+
assert_equal 269, bc.browser_timing_header.size
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_license_bytes_nil
|
@@ -36,7 +36,7 @@ class NewRelic::Agent::BeaconConfigurationTest < Test::Unit::TestCase
|
|
36
36
|
NewRelic::Control.instance.expects(:license_key).never
|
37
37
|
assert_equal([97] * 40, bc.license_bytes, "should return the cached value if it exists")
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def test_license_bytes_should_set_instance_cache
|
41
41
|
connect_data = {}
|
42
42
|
bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
|
@@ -50,21 +50,38 @@ class NewRelic::Agent::BeaconConfigurationTest < Test::Unit::TestCase
|
|
50
50
|
connect_data = {}
|
51
51
|
bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
|
52
52
|
bc.instance_eval { @rum_enabled = false }
|
53
|
-
assert_equal '', bc.build_browser_timing_header, "should not return a header when rum enabled is false"
|
53
|
+
assert_equal '', bc.build_browser_timing_header(connect_data), "should not return a header when rum enabled is false"
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def test_build_browser_timing_header_enabled_but_no_key
|
57
57
|
connect_data = {}
|
58
58
|
bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
|
59
59
|
bc.instance_eval { @rum_enabled = true; @browser_monitoring_key = nil }
|
60
|
-
assert_equal '', bc.build_browser_timing_header, "should not return a header when browser_monitoring_key is nil"
|
60
|
+
assert_equal '', bc.build_browser_timing_header(connect_data), "should not return a header when browser_monitoring_key is nil"
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
|
+
def test_build_browser_timing_header_enabled_checking_for_episodes_url
|
64
|
+
connect_data = {'episodes_url' => 'an episodes url'}
|
65
|
+
bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
|
66
|
+
bc.instance_eval { @rum_enabled = true; @browser_monitoring_key = 'a' * 40 }
|
67
|
+
assert(bc.build_browser_timing_header(connect_data).include?('an episodes url'), "should include the episodes url in the javascript")
|
68
|
+
end
|
69
|
+
|
63
70
|
def test_build_browser_timing_header_enabled_with_key
|
64
71
|
connect_data = {}
|
65
72
|
bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
|
66
73
|
bc.instance_eval { @browser_monitoring_key = 'a browser monitoring key' }
|
67
|
-
|
74
|
+
bc.expects(:load_file_js).with({}).returns('load file js')
|
75
|
+
assert(bc.build_browser_timing_header(connect_data).include?('load file js'), "header should be generated when rum is enabled and browser monitoring key is set")
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_basic_javascript
|
79
|
+
connect_data = {}
|
80
|
+
bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
|
81
|
+
mock_data = mock('connect data')
|
82
|
+
bc.expects(:load_file_js).with(mock_data)
|
83
|
+
# should just pass through the data
|
84
|
+
bc.basic_javascript(mock_data)
|
68
85
|
end
|
69
86
|
|
70
87
|
def test_build_browser_timing_header_should_html_safe_header
|
@@ -72,33 +89,33 @@ class NewRelic::Agent::BeaconConfigurationTest < Test::Unit::TestCase
|
|
72
89
|
connect_data = {'browser_key' => 'a' * 40}
|
73
90
|
bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
|
74
91
|
assert_equal('a' * 40, bc.instance_variable_get('@browser_monitoring_key'), "should save the key from the config")
|
75
|
-
bc.expects(:
|
92
|
+
bc.expects(:basic_javascript).with(connect_data).returns(mock_javascript)
|
76
93
|
mock_javascript.expects(:respond_to?).with(:html_safe).returns(true)
|
77
94
|
mock_javascript.expects(:html_safe)
|
78
|
-
bc.build_browser_timing_header
|
95
|
+
bc.build_browser_timing_header(connect_data)
|
79
96
|
end
|
80
|
-
|
81
|
-
def
|
97
|
+
|
98
|
+
def test_load_file_js_load_episodes_file_false
|
82
99
|
connect_data = {'rum.load_episodes_file' => false}
|
83
100
|
bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
|
84
|
-
assert_equal '', bc.
|
101
|
+
assert_equal '', bc.load_file_js(connect_data), "should be empty when load episodes file is false"
|
85
102
|
end
|
86
|
-
|
87
|
-
def
|
103
|
+
|
104
|
+
def test_load_file_js_load_episodes_file_missing
|
88
105
|
connect_data = {}
|
89
106
|
bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
|
90
|
-
assert_equal(
|
107
|
+
assert_equal(183, bc.load_file_js(connect_data).size, "should output the javascript when there is no configuration")
|
91
108
|
end
|
92
109
|
|
93
|
-
def
|
110
|
+
def test_load_file_js_load_episodes_file_present
|
94
111
|
connect_data = {'rum.load_episodes_file' => true}
|
95
112
|
bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
|
96
|
-
assert_equal(
|
113
|
+
assert_equal(183, bc.load_file_js(connect_data).size, "should output the javascript when rum.load_episodes_file is true")
|
97
114
|
end
|
98
|
-
|
99
|
-
def
|
115
|
+
|
116
|
+
def test_load_file_js_load_episodes_file_with_episodes_url
|
100
117
|
connect_data = {'episodes_url' => 'an episodes url'}
|
101
118
|
bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
|
102
|
-
assert(bc.
|
119
|
+
assert(bc.load_file_js(connect_data).include?('an episodes url'), "should include the episodes url by default")
|
103
120
|
end
|
104
121
|
end
|
@@ -30,13 +30,13 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
|
|
30
30
|
|
31
31
|
def test_browser_timing_header
|
32
32
|
header = browser_timing_header
|
33
|
-
assert_equal "<script>var NREUMQ=[];NREUMQ.push([\"mark\",\"firstbyte\",new Date().getTime()])
|
33
|
+
assert_equal "<script>var NREUMQ=[];NREUMQ.push([\"mark\",\"firstbyte\",new Date().getTime()]);(function(){var d=document;var e=d.createElement(\"script\");e.type=\"text/javascript\";e.async=true;e.src=\"this_is_my_file\";var s=d.getElementsByTagName(\"script\")[0];s.parentNode.insertBefore(e,s);})()</script>", header
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def test_browser_timing_header_with_rum_enabled_not_specified
|
37
37
|
NewRelic::Agent.instance.expects(:beacon_configuration).at_least_once.returns( NewRelic::Agent::BeaconConfiguration.new({"browser_key" => "browserKey", "application_id" => "apId", "beacon"=>"beacon", "episodes_url"=>"this_is_my_file"}))
|
38
38
|
header = browser_timing_header
|
39
|
-
assert_equal "<script>var NREUMQ=[];NREUMQ.push([\"mark\",\"firstbyte\",new Date().getTime()])
|
39
|
+
assert_equal "<script>var NREUMQ=[];NREUMQ.push([\"mark\",\"firstbyte\",new Date().getTime()]);(function(){var d=document;var e=d.createElement(\"script\");e.type=\"text/javascript\";e.async=true;e.src=\"this_is_my_file\";var s=d.getElementsByTagName(\"script\")[0];s.parentNode.insertBefore(e,s);})()</script>", header
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_browser_timing_header_with_rum_enabled_false
|
@@ -68,15 +68,14 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
|
|
68
68
|
Thread.current[:newrelic_start_time] = Time.now
|
69
69
|
|
70
70
|
footer = browser_timing_footer
|
71
|
-
|
72
|
-
assert footer.include?(snippet), "Expected footer to include snippet: #{snippet}, but instead was #{footer}"
|
71
|
+
assert footer.include?("<script type=\"text/javascript\" charset=\"utf-8\">NREUMQ.push([\"nrf2\",")
|
73
72
|
end
|
74
|
-
|
73
|
+
|
75
74
|
def test_browser_timing_footer_without_calling_header
|
76
75
|
footer = browser_timing_footer
|
77
76
|
assert_equal "", footer
|
78
77
|
end
|
79
|
-
|
78
|
+
|
80
79
|
def test_browser_timing_footer_with_no_browser_key_rum_enabled
|
81
80
|
browser_timing_header
|
82
81
|
NewRelic::Agent.instance.expects(:beacon_configuration).returns( NewRelic::Agent::BeaconConfiguration.new({"rum.enabled" => true, "application_id" => "apId", "beacon"=>"beacon", "episodes_url"=>"this_is_my_file"}))
|
@@ -101,10 +100,8 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
|
|
101
100
|
config.expects(:license_bytes).returns(license_bytes)
|
102
101
|
NewRelic::Agent.instance.expects(:beacon_configuration).returns(config).at_least_once
|
103
102
|
footer = browser_timing_footer
|
104
|
-
|
105
|
-
|
106
|
-
assert(footer.include?(beginning_snippet), "expected footer to include beginning snippet: #{beginning_snippet}, but was #{footer}")
|
107
|
-
assert(footer.include?(ending_snippet), "expected footer to include ending snippet: #{ending_snippet}, but was #{footer}")
|
103
|
+
assert footer.include?("<script type=\"text/javascript\" charset=\"utf-8\">NREUMQ.push([\"nrf2\",")
|
104
|
+
assert footer.include?("])</script>")
|
108
105
|
end
|
109
106
|
|
110
107
|
def test_browser_timing_footer_with_no_beacon_configuration
|
@@ -155,13 +152,13 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
|
|
155
152
|
self.expects(:browser_monitoring_start_time).returns(nil)
|
156
153
|
assert_equal('', generate_footer_js, "should not send javascript when there is no start time")
|
157
154
|
end
|
158
|
-
|
155
|
+
|
159
156
|
def test_generate_footer_js_with_start_time
|
160
157
|
self.expects(:browser_monitoring_start_time).returns(Time.at(100))
|
161
158
|
fake_bc = mock('beacon configuration')
|
162
159
|
fake_bc.expects(:application_id).returns(1)
|
163
160
|
fake_bc.expects(:beacon).returns('beacon')
|
164
|
-
fake_bc.expects(:browser_monitoring_key).returns('a' * 40)
|
161
|
+
fake_bc.expects(:browser_monitoring_key).returns('a' * 40)
|
165
162
|
NewRelic::Agent.instance.expects(:beacon_configuration).returns(fake_bc)
|
166
163
|
self.expects(:footer_js_string).with('beacon', 'a' * 40, 1).returns('footer js')
|
167
164
|
assert_equal('footer js', generate_footer_js, 'should generate and return the footer JS when there is a start time')
|
@@ -171,7 +168,7 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
|
|
171
168
|
Thread.current[:newrelic_most_recent_transaction] = 'a transaction name'
|
172
169
|
assert_equal('a transaction name', browser_monitoring_transaction_name, "should take the value from the thread local")
|
173
170
|
end
|
174
|
-
|
171
|
+
|
175
172
|
def test_browser_monitoring_transaction_name_empty
|
176
173
|
Thread.current[:newrelic_most_recent_transaction] = ''
|
177
174
|
assert_equal('', browser_monitoring_transaction_name, "should take the value even when it is empty")
|
@@ -204,7 +201,7 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
|
|
204
201
|
Thread.current[:newrelic_queue_time] = nil
|
205
202
|
assert_equal(0.0, browser_monitoring_queue_time, 'should return zero when there is no queue time')
|
206
203
|
end
|
207
|
-
|
204
|
+
|
208
205
|
def test_browser_monitoring_queue_time_zero
|
209
206
|
Thread.current[:newrelic_queue_time] = 0.0
|
210
207
|
assert_equal(0.0, browser_monitoring_queue_time, 'should return zero when there is zero queue time')
|
@@ -213,7 +210,7 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
|
|
213
210
|
def test_browser_monitoring_queue_time_ducks
|
214
211
|
Thread.current[:newrelic_queue_time] = 'a duck'
|
215
212
|
assert_equal(0.0, browser_monitoring_queue_time, 'should return zero when there is an incorrect queue time')
|
216
|
-
end
|
213
|
+
end
|
217
214
|
|
218
215
|
def test_browser_monitoring_queue_time_nonzero
|
219
216
|
Thread.current[:newrelic_queue_time] = 3.00002
|
@@ -232,9 +229,9 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
|
|
232
229
|
Thread.current[:newrelic_most_recent_transaction] = 'most recent transaction'
|
233
230
|
|
234
231
|
self.expects(:obfuscate).with('most recent transaction').returns('most recent transaction')
|
235
|
-
|
232
|
+
|
236
233
|
value = footer_js_string(beacon, license_key, application_id)
|
237
|
-
assert_equal('<script
|
234
|
+
assert_equal('<script type="text/javascript" charset="utf-8">NREUMQ.push(["nrf2","","",1,"most recent transaction",0,0])</script>', value, "should return the javascript given some default values")
|
238
235
|
end
|
239
236
|
|
240
237
|
def test_html_safe_if_needed_unsafed
|
@@ -245,14 +242,14 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
|
|
245
242
|
string.expects(:respond_to?).with(:html_safe).returns(false)
|
246
243
|
assert_equal(string, html_safe_if_needed(string))
|
247
244
|
end
|
248
|
-
|
245
|
+
|
249
246
|
def test_html_safe_if_needed_safed
|
250
247
|
string = mock('string')
|
251
248
|
string.expects(:respond_to?).with(:html_safe).returns(true)
|
252
249
|
string.expects(:html_safe).returns(string)
|
253
250
|
# here to handle 1.9 encoding - we stub this out because it should
|
254
251
|
# be handled automatically and is outside the scope of this test
|
255
|
-
string.stubs(:respond_to?).with(:encoding).returns(false)
|
252
|
+
string.stubs(:respond_to?).with(:encoding).returns(false)
|
256
253
|
assert_equal(string, html_safe_if_needed(string))
|
257
254
|
end
|
258
255
|
|
@@ -263,12 +260,4 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
|
|
263
260
|
output = obfuscate(text)
|
264
261
|
assert_equal('YCJrZXV2fih5Y25vaCFtZSR2a2ZkZSp/aXV1', output, "should output obfuscated text")
|
265
262
|
end
|
266
|
-
|
267
|
-
def test_obfuscate_long_string
|
268
|
-
text = 'a happy piece of small text' * 5
|
269
|
-
key = (1..40).to_a
|
270
|
-
NewRelic::Agent.instance.beacon_configuration.expects(:license_bytes).returns(key)
|
271
|
-
output = obfuscate(text)
|
272
|
-
assert_equal('YCJrZXV2fih5Y25vaCFtZSR2a2ZkZSp/aXV1YyNsZHZ3cSl6YmluZCJsYiV1amllZit4aHl2YiRtZ3d4cCp7ZWhiZyNrYyZ0ZWhmZyx5ZHp3ZSVuZnh5cyt8ZGRhZiRqYCd7ZGtnYC11Z3twZCZvaXl6cix9aGdgYSVpYSh6Z2pgYSF2Znxx', output, "should output obfuscated text")
|
273
|
-
end
|
274
263
|
end
|