From 1db54d7d01ea36a9d8c0c6276d66d04a9a6c2fac Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Mon, 4 Feb 2013 17:16:25 +0100 Subject: Backport rails/rails-perftest#2 to fix rake test:benchmark --- activesupport/lib/active_support/testing/performance.rb | 2 +- activesupport/lib/active_support/testing/performance/jruby.rb | 2 +- activesupport/lib/active_support/testing/performance/rubinius.rb | 2 +- activesupport/lib/active_support/testing/performance/ruby.rb | 2 +- railties/CHANGELOG.md | 5 +++++ railties/lib/rails/commands/benchmarker.rb | 3 +-- railties/lib/rails/test_unit/testing.rake | 7 +++++-- 7 files changed, 15 insertions(+), 8 deletions(-) diff --git a/activesupport/lib/active_support/testing/performance.rb b/activesupport/lib/active_support/testing/performance.rb index dd23f8d82d..5b74e52953 100644 --- a/activesupport/lib/active_support/testing/performance.rb +++ b/activesupport/lib/active_support/testing/performance.rb @@ -23,7 +23,7 @@ module ActiveSupport # each implementation should define metrics and freeze the defaults DEFAULTS = - if ARGV.include?('--benchmark') # HAX for rake test + if ENV["BENCHMARK_TESTS"] { :runs => 4, :output => 'tmp/performance', :benchmark => true } diff --git a/activesupport/lib/active_support/testing/performance/jruby.rb b/activesupport/lib/active_support/testing/performance/jruby.rb index b347539f13..af08f0e22d 100644 --- a/activesupport/lib/active_support/testing/performance/jruby.rb +++ b/activesupport/lib/active_support/testing/performance/jruby.rb @@ -6,7 +6,7 @@ module ActiveSupport module Testing module Performance DEFAULTS.merge!( - if ARGV.include?('--benchmark') + if ENV["BENCHMARK_TESTS"] {:metrics => [:wall_time, :user_time, :memory, :gc_runs, :gc_time]} else { :metrics => [:wall_time], diff --git a/activesupport/lib/active_support/testing/performance/rubinius.rb b/activesupport/lib/active_support/testing/performance/rubinius.rb index d9ebfbe352..baabd9cc44 100644 --- a/activesupport/lib/active_support/testing/performance/rubinius.rb +++ b/activesupport/lib/active_support/testing/performance/rubinius.rb @@ -4,7 +4,7 @@ module ActiveSupport module Testing module Performance DEFAULTS.merge!( - if ARGV.include?('--benchmark') + if ENV["BENCHMARK_TESTS"] {:metrics => [:wall_time, :memory, :objects, :gc_runs, :gc_time]} else { :metrics => [:wall_time], diff --git a/activesupport/lib/active_support/testing/performance/ruby.rb b/activesupport/lib/active_support/testing/performance/ruby.rb index 50c4852d4c..5aaed2bbe7 100644 --- a/activesupport/lib/active_support/testing/performance/ruby.rb +++ b/activesupport/lib/active_support/testing/performance/ruby.rb @@ -9,7 +9,7 @@ module ActiveSupport module Testing module Performance DEFAULTS.merge!( - if ARGV.include?('--benchmark') + if ENV["BENCHMARK_TESTS"] { :metrics => [:wall_time, :memory, :objects, :gc_runs, :gc_time] } else { :min_percent => 0.01, diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 4bb2ec4618..9ecb37e903 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -21,6 +21,11 @@ * No changes. +* Fix launching performance tests through rake `test:benchmark`. + Fixes #4938. + Backport rails/rails-perftest#2. + + *Dmitry Vorotilin + Yves Senn* ## Rails 3.2.11 (Jan 8, 2013) ## diff --git a/railties/lib/rails/commands/benchmarker.rb b/railties/lib/rails/commands/benchmarker.rb index b745b45e17..b9169468a3 100644 --- a/railties/lib/rails/commands/benchmarker.rb +++ b/railties/lib/rails/commands/benchmarker.rb @@ -2,9 +2,8 @@ require 'optparse' require 'rails/test_help' require 'rails/performance_test_help' -ARGV.push('--benchmark') # HAX +ENV["BENCHMARK_TESTS"] = '1' require 'active_support/testing/performance' -ARGV.pop def options options = {} diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake index 290005993a..8d624c6999 100644 --- a/railties/lib/rails/test_unit/testing.rake +++ b/railties/lib/rails/test_unit/testing.rake @@ -123,10 +123,13 @@ namespace :test do t.pattern = 'test/integration/**/*_test.rb' end - Rails::SubTestTask.new(:benchmark => 'test:prepare') do |t| + task 'test:benchmark_mode' do + ENV["BENCHMARK_TESTS"] = '1' + end + + Rails::SubTestTask.new(:benchmark => ['test:prepare', 'test:benchmark_mode']) do |t| t.libs << 'test' t.pattern = 'test/performance/**/*_test.rb' - t.options = '-- --benchmark' end Rails::SubTestTask.new(:profile => 'test:prepare') do |t| -- cgit v1.2.3 From b47f8d035ec6a38a69eb5b3bdb1e27bb40e574c7 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Thu, 27 Jun 2013 20:54:57 +0200 Subject: clear ARGV to prevent mintest autorun errors: Minitest expects the first argument in `ARGV` to be the path to a test file. Because `rails benchmarker` and `rails profiler` define an on-the-fly test-case, using the first `ARGV` to pass the code to execute this results in: ``` /Users/senny/.rbenv/versions/1.9.3-p374/lib/ruby/1.9.1/test/unit.rb:167:in `block in non_options': file not found: 1000.times{"a string"} (ArgumentError) from /Users/senny/.rbenv/versions/1.9.3-p374/lib/ruby/1.9.1/test/unit.rb:146:in `map!' from /Users/senny/.rbenv/versions/1.9.3-p374/lib/ruby/1.9.1/test/unit.rb:146:in `non_options' from /Users/senny/.rbenv/versions/1.9.3-p374/lib/ruby/1.9.1/test/unit.rb:207:in `non_options' from /Users/senny/.rbenv/versions/1.9.3-p374/lib/ruby/1.9.1/test/unit.rb:52:in `process_args' from /Users/senny/.rbenv/versions/1.9.3-p374/lib/ruby/1.9.1/minitest/unit.rb:891:in `_run' from /Users/senny/.rbenv/versions/1.9.3-p374/lib/ruby/1.9.1/minitest/unit.rb:884:in `run' from /Users/senny/.rbenv/versions/1.9.3-p374/lib/ruby/1.9.1/test/unit.rb:21:in `run' from /Users/senny/.rbenv/versions/1.9.3-p374/lib/ruby/1.9.1/test/unit.rb:326:in `block (2 levels) in autorun' from /Users/senny/.rbenv/versions/1.9.3-p374/lib/ruby/1.9.1/test/unit.rb:27:in `run_once' from /Users/senny/.rbenv/versions/1.9.3-p374/lib/ruby/1.9.1/test/unit.rb:325:in `block in autorun' ``` clearing ARGV after defining the test-case solves this issue. --- railties/CHANGELOG.md | 6 ++++++ railties/lib/rails/commands/benchmarker.rb | 1 + railties/lib/rails/commands/profiler.rb | 1 + 3 files changed, 8 insertions(+) diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 9ecb37e903..43aed3f0e7 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,5 +1,11 @@ ## unreleased ## +* Fix bugs that crashed `rake test:benchmark`, `rails profiler` and + `rails benchmarker`. + Fixes #4938. + + *Yves Senn* + * Add support for runner hook. Backport #7695. diff --git a/railties/lib/rails/commands/benchmarker.rb b/railties/lib/rails/commands/benchmarker.rb index b9169468a3..a2d92f8956 100644 --- a/railties/lib/rails/commands/benchmarker.rb +++ b/railties/lib/rails/commands/benchmarker.rb @@ -30,4 +30,5 @@ class BenchmarkerTest < ActionDispatch::PerformanceTest #:nodoc: end RUBY end + ARGV.clear end diff --git a/railties/lib/rails/commands/profiler.rb b/railties/lib/rails/commands/profiler.rb index 3f6966b4f0..9b3b4f41f6 100644 --- a/railties/lib/rails/commands/profiler.rb +++ b/railties/lib/rails/commands/profiler.rb @@ -29,4 +29,5 @@ class ProfilerTest < ActionDispatch::PerformanceTest #:nodoc: end RUBY end + ARGV.clear end -- cgit v1.2.3