newrelic_rpm 3.5.2.17 → 3.5.3.24

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 (134) hide show
  1. data/.travis.yml +3 -1
  2. data/CHANGELOG +39 -23
  3. data/GUIDELINES_FOR_CONTRIBUTING.md +23 -2
  4. data/Rakefile +32 -0
  5. data/lib/new_relic/agent.rb +1 -0
  6. data/lib/new_relic/agent/agent.rb +45 -6
  7. data/lib/new_relic/agent/browser_monitoring.rb +36 -20
  8. data/lib/new_relic/agent/busy_calculator.rb +12 -4
  9. data/lib/new_relic/agent/configuration/defaults.rb +6 -1
  10. data/lib/new_relic/agent/configuration/environment_source.rb +14 -0
  11. data/lib/new_relic/agent/instrumentation/sinatra.rb +14 -10
  12. data/lib/new_relic/agent/new_relic_service.rb +192 -34
  13. data/lib/new_relic/agent/pipe_channel_manager.rb +1 -2
  14. data/lib/new_relic/agent/pipe_service.rb +5 -1
  15. data/lib/new_relic/agent/samplers/memory_sampler.rb +1 -1
  16. data/lib/new_relic/agent/sql_sampler.rb +29 -10
  17. data/lib/new_relic/agent/stats_engine/metric_stats.rb +40 -0
  18. data/lib/new_relic/agent/stats_engine/samplers.rb +1 -2
  19. data/lib/new_relic/agent/thread.rb +27 -0
  20. data/lib/new_relic/agent/thread_profiler.rb +295 -0
  21. data/lib/new_relic/agent/worker_loop.rb +29 -15
  22. data/lib/new_relic/control/frameworks/rails.rb +4 -4
  23. data/lib/new_relic/control/frameworks/rails3.rb +1 -1
  24. data/lib/new_relic/helper.rb +3 -0
  25. data/lib/new_relic/metric_data.rb +10 -2
  26. data/lib/new_relic/noticed_error.rb +5 -0
  27. data/lib/new_relic/transaction_sample.rb +23 -13
  28. data/lib/new_relic/transaction_sample/segment.rb +13 -15
  29. data/lib/new_relic/version.rb +1 -1
  30. data/lib/tasks/tests.rake +5 -11
  31. data/test/multiverse/.gitignore +10 -0
  32. data/test/multiverse/README.md +90 -0
  33. data/test/multiverse/Rakefile +17 -0
  34. data/test/multiverse/lib/multiverse/color.rb +13 -0
  35. data/test/multiverse/lib/multiverse/envfile.rb +66 -0
  36. data/test/multiverse/lib/multiverse/environment.rb +16 -0
  37. data/test/multiverse/lib/multiverse/output_collector.rb +29 -0
  38. data/test/multiverse/lib/multiverse/runner.rb +44 -0
  39. data/test/multiverse/lib/multiverse/suite.rb +162 -0
  40. data/test/multiverse/script/run_one +3 -0
  41. data/test/multiverse/script/runner +9 -0
  42. data/test/multiverse/suites/active_record/Envfile +13 -0
  43. data/test/multiverse/suites/active_record/ar_method_aliasing.rb +94 -0
  44. data/test/multiverse/suites/active_record/config/newrelic.yml +22 -0
  45. data/test/multiverse/suites/active_record/encoding_test.rb +26 -0
  46. data/test/multiverse/suites/agent_only/Envfile +3 -0
  47. data/test/multiverse/suites/agent_only/config/newrelic.yml +22 -0
  48. data/test/multiverse/suites/agent_only/http_response_code_test.rb +53 -0
  49. data/test/multiverse/suites/agent_only/marshaling_test.rb +109 -0
  50. data/test/multiverse/suites/agent_only/method_visibility_test.rb +98 -0
  51. data/test/multiverse/suites/agent_only/pipe_manager_test.rb +33 -0
  52. data/test/multiverse/suites/agent_only/service_timeout_test.rb +29 -0
  53. data/test/multiverse/suites/agent_only/test_trace_method_with_punctuation.rb +30 -0
  54. data/test/multiverse/suites/agent_only/test_trace_transaction_with_punctuation.rb +32 -0
  55. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +80 -0
  56. data/test/multiverse/suites/datamapper/Envfile +8 -0
  57. data/test/multiverse/suites/datamapper/config/newrelic.yml +22 -0
  58. data/test/multiverse/suites/datamapper/encoding_test.rb +36 -0
  59. data/test/multiverse/suites/monitor_mode_false/Envfile +2 -0
  60. data/test/multiverse/suites/monitor_mode_false/config/newrelic.yml +25 -0
  61. data/test/multiverse/suites/monitor_mode_false/no_dns_resolv.rb +29 -0
  62. data/test/multiverse/suites/no_load/Envfile +2 -0
  63. data/test/multiverse/suites/no_load/config/newrelic.yml +23 -0
  64. data/test/multiverse/suites/no_load/start_up_test.rb +14 -0
  65. data/test/multiverse/suites/rails_3_error_tracing/Envfile +15 -0
  66. data/test/multiverse/suites/rails_3_error_tracing/config/newrelic.yml +165 -0
  67. data/test/multiverse/suites/rails_3_error_tracing/error_tracing_test.rb +236 -0
  68. data/test/multiverse/suites/rails_3_gc/Envfile +8 -0
  69. data/test/multiverse/suites/rails_3_gc/config/newrelic.yml +167 -0
  70. data/test/multiverse/suites/rails_3_gc/instrumentation_test.rb +92 -0
  71. data/test/multiverse/suites/rails_3_queue_time/Envfile +15 -0
  72. data/test/multiverse/suites/rails_3_queue_time/config/newrelic.yml +165 -0
  73. data/test/multiverse/suites/rails_3_queue_time/queue_time_test.rb +75 -0
  74. data/test/multiverse/suites/rails_3_views/.gitignore +3 -0
  75. data/test/multiverse/suites/rails_3_views/Envfile +16 -0
  76. data/test/multiverse/suites/rails_3_views/app/views/foos/_foo.html.haml +1 -0
  77. data/test/multiverse/suites/rails_3_views/app/views/test/_a_partial.html.erb +1 -0
  78. data/test/multiverse/suites/rails_3_views/app/views/test/_mid_partial.html.erb +1 -0
  79. data/test/multiverse/suites/rails_3_views/app/views/test/_top_partial.html.erb +3 -0
  80. data/test/multiverse/suites/rails_3_views/app/views/test/deep_partial.html.erb +3 -0
  81. data/test/multiverse/suites/rails_3_views/app/views/test/haml_view.html.haml +6 -0
  82. data/test/multiverse/suites/rails_3_views/app/views/test/index.html.erb +4 -0
  83. data/test/multiverse/suites/rails_3_views/config/newrelic.yml +164 -0
  84. data/test/multiverse/suites/rails_3_views/view_instrumentation_test.rb +245 -0
  85. data/test/multiverse/suites/resque/Envfile +21 -0
  86. data/test/multiverse/suites/resque/config/newrelic.yml +22 -0
  87. data/test/multiverse/suites/resque/dump.rdb +0 -0
  88. data/test/multiverse/suites/resque/instrumentation_test.rb +73 -0
  89. data/test/multiverse/suites/rum_auto_instrumentation/Envfile +4 -0
  90. data/test/multiverse/suites/rum_auto_instrumentation/config/newrelic.yml +24 -0
  91. data/test/multiverse/suites/rum_auto_instrumentation/problem_response.html +422 -0
  92. data/test/multiverse/suites/rum_auto_instrumentation/responses/worst_case_small.html +5000 -0
  93. data/test/multiverse/suites/rum_auto_instrumentation/sanity_test.rb +115 -0
  94. data/test/multiverse/suites/sinatra/Envfile +13 -0
  95. data/test/multiverse/suites/sinatra/config/newrelic.yml +24 -0
  96. data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +76 -0
  97. data/test/multiverse/suites/sinatra/sinatra_routes_test.rb +46 -0
  98. data/test/multiverse/test/multiverse_test.rb +55 -0
  99. data/test/multiverse/test/suite_examples/one/a/Envfile +3 -0
  100. data/test/multiverse/test/suite_examples/one/a/a_test.rb +11 -0
  101. data/test/multiverse/test/suite_examples/one/a/config/newrelic.yml +24 -0
  102. data/test/multiverse/test/suite_examples/one/b/Envfile +3 -0
  103. data/test/multiverse/test/suite_examples/one/b/b_test.rb +11 -0
  104. data/test/multiverse/test/suite_examples/one/b/config/newrelic.yml +24 -0
  105. data/test/multiverse/test/suite_examples/three/a/Envfile +2 -0
  106. data/test/multiverse/test/suite_examples/three/a/fail_test.rb +6 -0
  107. data/test/multiverse/test/suite_examples/three/b/Envfile +2 -0
  108. data/test/multiverse/test/suite_examples/three/b/win_test.rb +6 -0
  109. data/test/multiverse/test/suite_examples/two/a/Envfile +1 -0
  110. data/test/multiverse/test/suite_examples/two/a/fail_test.rb +6 -0
  111. data/test/new_relic/agent/agent_test.rb +54 -2
  112. data/test/new_relic/agent/agent_test_controller.rb +1 -1
  113. data/test/new_relic/agent/agent_test_controller_test.rb +35 -5
  114. data/test/new_relic/agent/browser_monitoring_test.rb +8 -8
  115. data/test/new_relic/agent/configuration/environment_source_test.rb +16 -0
  116. data/test/new_relic/agent/method_tracer_test.rb +6 -6
  117. data/test/new_relic/agent/new_relic_service_test.rb +137 -20
  118. data/test/new_relic/agent/sql_sampler_test.rb +26 -0
  119. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +1 -1
  120. data/test/new_relic/agent/stats_engine_test.rb +1 -0
  121. data/test/new_relic/agent/thread_profiler_test.rb +536 -0
  122. data/test/new_relic/agent/thread_test.rb +76 -0
  123. data/test/new_relic/agent/threaded_test.rb +65 -0
  124. data/test/new_relic/agent/transaction_sampler_test.rb +16 -13
  125. data/test/new_relic/agent/worker_loop_test.rb +20 -0
  126. data/test/new_relic/fake_collector.rb +103 -31
  127. data/test/new_relic/fake_service.rb +7 -1
  128. data/test/new_relic/metric_data_test.rb +45 -16
  129. data/test/new_relic/noticed_error_test.rb +14 -0
  130. data/test/new_relic/transaction_sample/segment_test.rb +23 -4
  131. data/test/new_relic/transaction_sample_test.rb +39 -0
  132. data/ui/views/layouts/newrelic_default.rhtml +1 -0
  133. data/ui/views/newrelic/threads.rhtml +2 -10
  134. metadata +88 -2
@@ -6,23 +6,28 @@ module NewRelic
6
6
  # A task is a proc or block with a specified call period in seconds.
7
7
  class WorkerLoop
8
8
 
9
- def initialize
9
+ # Optional argument :duration (in seconds) for how long the worker loop runs
10
+ # or :limit (integer) for max number of iterations
11
+ def initialize(opts={})
10
12
  @log = log
11
13
  @should_run = true
12
14
  @next_invocation_time = Time.now
13
15
  @period = 60.0
16
+ @deadline = Time.now + opts[:duration] if opts[:duration]
17
+ @limit = opts[:limit] if opts[:limit]
18
+ @iterations = 0
14
19
  end
15
-
20
+
16
21
  # returns a class-level memoized mutex to make sure we don't run overlapping
17
22
  def lock
18
23
  @@lock ||= Mutex.new
19
24
  end
20
-
25
+
21
26
  # a helper to access the NewRelic::Control.instance.log
22
27
  def log
23
28
  NewRelic::Control.instance.log
24
29
  end
25
-
30
+
26
31
  # Run infinitely, calling the registered tasks at their specified
27
32
  # call periods. The caller is responsible for creating the thread
28
33
  # that runs this worker loop. This will run the task immediately.
@@ -30,28 +35,37 @@ module NewRelic
30
35
  @period = period if period
31
36
  @next_invocation_time = (Time.now + @period)
32
37
  @task = block
33
- while keep_running do
34
- now = Time.now
35
- while now < @next_invocation_time
38
+ while keep_running? do
39
+ while @now < @next_invocation_time
36
40
  # sleep until this next task's scheduled invocation time
37
- sleep_time = @next_invocation_time - now
41
+ sleep_time = @next_invocation_time - @now
38
42
  sleep sleep_time if sleep_time > 0
39
- now = Time.now
43
+ @now = Time.now
40
44
  end
41
- run_task if keep_running
45
+ run_task if keep_running?
46
+ @iterations += 1 if !@limit.nil?
42
47
  end
43
48
  end
44
-
49
+
45
50
  # a simple accessor for @should_run
46
- def keep_running
47
- @should_run
51
+ def keep_running?
52
+ @now = Time.now
53
+ @should_run && under_duration? && under_limit?
54
+ end
55
+
56
+ def under_duration?
57
+ !@deadline || @now < @deadline
58
+ end
59
+
60
+ def under_limit?
61
+ !@limit || @iterations < @limit
48
62
  end
49
-
63
+
50
64
  # Sets @should_run to false. Returns false
51
65
  def stop
52
66
  @should_run = false
53
67
  end
54
-
68
+
55
69
  # Executes the block given to the worker loop, and handles many
56
70
  # possible errors. Also updates the execution time so that the
57
71
  # next run occurs on schedule, even if we execute at some odd time
@@ -158,10 +158,10 @@ module NewRelic
158
158
  def install_shim
159
159
  super
160
160
  require 'new_relic/agent/instrumentation/controller_instrumentation'
161
- if !ActiveSupport.respond_to?(:on_load) # rails 3+
162
- ActionController::Base.class_eval do
163
- include NewRelic::Agent::Instrumentation::ControllerInstrumentation::Shim
164
- end
161
+ if ActiveSupport.respond_to?(:on_load) # rails 3+
162
+ ActiveSupport.on_load(:action_controller) { include NewRelic::Agent::Instrumentation::ControllerInstrumentation::Shim }
163
+ else
164
+ ActionController::Base.class_eval { include NewRelic::Agent::Instrumentation::ControllerInstrumentation::Shim }
165
165
  end
166
166
  end
167
167
  end
@@ -69,7 +69,7 @@ module NewRelic
69
69
 
70
70
  # Collect the Rails::Info into an associative array as well as the list of plugins
71
71
  def append_environment_info
72
- local_env.append_environment_value('Rails version'){ version }
72
+ local_env.append_environment_value('Rails version'){ ::Rails::VERSION::STRING }
73
73
  local_env.append_environment_value('Rails threadsafe') do
74
74
  true == ::Rails.configuration.action_controller.allow_concurrency
75
75
  end
@@ -27,5 +27,8 @@ module NewRelic
27
27
  end
28
28
  end
29
29
 
30
+ def time_to_millis(time)
31
+ (time.to_f * 1000).round
32
+ end
30
33
  end
31
34
  end
@@ -20,7 +20,7 @@ module NewRelic
20
20
  def original_spec
21
21
  @original_spec || @metric_spec
22
22
  end
23
-
23
+
24
24
  # assigns a new metric spec, and retains the old metric spec as
25
25
  # @original_spec if it exists currently
26
26
  def metric_spec= new_spec
@@ -36,7 +36,7 @@ module NewRelic
36
36
  def to_json(*a)
37
37
  %Q[{"metric_spec":#{metric_id ? 'null' : metric_spec.to_json},"stats":{"total_exclusive_time":#{stats.total_exclusive_time},"min_call_time":#{stats.min_call_time},"call_count":#{stats.call_count},"sum_of_squares":#{stats.sum_of_squares},"total_call_time":#{stats.total_call_time},"max_call_time":#{stats.max_call_time}},"metric_id":#{metric_id ? metric_id : 'null'}}]
38
38
  end
39
-
39
+
40
40
  def to_s
41
41
  if metric_spec
42
42
  "#{metric_spec.name}(#{metric_spec.scope}): #{stats}"
@@ -44,8 +44,16 @@ module NewRelic
44
44
  "#{metric_id}: #{stats}"
45
45
  end
46
46
  end
47
+
47
48
  def inspect
48
49
  "#<MetricData metric_spec:#{metric_spec.inspect}, stats:#{stats.inspect}, metric_id:#{metric_id.inspect}>"
49
50
  end
51
+
52
+ def to_collector_array(marshaller=nil)
53
+ stat_key = metric_id || { 'name' => metric_spec.name, 'scope' => metric_spec.scope }
54
+ [ stat_key,
55
+ [ stats.call_count, stats.total_call_time, stats.total_exclusive_time,
56
+ stats.min_call_time, stats.max_call_time, stats.sum_of_squares ] ]
57
+ end
50
58
  end
51
59
  end
@@ -36,4 +36,9 @@ class NewRelic::NoticedError
36
36
  false
37
37
  end
38
38
  end
39
+
40
+ def to_collector_array(marshaller=nil)
41
+ [ (@timestamp.to_f * 1000).round, @path, @message, @exception_class,
42
+ @params ]
43
+ end
39
44
  end
@@ -1,3 +1,5 @@
1
+ require 'base64'
2
+
1
3
  require 'new_relic/transaction_sample/segment'
2
4
  require 'new_relic/transaction_sample/summary_segment'
3
5
  require 'new_relic/transaction_sample/fake_segment'
@@ -51,15 +53,25 @@ module NewRelic
51
53
  @start_time - @@start_time.to_f
52
54
  end
53
55
 
54
- # Used in the server only
55
- def to_json(options = {}) #:nodoc:
56
- map = {:sample_id => @sample_id,
57
- :start_time => @start_time,
58
- :root_segment => @root_segment}
59
- if @params && !@params.empty?
60
- map[:params] = @params
56
+ def to_json
57
+ JSON.dump(self.to_array)
58
+ end
59
+
60
+ def to_array
61
+ [ @start_time.to_f, @params[:request_params], @params[:custom_params],
62
+ @root_segment.to_array ]
63
+ end
64
+
65
+ def to_collector_array(marshaller)
66
+ trace_tree = if marshaller.respond_to?(:encode_compress)
67
+ marshaller.encode_compress(self.to_array)
68
+ else
69
+ self.to_array
61
70
  end
62
- map.to_json
71
+
72
+ [ Helper.time_to_millis(@start_time), Helper.time_to_millis(duration),
73
+ @params[:path], @params[:uri], trace_tree, @guid, nil,
74
+ !!@force_persist ]
63
75
  end
64
76
 
65
77
  def start_time
@@ -134,10 +146,10 @@ module NewRelic
134
146
  regex = Regexp.new(regex)
135
147
 
136
148
  sample = TransactionSample.new(@start_time, sample_id)
137
-
149
+
138
150
  sample.params = params.dup
139
151
  sample.params[:segment_count] = 0
140
-
152
+
141
153
  delta = build_segment_with_omissions(sample, 0.0, @root_segment, sample.root_segment, regex)
142
154
  sample.root_segment.end_trace(@root_segment.exit_timestamp - delta)
143
155
  sample.profile = self.profile
@@ -160,7 +172,7 @@ module NewRelic
160
172
  sample.force_persist = self.force_persist if self.force_persist
161
173
 
162
174
  build_segment_for_transfer(sample, @root_segment, sample.root_segment, options)
163
-
175
+
164
176
  sample.root_segment.end_trace(@root_segment.exit_timestamp)
165
177
  sample
166
178
  end
@@ -171,8 +183,6 @@ module NewRelic
171
183
 
172
184
  private
173
185
 
174
-
175
-
176
186
  HEX_DIGITS = (0..15).map{|i| i.to_s(16)}
177
187
  # generate a random 64 bit uuid
178
188
  def generate_guid
@@ -1,4 +1,5 @@
1
1
  require 'new_relic/transaction_sample'
2
+
2
3
  module NewRelic
3
4
  class TransactionSample
4
5
  class Segment
@@ -15,13 +16,13 @@ module NewRelic
15
16
  @metric_name = metric_name || '<unknown>'
16
17
  @segment_id = segment_id || object_id
17
18
  end
18
-
19
+
19
20
  # sets the final timestamp on a segment to indicate the exit
20
21
  # point of the segment
21
22
  def end_trace(timestamp)
22
23
  @exit_timestamp = timestamp
23
24
  end
24
-
25
+
25
26
  def add_called_segment(s)
26
27
  @called_segments ||= []
27
28
  @called_segments << s
@@ -32,18 +33,15 @@ module NewRelic
32
33
  to_debug_str(0)
33
34
  end
34
35
 
35
- def to_json(options={})
36
- hash = {
37
- :entry_timestamp => @entry_timestamp,
38
- :exit_timestamp => @exit_timestamp,
39
- :metric_name => @metric_name,
40
- :segment_id => @segment_id,
41
- }
42
-
43
- hash[:called_segments] = called_segments if !called_segments.empty?
44
- hash[:params] = @params if @params && !@params.empty?
36
+ def to_array
37
+ [ (@entry_timestamp.to_f * 1000).round,
38
+ (@exit_timestamp.to_f * 1000).round,
39
+ @metric_name, (@params || {}) ] +
40
+ [ (@called_segments ? @called_segments.map{|s| s.to_array} : []) ]
41
+ end
45
42
 
46
- hash.to_json
43
+ def to_json
44
+ JSON.dump(self.to_array)
47
45
  end
48
46
 
49
47
  def path_string
@@ -97,13 +95,13 @@ module NewRelic
97
95
  end
98
96
  d
99
97
  end
100
-
98
+
101
99
  def count_segments
102
100
  count = 1
103
101
  called_segments.each { | seg | count += seg.count_segments }
104
102
  count
105
103
  end
106
-
104
+
107
105
  # Walk through the tree and truncate the segments in a
108
106
  # depth-first manner
109
107
  def truncate(max)
@@ -3,7 +3,7 @@ module NewRelic
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 3
5
5
  MINOR = 5
6
- TINY = 2
6
+ TINY = 3
7
7
  BUILD = nil
8
8
  STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
9
9
  end
@@ -7,18 +7,12 @@ if defined? Rake::TestTask
7
7
  task :test => 'test:newrelic'
8
8
  task :default => :test
9
9
  namespace :test do
10
- AGENT_HOME = File.expand_path(File.join(File.dirname(__FILE__),'..','..'))
11
- Rake::TestTask.new(:newrelic) do |t|
12
- t.libs << "#{AGENT_HOME}/test"
13
- t.libs << "#{AGENT_HOME}/lib"
14
- t.pattern = "#{AGENT_HOME}/test/**/*_test.rb"
15
- t.verbose = true
16
- end
10
+ agent_home = File.expand_path(File.join(File.dirname(__FILE__),'..','..'))
17
11
 
18
- Rake::TestTask.new(:intentional_fail) do |t|
19
- t.libs << "#{AGENT_HOME}/test"
20
- t.libs << "#{AGENT_HOME}/lib"
21
- t.pattern = "#{AGENT_HOME}/test/intentional_fail.rb"
12
+ Rake::TestTask.new(:newrelic) do |t|
13
+ t.libs << "#{agent_home}/test"
14
+ t.libs << "#{agent_home}/lib"
15
+ t.pattern = "#{agent_home}/test/new_relic/**/*_test.rb"
22
16
  t.verbose = true
23
17
  end
24
18
  end
@@ -0,0 +1,10 @@
1
+ tmp
2
+ *.swp
3
+ .bundler_work_area
4
+ Gemfile
5
+ Gemfile.lock
6
+ *.log
7
+ *.db
8
+ .idea
9
+ tags
10
+ *.sqlite3
@@ -0,0 +1,90 @@
1
+ # Multiverse
2
+
3
+ ## Testing in a multitude of environments
4
+
5
+ Multiverse was created to solve a specific problem experienced by the Agent
6
+ team. Not only does the New Relic Agent run in a wide variety of environments,
7
+ but its expected behavior *changes* based on the environment. Instrumenation is
8
+ toggled on and off based on the presence of certain libraries, and some of these
9
+ libraries are incompatible with each other. Effective testing requires us to
10
+ specify different environments for different tests; Multiverse aims to make this
11
+ painless.
12
+
13
+
14
+ ## Getting started
15
+
16
+ To run tests against the agent invoke the runner script.
17
+
18
+ script/runner
19
+
20
+
21
+ You can invoke this via rake
22
+
23
+ rake test
24
+
25
+ If you only want to run some test suites you can filter by their names
26
+
27
+ script/runner sinatra
28
+
29
+ You can run tests of multiverse itself with
30
+
31
+ rake test:self
32
+
33
+ ### Adding a test suite
34
+
35
+ To add tests add a directory to the `suites` directory. This directory should
36
+ contain at least two files.
37
+
38
+ #### Envfile
39
+
40
+ The Envfile is a meta gem file. It allows you to specify one or more gemset
41
+ that the tests in this directory should be run against. For example:
42
+
43
+ gemfile <<-GEMFILE
44
+ gem "rails", "~>3.2.0"
45
+ GEMFILE
46
+
47
+ gemfile <<-GEMFILE
48
+ gem "rails", "~>3.1.0"
49
+ GEMFILE
50
+
51
+ This will run these tests against 2 environments, one running rails 3.1, the
52
+ other running rails 3.2.
53
+
54
+ New Relic is automatically included in the environment. Specifying it in the
55
+ Envfile will trigger and error. You can override where newrelic is loaded from
56
+ using two environment variables.
57
+
58
+ The default gemfile line is
59
+
60
+ gem 'newrelic_rpm', :path => '../../../ruby_agent'
61
+
62
+ `ENV['NEWRELIC_GEMFILE_LINE']` will specify the full line for the gemfile
63
+
64
+ `ENV['NEWRELIC_GEM_PATH']` will override the `:path` option in the default line.
65
+
66
+
67
+ #### Test files
68
+
69
+ All files in a test suite directory that end with .rb will be executed as test
70
+ files. These should use test unit.
71
+
72
+ For example:
73
+
74
+ require 'test/unit'
75
+ class ATest < Test::Unit::TestCase
76
+ def test_json_is_loaded
77
+ assert JSON
78
+ end
79
+
80
+ def test_haml_is_not_loaded
81
+ assert !defined?(Haml)
82
+ end
83
+ end
84
+
85
+
86
+ ## Testing Multiverse
87
+
88
+ Multiverse has a suite of tests in the `test` directory for testing the
89
+ framework itself (sooo meta). These help confirm that the system is working as
90
+ expected.
@@ -0,0 +1,17 @@
1
+ require 'rake/testtask.rb'
2
+ require File.join(File.dirname(__FILE__),'lib','multiverse','color')
3
+
4
+ desc "Test the testing framework by executing tests in /test. Get meta with it."
5
+ task "test:self" do
6
+ extend Multiverse::Color
7
+ puts yellow("Testing the multiverse testing framework...")
8
+ test_files = FileList['test/*_test.rb']
9
+ ruby test_files.join(" ")
10
+ end
11
+
12
+ desc "Test the agent. Run all suites in /suites to test."
13
+ task "test" do
14
+ ruby 'script/runner'
15
+ end
16
+
17
+ task 'default' => ['test:self', 'test']