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,6 +1,6 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'/../test_helper'))
2
2
  # TODO
3
- class NewRelic::ShimAgentTests < Test::Unit::TestCase
3
+ class NewRelic::ShimAgentTest < Test::Unit::TestCase
4
4
 
5
5
  def test_shim
6
6
  end
@@ -0,0 +1,291 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
2
+ ##require "new_relic/stats"
3
+
4
+ module NewRelic; class TestObjectForStats
5
+ include Stats
6
+ attr_accessor :total_call_time
7
+ attr_accessor :total_exclusive_time
8
+ attr_accessor :begin_time
9
+ attr_accessor :end_time
10
+ attr_accessor :call_count
11
+ end; end
12
+
13
+
14
+ class NewRelic::StatsTest < Test::Unit::TestCase
15
+
16
+ def test_simple
17
+ stats = NewRelic::MethodTraceStats.new
18
+ validate stats, 0, 0, 0, 0
19
+
20
+ assert_equal stats.call_count,0
21
+ stats.trace_call 10
22
+ stats.trace_call 20
23
+ stats.trace_call 30
24
+
25
+ validate stats, 3, (10+20+30), 10, 30
26
+ end
27
+
28
+ def test_to_s
29
+ s1 = NewRelic::MethodTraceStats.new
30
+ s1.trace_call 10
31
+ assert_equal(s1.to_s, "Begin=0.0, Duration=0.0 s, Count=1, Total=10000, Total Exclusive=10000, Avg=10000, Min=10000, Max=10000, StdDev=0")
32
+ end
33
+
34
+ def test_time_str
35
+ s1 = NewRelic::MethodTraceStats.new
36
+ assert_equal(s1.time_str(10), "10 ms")
37
+ assert_equal(s1.time_str(4999), "4999 ms")
38
+ assert_equal(s1.time_str(5000), "5.00 s")
39
+ assert_equal(s1.time_str(5010), "5.01 s")
40
+ assert_equal(s1.time_str(9999), "10.00 s")
41
+ assert_equal(s1.time_str(10000), "10.0 s")
42
+ assert_equal(s1.time_str(20000), "20.0 s")
43
+ end
44
+
45
+ def test_fraction_of
46
+ s1 = NewRelic::MethodTraceStats.new
47
+ s2 = NewRelic::MethodTraceStats.new
48
+ s1.trace_call 10
49
+ s2.trace_call 20
50
+ assert_equal(s1.fraction_of(s2).to_s, 'NaN')
51
+ end
52
+
53
+ def test_fraction_of2
54
+ s1 = NewRelic::MethodTraceStats.new
55
+ s1.trace_call 10
56
+ s2 = NewRelic::MethodTraceStats.new
57
+ assert_equal(s1.fraction_of(s2).to_s, 'NaN')
58
+ end
59
+
60
+ def test_multiply_by
61
+ s1 = NewRelic::MethodTraceStats.new
62
+ s1.trace_call 10
63
+ assert_equal(s1.multiply_by(10).to_s, "Begin=0.0, Duration=0.0 s, Count=10, Total=100000, Total Exclusive=10000, Avg=10000, Min=10000, Max=10000, StdDev=0")
64
+ end
65
+
66
+ def test_get_apdex
67
+ s1 = NewRelic::MethodTraceStats.new
68
+ s1.trace_call 10
69
+ assert_equal(s1.get_apdex, [1, 10, 10])
70
+ end
71
+
72
+ def test_apdex_score
73
+ s1 = NewRelic::MethodTraceStats.new
74
+ s1.trace_call 10
75
+ # FIXME make this test the real logic
76
+ # don't ask me what this means, but it's what's coming out the
77
+ # other end when I actually run it.
78
+ assert_in_delta(s1.apdex_score, 0.285714285714286, 0.0000001)
79
+ end
80
+
81
+ def test_as_percentage
82
+ s1 = NewRelic::MethodTraceStats.new
83
+ s1.trace_call 10
84
+ assert_equal(s1.as_percentage, 1000.0)
85
+ end
86
+
87
+ def test_calls_per_minute
88
+
89
+ s1 = NewRelic::TestObjectForStats.new
90
+ s1.call_count = 1
91
+ s1.begin_time = Time.at(0)
92
+ s1.end_time = Time.at(30)
93
+ assert_equal(s1.calls_per_minute, 2)
94
+ end
95
+
96
+ def test_calls_per_second
97
+ s1 = NewRelic::TestObjectForStats.new
98
+ s1.call_count = 90
99
+ s1.begin_time = Time.at(0)
100
+ s1.end_time = Time.at(30)
101
+ assert_equal(s1.calls_per_second, 3)
102
+ end
103
+
104
+ def test_total_call_time_per_minute
105
+ s1 = NewRelic::TestObjectForStats.new
106
+ s1.begin_time = Time.at(0)
107
+ s1.end_time = Time.at(0)
108
+ assert_equal(0, s1.total_call_time_per_minute)
109
+ s1.begin_time = Time.at(0)
110
+ s1.end_time = Time.at(30)
111
+ s1.total_call_time = 10
112
+ assert_equal(20, s1.total_call_time_per_minute)
113
+ end
114
+
115
+ def test_time_percentage
116
+ s1 = NewRelic::TestObjectForStats.new
117
+ s1.begin_time = Time.at(0)
118
+ s1.end_time = Time.at(0)
119
+ assert_equal(0, s1.time_percentage)
120
+ s1.total_call_time = 10
121
+ s1.begin_time = Time.at(0)
122
+ s1.end_time = Time.at(30)
123
+ assert_equal((1.0 / 3.0), s1.time_percentage)
124
+ s1.total_call_time = 20
125
+ assert_equal((2.0 / 3.0), s1.time_percentage)
126
+ end
127
+
128
+ def test_exclusive_time_percentage
129
+ s1 = NewRelic::TestObjectForStats.new
130
+ s1.begin_time = Time.at(0)
131
+ s1.end_time = Time.at(0)
132
+ assert_equal(0, s1.exclusive_time_percentage)
133
+ s1.total_exclusive_time = 10
134
+ s1.begin_time = Time.at(0)
135
+ s1.end_time = Time.at(30)
136
+ assert_equal((1.0 / 3.0), s1.exclusive_time_percentage)
137
+ s1.total_exclusive_time = 20
138
+ assert_equal((2.0 / 3.0), s1.exclusive_time_percentage)
139
+ end
140
+
141
+ def test_merge
142
+ s1 = NewRelic::MethodTraceStats.new
143
+ s2 = NewRelic::MethodTraceStats.new
144
+
145
+ s1.trace_call 10
146
+ s2.trace_call 20
147
+ s2.freeze
148
+
149
+ validate s2, 1, 20, 20, 20
150
+ s3 = s1.merge s2
151
+ validate s3, 2, (10+20), 10, 20
152
+ validate s1, 1, 10, 10, 10
153
+ validate s2, 1, 20, 20, 20
154
+
155
+ s1.merge! s2
156
+ validate s1, 2, (10+20), 10, 20
157
+ validate s2, 1, 20, 20, 20
158
+ end
159
+
160
+ def test_merge_with_exclusive
161
+ s1 = NewRelic::MethodTraceStats.new
162
+
163
+ s2 = NewRelic::MethodTraceStats.new
164
+
165
+ s1.trace_call 10, 5
166
+ s2.trace_call 20, 10
167
+ s2.freeze
168
+
169
+ validate s2, 1, 20, 20, 20, 10
170
+ s3 = s1.merge s2
171
+ validate s3, 2, (10+20), 10, 20, (10+5)
172
+ validate s1, 1, 10, 10, 10, 5
173
+ validate s2, 1, 20, 20, 20, 10
174
+
175
+ s1.merge! s2
176
+ validate s1, 2, (10+20), 10, 20, (5+10)
177
+ validate s2, 1, 20, 20, 20, 10
178
+ end
179
+
180
+ def test_merge_array
181
+ s1 = NewRelic::MethodTraceStats.new
182
+ merges = []
183
+ merges << (NewRelic::MethodTraceStats.new.trace_call 1)
184
+ merges << (NewRelic::MethodTraceStats.new.trace_call 1)
185
+ merges << (NewRelic::MethodTraceStats.new.trace_call 1)
186
+
187
+ s1.merge! merges
188
+ validate s1, 3, 3, 1, 1
189
+ end
190
+ def test_round
191
+ stats = NewRelic::MethodTraceStats.new
192
+ stats.record_data_point(0.125222, 0.025)
193
+ stats.record_data_point(0.125222, 0.025)
194
+ stats.record_data_point(0.125222, 0.025)
195
+ assert_equal 0.047041647852, stats.sum_of_squares
196
+ assert_equal 0.375666, stats.total_call_time
197
+ stats.round!
198
+ assert_equal 0.376, stats.total_call_time
199
+ assert_equal 0.047, stats.sum_of_squares
200
+
201
+ end
202
+
203
+ def test_freeze
204
+ s1 = NewRelic::MethodTraceStats.new
205
+
206
+ s1.trace_call 10
207
+ s1.freeze
208
+
209
+ begin
210
+ # the following should throw an exception because s1 is frozen
211
+ s1.trace_call 20
212
+ assert false
213
+ rescue StandardError
214
+ assert s1.frozen?
215
+ validate s1, 1, 10, 10, 10
216
+ end
217
+ end
218
+
219
+ def test_std_dev
220
+ s = NewRelic::MethodTraceStats.new
221
+ s.trace_call 1
222
+ assert s.standard_deviation == 0
223
+
224
+ s = NewRelic::MethodTraceStats.new
225
+ s.trace_call 10
226
+ s.trace_call 10
227
+ s.sum_of_squares = nil
228
+ assert s.standard_deviation == 0
229
+
230
+ s = NewRelic::MethodTraceStats.new
231
+ s.trace_call 0.001
232
+ s.trace_call 0.001
233
+ assert s.standard_deviation == 0
234
+
235
+
236
+ s = NewRelic::MethodTraceStats.new
237
+ s.trace_call 10
238
+ s.trace_call 10
239
+ s.trace_call 10
240
+ s.trace_call 10
241
+ s.trace_call 10
242
+ s.trace_call 10
243
+ assert s.standard_deviation == 0
244
+
245
+ s = NewRelic::MethodTraceStats.new
246
+ s.trace_call 4
247
+ s.trace_call 7
248
+ s.trace_call 13
249
+ s.trace_call 16
250
+ s.trace_call 8
251
+ s.trace_call 4
252
+ assert_equal(s.sum_of_squares, 4**2 + 7**2 + 13**2 + 16**2 + 8**2 + 4**2)
253
+
254
+ s.trace_call 9
255
+ s.trace_call 3
256
+ s.trace_call 1000
257
+ s.trace_call 4
258
+
259
+ # calculated stdev (population, not sample) from a spreadsheet.
260
+ assert_in_delta(s.standard_deviation, 297.76, 0.01)
261
+ end
262
+
263
+ def test_std_dev_merge
264
+ s1 = NewRelic::MethodTraceStats.new
265
+ s1.trace_call 4
266
+ s1.trace_call 7
267
+
268
+ s2 = NewRelic::MethodTraceStats.new
269
+ s2.trace_call 13
270
+ s2.trace_call 16
271
+
272
+ s3 = s1.merge(s2)
273
+
274
+ assert(s1.sum_of_squares, 4*4 + 7*7)
275
+ assert_in_delta(s1.standard_deviation, 1.5, 0.01)
276
+
277
+ assert_in_delta(s2.standard_deviation, 1.5, 0.01)
278
+ assert_equal(s3.sum_of_squares, 4*4 + 7*7 + 13*13 + 16*16, "check sum of squares")
279
+ assert_in_delta(s3.standard_deviation, 4.743, 0.01)
280
+ end
281
+
282
+ private
283
+ def validate (stats, count, total, min, max, exclusive = nil)
284
+ assert_equal stats.call_count, count
285
+ assert_equal stats.total_call_time, total
286
+ assert_equal stats.average_call_time, (count > 0 ? total / count : 0)
287
+ assert_equal stats.min_call_time, min
288
+ assert_equal stats.max_call_time, max
289
+ assert_equal stats.total_exclusive_time, exclusive if exclusive
290
+ end
291
+ end
@@ -0,0 +1,46 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
2
+ class NewRelic::VersionNumberTest < Test::Unit::TestCase
3
+
4
+ def test_comparison__first
5
+ versions = %w[1.0.0 0.1.0 0.0.1 10.0.1 1.10.0].map {|s| NewRelic::VersionNumber.new s }
6
+ assert_equal %w[0.0.1 0.1.0 1.0.0 1.10.0 10.0.1], versions.sort.map(&:to_s)
7
+ v0 = NewRelic::VersionNumber.new '1.2.3'
8
+ v1 = NewRelic::VersionNumber.new '1.2.2'
9
+ v3 = NewRelic::VersionNumber.new '1.2.2'
10
+ assert v0 > v1
11
+ assert v1 == v1
12
+ assert v1 == v3
13
+ end
14
+ def test_comparison__second
15
+ v0 = NewRelic::VersionNumber.new '1.2.0'
16
+ v1 = NewRelic::VersionNumber.new '2.2.2'
17
+ v3 = NewRelic::VersionNumber.new '1.1.2'
18
+ assert v0 < v1
19
+ assert v1 > v3
20
+ assert v3 < v0
21
+ end
22
+ def test_long_version
23
+ v0 = NewRelic::VersionNumber.new '1.2.3.4'
24
+ v1 = NewRelic::VersionNumber.new '1.2.3.3'
25
+ v3 = NewRelic::VersionNumber.new '1.3'
26
+ assert v0 > v1
27
+ assert v3 > v0
28
+ end
29
+ def test_sort
30
+ values = %w[1.1.1 2.6.5 2.7 2.7.1]
31
+ assert_equal values, values.map{|v| NewRelic::VersionNumber.new v}.sort.map(&:to_s)
32
+ end
33
+ def test_compare_string
34
+ v0 = NewRelic::VersionNumber.new '1.2.0'
35
+ v1 = NewRelic::VersionNumber.new '2.2.2'
36
+ v3 = NewRelic::VersionNumber.new '1.1.2'
37
+ assert v0 < '2.2.2'
38
+ assert v1 > '1.1.2'
39
+ assert v3 < '1.2.0'
40
+ assert v0 == '1.2.0'
41
+ end
42
+ def test_string
43
+ assert_equal '1.2.0', NewRelic::VersionNumber.new('1.2.0').to_s
44
+ assert_equal '1.2', NewRelic::VersionNumber.new('1.2').to_s
45
+ end
46
+ end
data/test/test_helper.rb CHANGED
@@ -1,40 +1,17 @@
1
1
  module NewRelic; TEST = true; end unless defined? NewRelic::TEST
2
- NEWRELIC_PLUGIN_DIR = File.expand_path(File.dirname(__FILE__)+"/..")
2
+
3
+ NEWRELIC_PLUGIN_DIR = File.expand_path(File.join(File.dirname(__FILE__),".."))
3
4
  $LOAD_PATH << File.join(NEWRELIC_PLUGIN_DIR,"test")
5
+ $LOAD_PATH << File.join(NEWRELIC_PLUGIN_DIR,"ui/helpers")
4
6
  $LOAD_PATH.uniq!
5
7
 
6
- require File.expand_path(File.dirname(__FILE__) + "/../../../../config/environment")
8
+ require File.expand_path(File.join(NEWRELIC_PLUGIN_DIR, "..","..","..","config","environment"))
7
9
 
8
10
  require 'test_help'
9
11
  require 'mocha'
10
12
  require 'test/unit'
11
13
 
12
- module NewRelic
13
- class Config
14
- def setup_log_with_block_logging(*args)
15
- silence_stream(::STDERR) { self.setup_log_without_block_logging(*args) }
16
- end
17
- alias_method_chain :setup_log, :block_logging rescue nil
18
- end
19
- end
20
-
21
- =begin
22
- # This is a mixin for hacking the select method
23
- if defined? ActiveRecord::ConnectionAdapters
24
- class ActiveRecord::ConnectionAdapters::MysqlAdapter
25
-
26
- def log_info_with_slowdown(sql, name, seconds)
27
- log_info_without_slowdown(sql, name, seconds)
28
- sleep 0.1
29
- end
30
-
31
- def setup_slow
32
- self.class.alias_method_chain :log_info, :slowdown
33
- end
34
-
35
- def teardown_slow
36
- alias :log_info :log_info_without_slowdown
37
- end
38
- end
14
+ def assert_between(floor, ceiling, value, message = nil)
15
+ assert floor <= value && value <= ceiling,
16
+ message || "expected #{floor} <= #{value} <= #{ceiling}"
39
17
  end
40
- =end
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
2
+ require 'newrelic_helper'
3
+ require 'active_record_fixtures'
4
+
5
+ class NewRelic::Agent::NewrelicControllerTest < Test::Unit::TestCase
6
+
7
+ # Clearly we need a functional test for the controller. For now
8
+ # I want to at least make sure the class loads in all versions of rails.
9
+ def test_controller_loading
10
+ NewrelicController
11
+ rescue
12
+ fail "Controller would not load:#{$!}"
13
+ end
14
+ end
@@ -1,16 +1,22 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
2
2
  require 'newrelic_helper'
3
- require 'new_relic/agent/model_fixture'
3
+ require 'active_record_fixtures'
4
4
 
5
- class NewRelic::Agent::NewrelicHelperTests < Test::Unit::TestCase
5
+ class NewRelic::Agent::NewrelicHelperTest < Test::Unit::TestCase
6
6
  include NewrelicHelper
7
+
8
+ def params
9
+ {}
10
+ end
11
+
7
12
  def setup
8
13
  super
9
- NewRelic::Agent::ModelFixture.setup
14
+ ActiveRecordFixtures.setup
15
+ # setup instrumentation
16
+ NewRelic::Agent.manual_start
17
+ # let's get a real stack trace
10
18
  begin
11
- # setup instrumentation
12
- NewRelic::Agent.instance.start :test, :test
13
- NewRelic::Agent::ModelFixture.find 0
19
+ ActiveRecordFixtures::Order.find 0
14
20
  rescue => e
15
21
  @exception = e
16
22
  return
@@ -18,7 +24,7 @@ class NewRelic::Agent::NewrelicHelperTests < Test::Unit::TestCase
18
24
  flunk "should throw"
19
25
  end
20
26
  def teardown
21
- NewRelic::Agent::ModelFixture.teardown
27
+ ActiveRecordFixtures.teardown
22
28
  NewRelic::Agent.instance.shutdown
23
29
  super
24
30
  end
@@ -32,6 +38,9 @@ class NewRelic::Agent::NewrelicHelperTests < Test::Unit::TestCase
32
38
  def test_application_stack_trace__no_rails
33
39
  assert_clean(application_stack_trace(@exception.backtrace, false), false)
34
40
  end
41
+ def test_with_delimiter
42
+ assert_equal "123,456.123456", with_delimiter(123456.123456)
43
+ end
35
44
 
36
45
  private
37
46
  def assert_clean(backtrace, rails=false)