newrelic_rpm 2.8.11 → 2.9.2

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.

Files changed (137) hide show
  1. data/CHANGELOG +267 -0
  2. data/LICENSE +1 -1
  3. data/Manifest +142 -0
  4. data/README.md +138 -0
  5. data/Rakefile +10 -28
  6. data/bin/mongrel_rpm +33 -0
  7. data/cert/cacert.pem +34 -0
  8. data/init.rb +38 -0
  9. data/lib/new_relic/agent/agent.rb +160 -347
  10. data/lib/new_relic/agent/collection_helper.rb +13 -24
  11. data/lib/new_relic/agent/error_collector.rb +29 -15
  12. data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +63 -76
  13. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +90 -48
  14. data/lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb +72 -47
  15. data/lib/new_relic/agent/instrumentation/error_instrumentation.rb +14 -0
  16. data/lib/new_relic/agent/instrumentation/merb/controller.rb +10 -1
  17. data/lib/new_relic/agent/instrumentation/merb/dispatcher.rb +5 -7
  18. data/lib/new_relic/agent/instrumentation/merb/errors.rb +3 -1
  19. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +7 -0
  20. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +34 -7
  21. data/lib/new_relic/agent/instrumentation/rails/dispatcher.rb +20 -12
  22. data/lib/new_relic/agent/instrumentation/rails/errors.rb +5 -4
  23. data/lib/new_relic/agent/method_tracer.rb +159 -135
  24. data/lib/new_relic/agent/patch_const_missing.rb +46 -26
  25. data/lib/new_relic/agent/sampler.rb +12 -0
  26. data/lib/new_relic/agent/samplers/cpu_sampler.rb +44 -0
  27. data/lib/new_relic/agent/samplers/memory_sampler.rb +126 -0
  28. data/lib/new_relic/agent/samplers/mongrel_sampler.rb +22 -0
  29. data/lib/new_relic/agent/shim_agent.rb +11 -0
  30. data/lib/new_relic/agent/stats_engine.rb +85 -46
  31. data/lib/new_relic/agent/transaction_sampler.rb +63 -38
  32. data/lib/new_relic/agent/worker_loop.rb +8 -18
  33. data/lib/new_relic/agent.rb +200 -25
  34. data/lib/new_relic/commands/deployments.rb +9 -9
  35. data/lib/new_relic/control/merb.rb +22 -0
  36. data/lib/new_relic/control/rails.rb +141 -0
  37. data/lib/new_relic/{config → control}/ruby.rb +13 -2
  38. data/lib/new_relic/control.rb +424 -0
  39. data/lib/new_relic/local_environment.rb +201 -79
  40. data/lib/new_relic/metric_data.rb +7 -0
  41. data/lib/new_relic/metric_parser/action_mailer.rb +9 -0
  42. data/lib/new_relic/metric_parser/active_merchant.rb +26 -0
  43. data/lib/new_relic/metric_parser/active_record.rb +11 -0
  44. data/lib/new_relic/metric_parser/controller.rb +51 -0
  45. data/lib/new_relic/metric_parser/controller_cpu.rb +38 -0
  46. data/lib/new_relic/metric_parser/database.rb +23 -0
  47. data/lib/new_relic/metric_parser/errors.rb +6 -0
  48. data/lib/new_relic/metric_parser/mem_cache.rb +12 -0
  49. data/lib/new_relic/metric_parser/view.rb +61 -0
  50. data/lib/new_relic/metric_parser/web_service.rb +9 -0
  51. data/lib/new_relic/metric_parser.rb +107 -0
  52. data/lib/new_relic/metric_spec.rb +5 -0
  53. data/lib/new_relic/noticed_error.rb +5 -1
  54. data/lib/new_relic/rack/metric_app.rb +57 -0
  55. data/lib/new_relic/rack/newrelic.ru +25 -0
  56. data/lib/new_relic/rack/newrelic.yml +25 -0
  57. data/lib/new_relic/rack.rb +5 -0
  58. data/lib/new_relic/recipes.rb +10 -3
  59. data/lib/new_relic/stats.rb +130 -144
  60. data/lib/new_relic/transaction_analysis.rb +7 -8
  61. data/lib/new_relic/transaction_sample.rb +86 -10
  62. data/lib/new_relic/version.rb +41 -160
  63. data/lib/new_relic_api.rb +7 -6
  64. data/lib/newrelic_rpm.rb +30 -17
  65. data/lib/tasks/{agent_tests.rake → tests.rake} +1 -1
  66. data/newrelic.yml +115 -62
  67. data/newrelic_rpm.gemspec +36 -0
  68. data/test/active_record_fixtures.rb +55 -0
  69. data/test/config/newrelic.yml +21 -3
  70. data/test/config/{test_config.rb → test_control.rb} +14 -10
  71. data/test/new_relic/agent/active_record_instrumentation_test.rb +189 -0
  72. data/test/new_relic/agent/agent_test.rb +104 -0
  73. data/test/new_relic/agent/agent_test_controller.rb +18 -1
  74. data/test/new_relic/agent/classloader_patch_test.rb +56 -0
  75. data/test/new_relic/agent/{tc_collection_helper.rb → collection_helper_test.rb} +28 -23
  76. data/test/new_relic/agent/controller_test.rb +107 -0
  77. data/test/new_relic/agent/dispatcher_instrumentation_test.rb +70 -0
  78. data/test/new_relic/agent/error_collector_test.rb +155 -0
  79. data/test/new_relic/agent/{tc_method_tracer.rb → method_tracer_test.rb} +6 -12
  80. data/test/new_relic/agent/metric_data_test.rb +56 -0
  81. data/test/new_relic/agent/stats_engine_test.rb +266 -0
  82. data/test/new_relic/agent/{tc_transaction_sample_builder.rb → transaction_sample_builder_test.rb} +6 -5
  83. data/test/new_relic/agent/{tc_transaction_sample.rb → transaction_sample_test.rb} +9 -13
  84. data/test/new_relic/agent/transaction_sampler_test.rb +317 -0
  85. data/test/new_relic/agent/{tc_worker_loop.rb → worker_loop_test.rb} +1 -1
  86. data/test/new_relic/control_test.rb +97 -0
  87. data/test/new_relic/{tc_deployments_api.rb → deployments_api_test.rb} +8 -4
  88. data/test/new_relic/environment_test.rb +75 -0
  89. data/test/new_relic/metric_parser_test.rb +142 -0
  90. data/test/new_relic/{tc_metric_spec.rb → metric_spec_test.rb} +28 -1
  91. data/test/new_relic/samplers_test.rb +71 -0
  92. data/test/new_relic/{tc_shim_agent.rb → shim_agent_test.rb} +1 -1
  93. data/test/new_relic/stats_test.rb +291 -0
  94. data/test/new_relic/version_number_test.rb +46 -0
  95. data/test/test_helper.rb +7 -30
  96. data/test/ui/newrelic_controller_test.rb +14 -0
  97. data/test/ui/{tc_newrelic_helper.rb → newrelic_helper_test.rb} +16 -7
  98. data/ui/controllers/newrelic_controller.rb +17 -3
  99. data/ui/helpers/newrelic_helper.rb +44 -15
  100. data/ui/views/layouts/newrelic_default.rhtml +7 -8
  101. data/ui/views/newrelic/_sample.rhtml +5 -2
  102. data/ui/views/newrelic/_segment.rhtml +1 -1
  103. data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
  104. data/ui/views/newrelic/_segment_row.rhtml +4 -4
  105. data/ui/views/newrelic/_show_sample_detail.rhtml +3 -1
  106. data/ui/views/newrelic/_show_sample_sql.rhtml +2 -1
  107. data/ui/views/newrelic/explain_sql.rhtml +2 -5
  108. data/ui/views/newrelic/images/file_icon.png +0 -0
  109. data/ui/views/newrelic/images/new_relic_rpm_desktop.gif +0 -0
  110. data/ui/views/newrelic/index.rhtml +21 -13
  111. data/ui/views/newrelic/javascript/prototype-scriptaculous.js +7288 -0
  112. data/ui/views/newrelic/show_sample.rhtml +18 -3
  113. data/ui/views/newrelic/stylesheets/style.css +39 -0
  114. data/ui/views/newrelic/threads.rhtml +52 -0
  115. metadata +192 -70
  116. data/README +0 -136
  117. data/lib/new_relic/agent/instrumentation/rails/rails.rb +0 -6
  118. data/lib/new_relic/agent/samplers/cpu.rb +0 -29
  119. data/lib/new_relic/agent/samplers/memory.rb +0 -53
  120. data/lib/new_relic/agent/samplers/mongrel.rb +0 -26
  121. data/lib/new_relic/agent/synchronize.rb +0 -40
  122. data/lib/new_relic/config/merb.rb +0 -35
  123. data/lib/new_relic/config/rails.rb +0 -114
  124. data/lib/new_relic/config.rb +0 -279
  125. data/lib/new_relic/shim_agent.rb +0 -96
  126. data/test/new_relic/agent/model_fixture.rb +0 -15
  127. data/test/new_relic/agent/tc_active_record.rb +0 -90
  128. data/test/new_relic/agent/tc_agent.rb +0 -148
  129. data/test/new_relic/agent/tc_controller.rb +0 -77
  130. data/test/new_relic/agent/tc_dispatcher_instrumentation.rb +0 -52
  131. data/test/new_relic/agent/tc_error_collector.rb +0 -127
  132. data/test/new_relic/agent/tc_stats_engine.rb +0 -218
  133. data/test/new_relic/agent/tc_synchronize.rb +0 -37
  134. data/test/new_relic/agent/tc_transaction_sampler.rb +0 -302
  135. data/test/new_relic/tc_config.rb +0 -36
  136. data/test/new_relic/tc_environment.rb +0 -94
  137. data/test/new_relic/tc_stats.rb +0 -141
@@ -1,37 +0,0 @@
1
- require 'test/unit'
2
- ##require 'new_relic/agent/testable_agent'
3
-
4
- class TestSync
5
- include NewRelic::Agent::Synchronize
6
- end
7
-
8
- class AgentSynchronizeTests < Test::Unit::TestCase
9
-
10
-
11
- def test_sync
12
- t = TestSync.new
13
-
14
- worked = false
15
- t.synchronize_sync do
16
- worked = true
17
- end
18
-
19
- assert worked
20
-
21
- worked = false
22
-
23
- t.synchronize_mutex do
24
- worked = true
25
- end
26
-
27
- assert worked
28
-
29
- worked = false
30
-
31
- t.synchronize_thread do
32
- worked = true
33
- end
34
-
35
- assert worked
36
- end
37
- end
@@ -1,302 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
-
3
- ::RPM_DEVELOPER = true unless defined? ::RPM_DEVELOPER
4
-
5
- NewRelic::Agent::TransactionSampler.send :public, :builder
6
-
7
- class NewRelic::Agent::TransationSamplerTests < Test::Unit::TestCase
8
-
9
- def setup
10
- Thread::current[:record_sql] = nil
11
- end
12
-
13
- def test_multiple_samples
14
- @sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
15
-
16
- run_sample_trace
17
- run_sample_trace
18
- run_sample_trace
19
- run_sample_trace
20
-
21
- samples = @sampler.get_samples
22
- assert_equal 4, samples.length
23
- assert_equal "a", samples.first.root_segment.called_segments[0].metric_name
24
- assert_equal "a", samples.last.root_segment.called_segments[0].metric_name
25
- end
26
-
27
-
28
- def test_harvest_slowest
29
- @sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
30
-
31
- run_sample_trace
32
- run_sample_trace
33
- run_sample_trace { sleep 0.5 }
34
- run_sample_trace
35
- run_sample_trace
36
-
37
- slowest = @sampler.harvest_slowest_sample(nil)
38
- assert slowest.duration >= 0.5
39
-
40
- run_sample_trace { sleep 0.2 }
41
- not_as_slow = @sampler.harvest_slowest_sample(slowest)
42
- assert not_as_slow == slowest
43
-
44
- run_sample_trace { sleep 0.6 }
45
- new_slowest = @sampler.harvest_slowest_sample(slowest)
46
- assert new_slowest != slowest
47
- assert new_slowest.duration >= 0.6
48
- end
49
-
50
-
51
- def test_preare_to_send
52
- @sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
53
-
54
- run_sample_trace { sleep 0.2 }
55
- sample = @sampler.harvest_slowest_sample(nil)
56
-
57
- ready_to_send = sample.prepare_to_send
58
- assert sample.duration == ready_to_send.duration
59
-
60
- assert ready_to_send.start_time.is_a?(Time)
61
- end
62
-
63
- def test_multithread
64
- @sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
65
- threads = []
66
-
67
- 20.times do
68
- t = Thread.new(@sampler) do |the_sampler|
69
- @sampler = the_sampler
70
- 100.times do
71
- run_sample_trace { sleep 0.01 }
72
- end
73
- end
74
-
75
- threads << t
76
- end
77
- threads.each {|t| t.join }
78
- end
79
-
80
- def test_sample_with_parallel_paths
81
- @sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
82
-
83
- assert_equal 0, @sampler.scope_depth
84
-
85
- @sampler.notice_first_scope_push Time.now.to_f
86
- @sampler.notice_transaction "/path", nil, {}
87
- @sampler.notice_push_scope "a"
88
-
89
- assert_equal 1, @sampler.scope_depth
90
-
91
- @sampler.notice_pop_scope "a"
92
- @sampler.notice_scope_empty
93
-
94
- assert_equal 0, @sampler.scope_depth
95
-
96
- @sampler.notice_first_scope_push Time.now.to_f
97
- @sampler.notice_transaction "/path", nil, {}
98
- @sampler.notice_push_scope "a"
99
- @sampler.notice_pop_scope "a"
100
- @sampler.notice_scope_empty
101
- end
102
-
103
- def test_double_scope_stack_empty
104
- @sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
105
-
106
- @sampler.notice_first_scope_push Time.now.to_f
107
- @sampler.notice_transaction "/path", nil, {}
108
- @sampler.notice_push_scope "a"
109
- @sampler.notice_pop_scope "a"
110
- @sampler.notice_scope_empty
111
- @sampler.notice_scope_empty
112
- @sampler.notice_scope_empty
113
- @sampler.notice_scope_empty
114
-
115
- assert_not_nil @sampler.harvest_slowest_sample(nil)
116
- end
117
-
118
-
119
- def test_record_sql_off
120
- sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
121
-
122
- sampler.notice_first_scope_push Time.now.to_f
123
-
124
- Thread::current[:record_sql] = false
125
-
126
- sampler.notice_sql("test", nil, 0)
127
-
128
- segment = sampler.builder.current_segment
129
-
130
- assert_nil segment[:sql]
131
- end
132
-
133
- def test_stack_trace__sql
134
- sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
135
-
136
- sampler.stack_trace_threshold = 0
137
-
138
- sampler.notice_first_scope_push Time.now.to_f
139
-
140
- sampler.notice_sql("test", nil, 1)
141
-
142
- segment = sampler.builder.current_segment
143
-
144
- assert segment[:sql]
145
- assert segment[:backtrace]
146
- end
147
- def test_stack_trace__scope
148
- sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
149
-
150
- sampler.stack_trace_threshold = 0
151
- t = Time.now
152
- sampler.notice_first_scope_push t.to_f
153
- sampler.notice_push_scope 'Bill', (t+1.second).to_f
154
-
155
- segment = sampler.builder.current_segment
156
- assert segment[:backtrace]
157
- end
158
-
159
- def test_nil_stacktrace
160
- sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
161
-
162
- sampler.stack_trace_threshold = 2
163
-
164
- sampler.notice_first_scope_push Time.now.to_f
165
-
166
- sampler.notice_sql("test", nil, 1)
167
-
168
- segment = sampler.builder.current_segment
169
-
170
- assert segment[:sql]
171
- assert_nil segment[:backtrace]
172
- end
173
-
174
- def test_big_sql
175
- @sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
176
-
177
- @sampler.notice_first_scope_push Time.now.to_f
178
-
179
- sql = "SADJKHASDHASD KAJSDH ASKDH ASKDHASDK JASHD KASJDH ASKDJHSAKDJHAS DKJHSADKJSAH DKJASHD SAKJDH SAKDJHS"
180
-
181
- len = 0
182
- while len <= NewRelic::Agent::TransactionSampler::MAX_SQL_LENGTH
183
- @sampler.notice_sql(sql, nil, 0)
184
- len += sql.length
185
- end
186
-
187
- segment = @sampler.builder.current_segment
188
-
189
- sql = segment[:sql]
190
-
191
- assert sql.length <= NewRelic::Agent::TransactionSampler::MAX_SQL_LENGTH
192
- end
193
-
194
-
195
- def test_segment_obfuscated
196
- @sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
197
-
198
- @sampler.notice_first_scope_push Time.now.to_f
199
-
200
- orig_sql = "SELECT * from Jim where id=66"
201
-
202
- @sampler.notice_sql(orig_sql, nil, 0)
203
-
204
- segment = @sampler.builder.current_segment
205
-
206
- assert_equal orig_sql, segment[:sql]
207
- assert_equal "SELECT * from Jim where id=?", segment.obfuscated_sql
208
- end
209
-
210
-
211
- def test_param_capture
212
- [true, false].each do |capture|
213
- t = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
214
-
215
- NewRelic::Agent::TransactionSampler.capture_params = capture
216
-
217
- t.notice_first_scope_push Time.now.to_f
218
- t.notice_transaction('/path', nil, {:param => 'hi'})
219
- t.notice_scope_empty
220
-
221
- tt = t.harvest_slowest_sample
222
-
223
- assert_equal (capture) ? 1 : 0, tt.params[:request_params].length
224
- end
225
- end
226
-
227
-
228
- def test_sql_normalization
229
- t = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
230
-
231
- # basic statement
232
- assert_equal "INSERT INTO X values(?,?, ? , ?)",
233
- t.default_sql_obfuscator("INSERT INTO X values('test',0, 1 , 2)")
234
-
235
- # escaped literals
236
- assert_equal "INSERT INTO X values(?, ?,?, ? , ?)",
237
- t.default_sql_obfuscator("INSERT INTO X values('', 'jim''s ssn',0, 1 , 'jim''s son''s son')")
238
-
239
- # multiple string literals
240
- assert_equal "INSERT INTO X values(?,?,?, ? , ?)",
241
- t.default_sql_obfuscator("INSERT INTO X values('jim''s ssn','x',0, 1 , 2)")
242
-
243
- # empty string literal
244
- # NOTE: the empty string literal resolves to empty string, which for our purposes is acceptable
245
- assert_equal "INSERT INTO X values(?,?,?, ? , ?)",
246
- t.default_sql_obfuscator("INSERT INTO X values('','x',0, 1 , 2)")
247
-
248
- # try a select statement
249
- assert_equal "select * from table where name=? and ssn=?",
250
- t.default_sql_obfuscator("select * from table where name='jim gochee' and ssn=0012211223")
251
-
252
- # number literals embedded in sql - oh well
253
- assert_equal "select * from table_? where name=? and ssn=?",
254
- t.default_sql_obfuscator("select * from table_007 where name='jim gochee' and ssn=0012211223")
255
- end
256
-
257
- def test_sql_obfuscation_filters
258
- orig = NewRelic::Agent.agent.obfuscator
259
-
260
- NewRelic::Agent.set_sql_obfuscator(:replace) do |sql|
261
- sql = "1" + sql
262
- end
263
-
264
- sql = "SELECT * FROM TABLE 123 'jim'"
265
-
266
- assert_equal "1" + sql, NewRelic::Agent.instance.obfuscator.call(sql)
267
-
268
- NewRelic::Agent.set_sql_obfuscator(:before) do |sql|
269
- sql = "2" + sql
270
- end
271
-
272
- assert_equal "12" + sql, NewRelic::Agent.instance.obfuscator.call(sql)
273
-
274
- NewRelic::Agent.set_sql_obfuscator(:after) do |sql|
275
- sql = sql + "3"
276
- end
277
-
278
- assert_equal "12" + sql + "3", NewRelic::Agent.instance.obfuscator.call(sql)
279
-
280
- NewRelic::Agent.agent.set_sql_obfuscator(:replace, &orig)
281
- end
282
-
283
-
284
- private
285
- def run_sample_trace(&proc)
286
- @sampler.notice_first_scope_push Time.now.to_f
287
- @sampler.notice_transaction '/path', nil, {}
288
- @sampler.notice_push_scope "a"
289
- @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'wheat'", nil, 0)
290
- @sampler.notice_push_scope "ab"
291
- @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'white'", nil, 0)
292
- proc.call if proc
293
- @sampler.notice_pop_scope "ab"
294
- @sampler.notice_push_scope "lew"
295
- @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'french'", nil, 0)
296
- @sampler.notice_pop_scope "lew"
297
- @sampler.notice_pop_scope "a"
298
- @sampler.notice_scope_empty
299
- end
300
-
301
- end
302
-
@@ -1,36 +0,0 @@
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
@@ -1,94 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
2
- require "test/unit"
3
- require "mocha"
4
- ##require 'new_relic/local_environment'
5
- class EnvironmentTest < ActiveSupport::TestCase
6
-
7
- def teardown
8
- # To remove mock server instances from ObjectSpace
9
- ObjectSpace.garbage_collect
10
- super
11
- end
12
- class MockOptions
13
- def fetch (*args)
14
- 1000
15
- end
16
- end
17
- MOCK_OPTIONS = MockOptions.new
18
-
19
- def test_environment
20
- e = NewRelic::LocalEnvironment.new
21
- assert_equal :unknown, e.environment
22
- assert_nil e.identifier
23
- end
24
- def test_webrick
25
- Object.const_set :OPTIONS, { :port => 3000 }
26
- e = NewRelic::LocalEnvironment.new
27
- assert_equal :webrick, e.environment
28
- assert_equal 3000, e.identifier
29
- Object.class_eval { remove_const :OPTIONS }
30
- end
31
- def test_no_webrick
32
- Object.const_set :OPTIONS, 'foo'
33
- e = NewRelic::LocalEnvironment.new
34
- assert_equal :unknown, e.environment
35
- assert_nil e.identifier
36
- Object.class_eval { remove_const :OPTIONS }
37
- end
38
- def test_mongrel
39
-
40
- class << self
41
- module ::Mongrel
42
- class HttpServer
43
- def port; 3000; end
44
- end
45
- end
46
- end
47
- Mongrel::HttpServer.new
48
- e = NewRelic::LocalEnvironment.new
49
- assert_equal :mongrel, e.environment
50
- assert_equal 3000, e.identifier
51
- Mongrel::HttpServer.class_eval {undef_method :port}
52
- end
53
- def test_thin
54
- class << self
55
- module ::Thin
56
- class Server
57
- def backend; self; end
58
- def socket; "/socket/file.000"; end
59
- end
60
- end
61
- end
62
- mock_thin = Thin::Server.new
63
- e = NewRelic::LocalEnvironment.new
64
- assert_equal :thin, e.environment
65
- assert_equal '/socket/file.000', e.identifier
66
- mock_thin
67
- end
68
- def test_litespeed
69
- e = NewRelic::LocalEnvironment.new
70
- assert_equal :unknown, e.environment
71
- assert_nil e.identifier
72
- end
73
- def test_passenger
74
- class << self
75
- module ::Passenger
76
- const_set "AbstractServer", 0
77
- end
78
- end
79
- e = NewRelic::LocalEnvironment.new
80
- assert_equal :passenger, e.environment
81
- assert_equal 'passenger', e.identifier
82
-
83
- NewRelic::Config.instance.instance_eval do
84
- @settings['app_name'] = 'myapp'
85
- end
86
-
87
- e = NewRelic::LocalEnvironment.new
88
- assert_equal :passenger, e.environment
89
- assert_equal 'passenger:myapp', e.identifier
90
-
91
- ::Passenger.class_eval { remove_const :AbstractServer }
92
- end
93
-
94
- end