newrelic_rpm 2.8.0
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/LICENSE +37 -0
- data/README +93 -0
- data/Rakefile +38 -0
- data/install.rb +37 -0
- data/lib/new_relic/agent.rb +26 -0
- data/lib/new_relic/agent/agent.rb +762 -0
- data/lib/new_relic/agent/chained_call.rb +13 -0
- data/lib/new_relic/agent/collection_helper.rb +81 -0
- data/lib/new_relic/agent/error_collector.rb +105 -0
- data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +95 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +151 -0
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +90 -0
- data/lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb +105 -0
- data/lib/new_relic/agent/instrumentation/memcache.rb +18 -0
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +17 -0
- data/lib/new_relic/agent/instrumentation/merb/dispatcher.rb +15 -0
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +6 -0
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +35 -0
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +27 -0
- data/lib/new_relic/agent/instrumentation/rails/dispatcher.rb +30 -0
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +23 -0
- data/lib/new_relic/agent/instrumentation/rails/rails.rb +6 -0
- data/lib/new_relic/agent/method_tracer.rb +171 -0
- data/lib/new_relic/agent/patch_const_missing.rb +31 -0
- data/lib/new_relic/agent/samplers/cpu.rb +29 -0
- data/lib/new_relic/agent/samplers/memory.rb +55 -0
- data/lib/new_relic/agent/samplers/mongrel.rb +26 -0
- data/lib/new_relic/agent/stats_engine.rb +241 -0
- data/lib/new_relic/agent/synchronize.rb +40 -0
- data/lib/new_relic/agent/transaction_sampler.rb +281 -0
- data/lib/new_relic/agent/worker_loop.rb +128 -0
- data/lib/new_relic/api/deployments.rb +92 -0
- data/lib/new_relic/config.rb +194 -0
- data/lib/new_relic/config/merb.rb +35 -0
- data/lib/new_relic/config/rails.rb +113 -0
- data/lib/new_relic/config/ruby.rb +9 -0
- data/lib/new_relic/local_environment.rb +108 -0
- data/lib/new_relic/merbtasks.rb +6 -0
- data/lib/new_relic/metric_data.rb +26 -0
- data/lib/new_relic/metric_spec.rb +39 -0
- data/lib/new_relic/metrics.rb +7 -0
- data/lib/new_relic/noticed_error.rb +21 -0
- data/lib/new_relic/shim_agent.rb +95 -0
- data/lib/new_relic/stats.rb +359 -0
- data/lib/new_relic/transaction_analysis.rb +122 -0
- data/lib/new_relic/transaction_sample.rb +499 -0
- data/lib/new_relic/version.rb +111 -0
- data/lib/new_relic_api.rb +275 -0
- data/lib/newrelic_rpm.rb +27 -0
- data/lib/tasks/agent_tests.rake +14 -0
- data/lib/tasks/all.rb +4 -0
- data/lib/tasks/install.rake +7 -0
- data/newrelic.yml +137 -0
- data/recipes/newrelic.rb +46 -0
- data/test/config/newrelic.yml +26 -0
- data/test/config/test_config.rb +9 -0
- data/test/new_relic/agent/mock_ar_connection.rb +40 -0
- data/test/new_relic/agent/mock_scope_listener.rb +23 -0
- data/test/new_relic/agent/model_fixture.rb +17 -0
- data/test/new_relic/agent/tc_active_record.rb +91 -0
- data/test/new_relic/agent/tc_agent.rb +112 -0
- data/test/new_relic/agent/tc_collection_helper.rb +104 -0
- data/test/new_relic/agent/tc_controller.rb +98 -0
- data/test/new_relic/agent/tc_dispatcher_instrumentation.rb +52 -0
- data/test/new_relic/agent/tc_error_collector.rb +127 -0
- data/test/new_relic/agent/tc_method_tracer.rb +306 -0
- data/test/new_relic/agent/tc_stats_engine.rb +218 -0
- data/test/new_relic/agent/tc_synchronize.rb +37 -0
- data/test/new_relic/agent/tc_transaction_sample.rb +175 -0
- data/test/new_relic/agent/tc_transaction_sample_builder.rb +200 -0
- data/test/new_relic/agent/tc_transaction_sampler.rb +305 -0
- data/test/new_relic/agent/tc_worker_loop.rb +101 -0
- data/test/new_relic/agent/testable_agent.rb +13 -0
- data/test/new_relic/tc_config.rb +36 -0
- data/test/new_relic/tc_deployments_api.rb +37 -0
- data/test/new_relic/tc_environment.rb +94 -0
- data/test/new_relic/tc_metric_spec.rb +150 -0
- data/test/new_relic/tc_shim_agent.rb +9 -0
- data/test/new_relic/tc_stats.rb +141 -0
- data/test/test_helper.rb +39 -0
- data/test/ui/tc_newrelic_helper.rb +44 -0
- data/ui/controllers/newrelic_controller.rb +200 -0
- data/ui/helpers/google_pie_chart.rb +55 -0
- data/ui/helpers/newrelic_helper.rb +286 -0
- data/ui/views/layouts/newrelic_default.rhtml +49 -0
- data/ui/views/newrelic/_explain_plans.rhtml +27 -0
- data/ui/views/newrelic/_sample.rhtml +12 -0
- data/ui/views/newrelic/_segment.rhtml +28 -0
- data/ui/views/newrelic/_segment_row.rhtml +14 -0
- data/ui/views/newrelic/_show_sample_detail.rhtml +22 -0
- data/ui/views/newrelic/_show_sample_sql.rhtml +19 -0
- data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
- data/ui/views/newrelic/_sql_row.rhtml +11 -0
- data/ui/views/newrelic/_stack_trace.rhtml +30 -0
- data/ui/views/newrelic/_table.rhtml +12 -0
- data/ui/views/newrelic/explain_sql.rhtml +45 -0
- data/ui/views/newrelic/images/arrow-close.png +0 -0
- data/ui/views/newrelic/images/arrow-open.png +0 -0
- data/ui/views/newrelic/images/blue_bar.gif +0 -0
- data/ui/views/newrelic/images/gray_bar.gif +0 -0
- data/ui/views/newrelic/index.rhtml +37 -0
- data/ui/views/newrelic/javascript/transaction_sample.js +107 -0
- data/ui/views/newrelic/sample_not_found.rhtml +2 -0
- data/ui/views/newrelic/show_sample.rhtml +62 -0
- data/ui/views/newrelic/show_source.rhtml +3 -0
- data/ui/views/newrelic/stylesheets/style.css +394 -0
- metadata +180 -0
@@ -0,0 +1,305 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
+
##require 'new_relic/agent/transaction_sampler'
|
3
|
+
|
4
|
+
::RPM_DEVELOPER = true unless defined? ::RPM_DEVELOPER
|
5
|
+
|
6
|
+
class NewRelic::Agent::TransactionSampler
|
7
|
+
public :builder
|
8
|
+
end
|
9
|
+
|
10
|
+
class NewRelic::Agent::TransationSamplerTests < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def setup
|
13
|
+
Thread::current[:record_sql] = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_multiple_samples
|
17
|
+
@sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
|
18
|
+
|
19
|
+
run_sample_trace
|
20
|
+
run_sample_trace
|
21
|
+
run_sample_trace
|
22
|
+
run_sample_trace
|
23
|
+
|
24
|
+
samples = @sampler.get_samples
|
25
|
+
assert_equal 4, samples.length
|
26
|
+
assert_equal "a", samples.first.root_segment.called_segments[0].metric_name
|
27
|
+
assert_equal "a", samples.last.root_segment.called_segments[0].metric_name
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def test_harvest_slowest
|
32
|
+
@sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
|
33
|
+
|
34
|
+
run_sample_trace
|
35
|
+
run_sample_trace
|
36
|
+
run_sample_trace { sleep 0.5 }
|
37
|
+
run_sample_trace
|
38
|
+
run_sample_trace
|
39
|
+
|
40
|
+
slowest = @sampler.harvest_slowest_sample(nil)
|
41
|
+
assert slowest.duration >= 0.5
|
42
|
+
|
43
|
+
run_sample_trace { sleep 0.2 }
|
44
|
+
not_as_slow = @sampler.harvest_slowest_sample(slowest)
|
45
|
+
assert not_as_slow == slowest
|
46
|
+
|
47
|
+
run_sample_trace { sleep 0.6 }
|
48
|
+
new_slowest = @sampler.harvest_slowest_sample(slowest)
|
49
|
+
assert new_slowest != slowest
|
50
|
+
assert new_slowest.duration >= 0.6
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def test_preare_to_send
|
55
|
+
@sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
|
56
|
+
|
57
|
+
run_sample_trace { sleep 0.2 }
|
58
|
+
sample = @sampler.harvest_slowest_sample(nil)
|
59
|
+
|
60
|
+
ready_to_send = sample.prepare_to_send
|
61
|
+
assert sample.duration == ready_to_send.duration
|
62
|
+
|
63
|
+
assert ready_to_send.start_time.is_a?(Time)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_multithread
|
67
|
+
@sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
|
68
|
+
threads = []
|
69
|
+
|
70
|
+
20.times do
|
71
|
+
t = Thread.new(@sampler) do |the_sampler|
|
72
|
+
@sampler = the_sampler
|
73
|
+
100.times do
|
74
|
+
run_sample_trace { sleep 0.01 }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
threads << t
|
79
|
+
end
|
80
|
+
threads.each {|t| t.join }
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_sample_with_parallel_paths
|
84
|
+
@sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
|
85
|
+
|
86
|
+
assert_equal 0, @sampler.scope_depth
|
87
|
+
|
88
|
+
@sampler.notice_first_scope_push Time.now.to_f
|
89
|
+
@sampler.notice_transaction "/path", nil, {}
|
90
|
+
@sampler.notice_push_scope "a"
|
91
|
+
|
92
|
+
assert_equal 1, @sampler.scope_depth
|
93
|
+
|
94
|
+
@sampler.notice_pop_scope "a"
|
95
|
+
@sampler.notice_scope_empty
|
96
|
+
|
97
|
+
assert_equal 0, @sampler.scope_depth
|
98
|
+
|
99
|
+
@sampler.notice_first_scope_push Time.now.to_f
|
100
|
+
@sampler.notice_transaction "/path", nil, {}
|
101
|
+
@sampler.notice_push_scope "a"
|
102
|
+
@sampler.notice_pop_scope "a"
|
103
|
+
@sampler.notice_scope_empty
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_double_scope_stack_empty
|
107
|
+
@sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
|
108
|
+
|
109
|
+
@sampler.notice_first_scope_push Time.now.to_f
|
110
|
+
@sampler.notice_transaction "/path", nil, {}
|
111
|
+
@sampler.notice_push_scope "a"
|
112
|
+
@sampler.notice_pop_scope "a"
|
113
|
+
@sampler.notice_scope_empty
|
114
|
+
@sampler.notice_scope_empty
|
115
|
+
@sampler.notice_scope_empty
|
116
|
+
@sampler.notice_scope_empty
|
117
|
+
|
118
|
+
assert_not_nil @sampler.harvest_slowest_sample(nil)
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
def test_record_sql_off
|
123
|
+
sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
|
124
|
+
|
125
|
+
sampler.notice_first_scope_push Time.now.to_f
|
126
|
+
|
127
|
+
Thread::current[:record_sql] = false
|
128
|
+
|
129
|
+
sampler.notice_sql("test", nil, 0)
|
130
|
+
|
131
|
+
segment = sampler.builder.current_segment
|
132
|
+
|
133
|
+
assert_nil segment[:sql]
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_stack_trace__sql
|
137
|
+
sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
|
138
|
+
|
139
|
+
sampler.stack_trace_threshold = 0
|
140
|
+
|
141
|
+
sampler.notice_first_scope_push Time.now.to_f
|
142
|
+
|
143
|
+
sampler.notice_sql("test", nil, 1)
|
144
|
+
|
145
|
+
segment = sampler.builder.current_segment
|
146
|
+
|
147
|
+
assert segment[:sql]
|
148
|
+
assert segment[:backtrace]
|
149
|
+
end
|
150
|
+
def test_stack_trace__scope
|
151
|
+
sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
|
152
|
+
|
153
|
+
sampler.stack_trace_threshold = 0
|
154
|
+
t = Time.now
|
155
|
+
sampler.notice_first_scope_push t.to_f
|
156
|
+
sampler.notice_push_scope 'Bill', (t+1.second).to_f
|
157
|
+
|
158
|
+
segment = sampler.builder.current_segment
|
159
|
+
assert segment[:backtrace]
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_nil_stacktrace
|
163
|
+
sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
|
164
|
+
|
165
|
+
sampler.stack_trace_threshold = 2
|
166
|
+
|
167
|
+
sampler.notice_first_scope_push Time.now.to_f
|
168
|
+
|
169
|
+
sampler.notice_sql("test", nil, 1)
|
170
|
+
|
171
|
+
segment = sampler.builder.current_segment
|
172
|
+
|
173
|
+
assert segment[:sql]
|
174
|
+
assert_nil segment[:backtrace]
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_big_sql
|
178
|
+
@sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
|
179
|
+
|
180
|
+
@sampler.notice_first_scope_push Time.now.to_f
|
181
|
+
|
182
|
+
sql = "SADJKHASDHASD KAJSDH ASKDH ASKDHASDK JASHD KASJDH ASKDJHSAKDJHAS DKJHSADKJSAH DKJASHD SAKJDH SAKDJHS"
|
183
|
+
|
184
|
+
len = 0
|
185
|
+
while len <= NewRelic::Agent::TransactionSampler::MAX_SQL_LENGTH
|
186
|
+
@sampler.notice_sql(sql, nil, 0)
|
187
|
+
len += sql.length
|
188
|
+
end
|
189
|
+
|
190
|
+
segment = @sampler.builder.current_segment
|
191
|
+
|
192
|
+
sql = segment[:sql]
|
193
|
+
|
194
|
+
assert sql.length <= NewRelic::Agent::TransactionSampler::MAX_SQL_LENGTH
|
195
|
+
end
|
196
|
+
|
197
|
+
|
198
|
+
def test_segment_obfuscated
|
199
|
+
@sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
|
200
|
+
|
201
|
+
@sampler.notice_first_scope_push Time.now.to_f
|
202
|
+
|
203
|
+
orig_sql = "SELECT * from Jim where id=66"
|
204
|
+
|
205
|
+
@sampler.notice_sql(orig_sql, nil, 0)
|
206
|
+
|
207
|
+
segment = @sampler.builder.current_segment
|
208
|
+
|
209
|
+
assert_equal orig_sql, segment[:sql]
|
210
|
+
assert_equal "SELECT * from Jim where id=?", segment.obfuscated_sql
|
211
|
+
end
|
212
|
+
|
213
|
+
|
214
|
+
def test_param_capture
|
215
|
+
[true, false].each do |capture|
|
216
|
+
t = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
|
217
|
+
|
218
|
+
NewRelic::Agent::TransactionSampler.capture_params = capture
|
219
|
+
|
220
|
+
t.notice_first_scope_push Time.now.to_f
|
221
|
+
t.notice_transaction('/path', nil, {:param => 'hi'})
|
222
|
+
t.notice_scope_empty
|
223
|
+
|
224
|
+
tt = t.harvest_slowest_sample
|
225
|
+
|
226
|
+
assert_equal (capture) ? 1 : 0, tt.params[:request_params].length
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
|
231
|
+
def test_sql_normalization
|
232
|
+
t = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
|
233
|
+
|
234
|
+
# basic statement
|
235
|
+
assert_equal "INSERT INTO X values(?,?, ? , ?)",
|
236
|
+
t.default_sql_obfuscator("INSERT INTO X values('test',0, 1 , 2)")
|
237
|
+
|
238
|
+
# escaped literals
|
239
|
+
assert_equal "INSERT INTO X values(?, ?,?, ? , ?)",
|
240
|
+
t.default_sql_obfuscator("INSERT INTO X values('', 'jim''s ssn',0, 1 , 'jim''s son''s son')")
|
241
|
+
|
242
|
+
# multiple string literals
|
243
|
+
assert_equal "INSERT INTO X values(?,?,?, ? , ?)",
|
244
|
+
t.default_sql_obfuscator("INSERT INTO X values('jim''s ssn','x',0, 1 , 2)")
|
245
|
+
|
246
|
+
# empty string literal
|
247
|
+
# NOTE: the empty string literal resolves to empty string, which for our purposes is acceptable
|
248
|
+
assert_equal "INSERT INTO X values(?,?,?, ? , ?)",
|
249
|
+
t.default_sql_obfuscator("INSERT INTO X values('','x',0, 1 , 2)")
|
250
|
+
|
251
|
+
# try a select statement
|
252
|
+
assert_equal "select * from table where name=? and ssn=?",
|
253
|
+
t.default_sql_obfuscator("select * from table where name='jim gochee' and ssn=0012211223")
|
254
|
+
|
255
|
+
# number literals embedded in sql - oh well
|
256
|
+
assert_equal "select * from table_? where name=? and ssn=?",
|
257
|
+
t.default_sql_obfuscator("select * from table_007 where name='jim gochee' and ssn=0012211223")
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_sql_obfuscation_filters
|
261
|
+
orig = NewRelic::Agent.agent.obfuscator
|
262
|
+
|
263
|
+
NewRelic::Agent.set_sql_obfuscator(:replace) do |sql|
|
264
|
+
sql = "1" + sql
|
265
|
+
end
|
266
|
+
|
267
|
+
sql = "SELECT * FROM TABLE 123 'jim'"
|
268
|
+
|
269
|
+
assert_equal "1" + sql, NewRelic::Agent.instance.obfuscator.call(sql)
|
270
|
+
|
271
|
+
NewRelic::Agent.set_sql_obfuscator(:before) do |sql|
|
272
|
+
sql = "2" + sql
|
273
|
+
end
|
274
|
+
|
275
|
+
assert_equal "12" + sql, NewRelic::Agent.instance.obfuscator.call(sql)
|
276
|
+
|
277
|
+
NewRelic::Agent.set_sql_obfuscator(:after) do |sql|
|
278
|
+
sql = sql + "3"
|
279
|
+
end
|
280
|
+
|
281
|
+
assert_equal "12" + sql + "3", NewRelic::Agent.instance.obfuscator.call(sql)
|
282
|
+
|
283
|
+
NewRelic::Agent.agent.set_sql_obfuscator(:replace, &orig)
|
284
|
+
end
|
285
|
+
|
286
|
+
|
287
|
+
private
|
288
|
+
def run_sample_trace(&proc)
|
289
|
+
@sampler.notice_first_scope_push Time.now.to_f
|
290
|
+
@sampler.notice_transaction '/path', nil, {}
|
291
|
+
@sampler.notice_push_scope "a"
|
292
|
+
@sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'wheat'", nil, 0)
|
293
|
+
@sampler.notice_push_scope "ab"
|
294
|
+
@sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'white'", nil, 0)
|
295
|
+
proc.call if proc
|
296
|
+
@sampler.notice_pop_scope "ab"
|
297
|
+
@sampler.notice_push_scope "lew"
|
298
|
+
@sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'french'", nil, 0)
|
299
|
+
@sampler.notice_pop_scope "lew"
|
300
|
+
@sampler.notice_pop_scope "a"
|
301
|
+
@sampler.notice_scope_empty
|
302
|
+
end
|
303
|
+
|
304
|
+
end
|
305
|
+
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
3
|
+
|
4
|
+
NewRelic::Agent::WorkerLoop.class_eval do
|
5
|
+
public :run_next_task
|
6
|
+
end
|
7
|
+
|
8
|
+
class NewRelic::Agent::WorkerLoopTests < Test::Unit::TestCase
|
9
|
+
def setup
|
10
|
+
@log = ""
|
11
|
+
@logger = Logger.new(StringIO.new(@log))
|
12
|
+
@worker_loop = NewRelic::Agent::WorkerLoop.new(@logger)
|
13
|
+
@test_start_time = Time.now
|
14
|
+
end
|
15
|
+
def test_add_task
|
16
|
+
@x = false
|
17
|
+
period = 1.0
|
18
|
+
@worker_loop.add_task(period) do
|
19
|
+
@x = true
|
20
|
+
end
|
21
|
+
|
22
|
+
assert !@x
|
23
|
+
@worker_loop.run_next_task
|
24
|
+
assert @x
|
25
|
+
check_test_timestamp period
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_add_tasks_with_different_periods
|
29
|
+
@last_executed = nil
|
30
|
+
|
31
|
+
period1 = 0.2
|
32
|
+
period2 = 0.35
|
33
|
+
|
34
|
+
@worker_loop.add_task(period1) do
|
35
|
+
@last_executed = 1
|
36
|
+
end
|
37
|
+
|
38
|
+
@worker_loop.add_task(period2) do
|
39
|
+
@last_executed = 2
|
40
|
+
end
|
41
|
+
|
42
|
+
@worker_loop.run_next_task
|
43
|
+
assert_equal @last_executed, 1 # 0.2 s
|
44
|
+
check_test_timestamp(0.2)
|
45
|
+
|
46
|
+
@worker_loop.run_next_task
|
47
|
+
assert_equal @last_executed, 2 # 0.35 s
|
48
|
+
check_test_timestamp(0.35)
|
49
|
+
|
50
|
+
@worker_loop.run_next_task
|
51
|
+
assert_equal @last_executed, 1 # 0.4 s
|
52
|
+
check_test_timestamp(0.4)
|
53
|
+
|
54
|
+
@worker_loop.run_next_task
|
55
|
+
assert_equal @last_executed, 1 # 0.6 s
|
56
|
+
check_test_timestamp(0.6)
|
57
|
+
|
58
|
+
@worker_loop.run_next_task
|
59
|
+
assert_equal @last_executed, 2 # 0.7 s
|
60
|
+
check_test_timestamp(0.7)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_task_error__standard
|
64
|
+
@worker_loop.add_task(0.2) do
|
65
|
+
raise "Standard Error Test"
|
66
|
+
end
|
67
|
+
# Should not throw
|
68
|
+
@logger.expects(:error).once
|
69
|
+
@logger.expects(:debug).never
|
70
|
+
@worker_loop.run_next_task
|
71
|
+
|
72
|
+
end
|
73
|
+
def test_task_error__runtime
|
74
|
+
@worker_loop.add_task(0.2) do
|
75
|
+
raise RuntimeError, "Runtime Error Test"
|
76
|
+
end
|
77
|
+
# Should not throw, but log at error level
|
78
|
+
# because it detects no agent listener inthe
|
79
|
+
# stack
|
80
|
+
@logger.expects(:error).once
|
81
|
+
@logger.expects(:debug).never
|
82
|
+
@worker_loop.run_next_task
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_task_error__server
|
86
|
+
@worker_loop.add_task(0.2) do
|
87
|
+
raise NewRelic::Agent::ServerError, "Runtime Error Test"
|
88
|
+
end
|
89
|
+
# Should not throw
|
90
|
+
@logger.expects(:error).never
|
91
|
+
@logger.expects(:debug).once
|
92
|
+
@worker_loop.run_next_task
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
def check_test_timestamp(expected)
|
97
|
+
ts = Time.now - @test_start_time
|
98
|
+
delta = (expected - ts).abs
|
99
|
+
assert(delta < 0.05, "#{delta} exceeds 50 milliseconds")
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'/../test_helper'))
|
2
|
+
|
3
|
+
|
4
|
+
module NewRelic
|
5
|
+
class Config
|
6
|
+
public :log_file_name
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class NewRelic::ConfigTests < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def test_rails_config
|
13
|
+
c = NewRelic::Config.instance
|
14
|
+
assert_equal :rails, c.app
|
15
|
+
assert_equal false, c['enabled']
|
16
|
+
c.local_env
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_config_yaml_erb
|
20
|
+
c = NewRelic::Config.instance
|
21
|
+
assert_equal 'heyheyhey', c['erb_value']
|
22
|
+
assert_equal '', c['message']
|
23
|
+
assert_equal '', c['license_key']
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_log_file_name
|
27
|
+
c = NewRelic::Config.instance
|
28
|
+
|
29
|
+
assert_equal "newrelic_agent.3000.log", c.log_file_name("3000")
|
30
|
+
assert_equal "newrelic_agent.passenger_redmine-0.7.log", c.log_file_name("passenger:redmine-0.7")
|
31
|
+
assert_equal "newrelic_agent._tmp_test_1.log", c.log_file_name("/tmp/test/1")
|
32
|
+
assert_equal "newrelic_agent.c__foo_bar_long_gone__yes_.log", c.log_file_name("c:/foo/bar long gone?/yes!")
|
33
|
+
assert_equal "newrelic_agent..._tmp_pipes.log", c.log_file_name("..\\tmp\\pipes")
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|