1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

minitest/ruby19 compatible performance test

This commit is contained in:
Jan Xie 2011-05-05 16:11:49 +08:00
parent 3e9bb5459c
commit 25288c137c

View file

@ -3,36 +3,61 @@ begin
require 'fileutils'
require 'rails/version'
require 'active_support/concern'
require 'active_support/core_ext/class/delegating_attributes'
require 'active_support/core_ext/string/inflections'
module ActiveSupport
module Testing
module Performance
DEFAULTS =
if benchmark = ARGV.include?('--benchmark') # HAX for rake test
{ :benchmark => true,
:runs => 4,
:metrics => [:wall_time, :memory, :objects, :gc_runs, :gc_time],
:output => 'tmp/performance' }
extend ActiveSupport::Concern
included do
superclass_delegating_accessor :profile_options
self.profile_options = DEFAULTS
if defined?(MiniTest::Assertions) && TestCase < MiniTest::Assertions
include ForMiniTest
else
{ :benchmark => false,
:runs => 1,
:min_percent => 0.01,
:metrics => [:process_time, :memory, :objects],
:formats => [:flat, :graph_html, :call_tree],
:output => 'tmp/performance' }
end.freeze
def self.included(base)
base.superclass_delegating_accessor :profile_options
base.profile_options = DEFAULTS
include ForClassicTestUnit
end
end
def full_test_name
"#{self.class.name}##{method_name}"
module ForMiniTest
def run(runner)
@runner = runner
run_warmup
if profile_options && metrics = profile_options[:metrics]
metrics.each do |metric_name|
if klass = Metrics[metric_name.to_sym]
run_profile(klass.new)
end
end
end
end
def run_test(metric, mode)
result = '.'
begin
run_callbacks :setup
setup
metric.send(mode) { __send__ method_name }
rescue Exception => e
result = @runner.puke(self.class, method_name, e)
ensure
begin
teardown
run_callbacks :teardown, :enumerator => :reverse_each
rescue Exception => e
result = @runner.puke(self.class, method_name, e)
end
end
result
end
end
module ForClassicTestUnit
def run(result)
return if method_name =~ /^default_test$/
@ -70,6 +95,26 @@ begin
add_error(e)
end
end
end
DEFAULTS =
if benchmark = ARGV.include?('--benchmark') # HAX for rake test
{ :benchmark => true,
:runs => 4,
:metrics => [:wall_time, :memory, :objects, :gc_runs, :gc_time],
:output => 'tmp/performance' }
else
{ :benchmark => false,
:runs => 1,
:min_percent => 0.01,
:metrics => [:process_time, :memory, :objects],
:formats => [:flat, :graph_html, :call_tree],
:output => 'tmp/performance' }
end.freeze
def full_test_name
"#{self.class.name}##{method_name}"
end
protected
def run_warmup