This project is archived and is in readonly mode.
Fresh Rails 3 app cannot run performance tests
Steps to reproduce:
$ rails myapp $ cd myapp $ rake db:schema:dump $ rake test:benchmark (in myapp) activesupport-3.0.0.beta/lib/active_support/dependencies.rb:456:in `load_missing_constant': uninitialized constant ActionDispatch::PerformanceTest (NameError) from activesupport-3.0.0.beta/lib/active_support/dependencies.rb:91:in `const_missing' from actionpack-3.0.0.beta/lib/action_controller/deprecated/performance_test.rb:1 from ./test/performance/browsing_test.rb:5 from rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `load' from rake-0.8.7/lib/rake/rake_test_loader.rb:5 from rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `each' from rake-0.8.7/lib/rake/rake_test_loader.rb:5 rake aborted! Command failed with status (1) (See full trace by running task with --trace)
I believe this issue began with Bundler 0.9 and its change so that disable_system_gems is the default and only option, preventing any gem not specified in the Gemfile or is a dependency of one of the gems, it won't load.
That prevents ActiveSupport::Testing:: Performance from being defined because its definition is wrapped in a begin; rescue LoadError; end block along with the require for ruby-prof, which will always fail in a fresh app since the Gemfile doesn't include it and it isn't specified as a dependency of any of the Rails gems.
ActionDispatch::PerformanceTest's definition is wrapped in an if defined? checking for a successful definition of ActiveSupport::Testing:: Performance, which again fails in a fresh app.
ActionController::PerformanceTest, which the generated test uses, is deprecated and just gets assigned as equal to ActionDispatch::PerformanceTest. Problem being it isn't always defined, and won't be in a fresh app since requiring ruby-prof fails.
It's a tricky set of dominoes that have fallen over after Bundler's change.
I think there's several likely changes that should be made in response to this beyond simply fixing the issue. A couple of changes to isolate these components from each other's changes should also be put in place I think. I'm happy to put together a patch, but I need some guidance on the best changes to make.
- ruby-prof has to be required at some point, which is tricky
since it involves C extensions. But it must be required as a gem
dependency either by a gem specification or the Gemfile.
- The definitions of ActionDispatch::PerformanceTest and
ActiveSupport::Testing::PerformanceTest should not be conditional,
if there must be special handling, have it in the behavior of the
class instead. In Rails 2.3, the definition is not conditional, it
was made so as a part of the autoload refactoring.
- The generator should not use the deprecated
- ActionController::PerformanceTest should log a deprecation warning.
Comments and changes to this ticket
- State changed from new to open
- Assigned user set to Jeremy Kemper
+1 on all four points, Chris.
For ruby-prof, I think a lazy-require would be good enough. If it's not available at that time, raise an error asking to add it to the Gemfile in the :test group.
- State changed from open to resolved
(from [835f5d0269a8d3615585119e77f1ba7d601c943b]) Rails 3 application can run performance tests now. [#4171 state:resolved] http://github.com/rails/rails/commit/835f5d0269a8d3615585119e77f1ba...
I think this is still an issue.
Trying to run the performance test with a fresh Rails app after adding "ruby-prof" to the Gemfile, i get this error:
activesupport-3.0.0/lib/active_support/testing/performance.rb:39:in `run': uninitialized constant BrowsingTest::STARTED (NameError)
Here's the full trace:
fresh$ rake test:benchmark --trace (in /Users/andreashaller/Desktop/fresh) ** Invoke test:benchmark (first_time) ** Invoke test:prepare (first_time) ** Invoke db:test:prepare (first_time) ** Invoke db:abort_if_pending_migrations (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute db:abort_if_pending_migrations ** Execute db:test:prepare ** Invoke db:test:load (first_time) ** Invoke db:test:purge (first_time) ** Invoke environment ** Execute db:test:purge ** Execute db:test:load ** Invoke db:schema:load (first_time) ** Invoke environment ** Execute db:schema:load ** Execute test:prepare ** Execute test:benchmark Loaded suite /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake/rake_test_loader Started /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/testing/performance.rb:39:in `run': uninitialized constant BrowsingTest::STARTED (NameError) from /Users/andreashaller/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/minitest/unit.rb:641:in `block (2 levels) in run_test_suites' from /Users/andreashaller/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/minitest/unit.rb:635:in `each' from /Users/andreashaller/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/minitest/unit.rb:635:in `block in run_test_suites' from /Users/andreashaller/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/minitest/unit.rb:634:in `each' from /Users/andreashaller/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/minitest/unit.rb:634:in `run_test_suites' from /Users/andreashaller/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/minitest/unit.rb:594:in `run' from /Users/andreashaller/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/minitest/unit.rb:492:in `block in autorun' rake aborted! Command failed with status (1): [/Users/andreashaller/.rvm/rubies/ruby-1.9....] /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:995:in `block in sh' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:1010:in `call' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:1010:in `sh' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:1094:in `sh' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:1029:in `ruby' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:1094:in `ruby' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0/lib/rails/test_unit/testing.rake:26:in `block (2 levels) in define' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:1112:in `verbose' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0/lib/rails/test_unit/testing.rake:11:in `block in define' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:636:in `call' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:636:in `block in execute' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:631:in `each' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:631:in `execute' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:597:in `block in invoke_with_call_chain' /Users/andreashaller/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:583:in `invoke' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2029:in `block (2 levels) in top_level' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2029:in `each' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2029:in `block in top_level' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2001:in `block in run' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/lib/rake.rb:1998:in `run' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.8.7/bin/rake:31:in `<top (required)>' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/bin/rake:19:in `load' /Users/andreashaller/.rvm/gems/ruby-1.9.2-p0/bin/rake:19:in `<main>'
It's probably problem with Ruby 1.9.2. I've created new issue:
lib/active_support/testing/performance.rb and ruby-prof rely on Test::Unit, adding "gem 'test-unit'" to my Gemfile allows me to run test:profile and test:benchmark on 1.9.2 without the "uninitialized constant BrowsingTest::STARTED" exception. I'd also advise compiling ruby 1.9.2 with the gcdata patch to get the most out of the test:benchmark results (this is not the patch referenced at http://guides.rubyonrails.org/performance_testing.html#installing-g.... The gcdata patch is included with rvm but I'm not sure where the official version resides.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Tickets have moved to Github
The new ticket tracker is available at https://github.com/rails/rails/issues