Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Fresh Rails 3 app cannot run performance tests

#4171

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.

  1. 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.
  2. 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.
  3. The generator should not use the deprecated ActionController::PerformanceTest.
  4. ActionController::PerformanceTest should log a deprecation warning.

Reported by Chris Griego · March 14th, 2010 @ 05:35 AM

State: resolved
Milestone: 3.0.2
Assigned to: nobody
Importance: High

Activity

  1. Chris Griego
    Chris Griego
    • Tag changed from actioncontroller, actiondispatch, bundler, generators, performance_test to actioncontroller, actiondispatch, bug, bundler, generators, performance_test

    March 15th, 2010 @ 12:20 PM

  2. José Valim
    José Valim
    • Milestone cleared.

    Hey, could you provide a patch for this one as well?

    March 15th, 2010 @ 02:48 PM

  3. GitHub
    GitHub

    I'm happy to put together a patch, but I need some guidance on the best changes to make.

    March 15th, 2010 @ 03:36 PM

  4. Chris Griego
    Chris Griego

    I'm happy to put together a patch, but I need some guidance on the best changes to make.

    Sorry, wrong account above.

    March 15th, 2010 @ 03:40 PM

  5. Jeremy Kemper
    Jeremy Kemper
    • 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.

    March 16th, 2010 @ 03:41 PM

  6. Rizwan Reza
  7. chaitanyav
    chaitanyav
    • Importance changed from to High

    Rizwan, this ticket still shsows as new in the list. Can this be updated to show resolved

    June 26th, 2010 @ 06:39 AM

  8. chaitanyav
    chaitanyav
    • Assigned user cleared.

    oops... my bad.

    June 26th, 2010 @ 06:41 AM

  9. Andreas Haller
    Andreas Haller

    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>'
    

    September 17th, 2010 @ 04:57 PM

  10. MikZ
    MikZ

    Same problem here. Fails in activesupport-3.0.0/lib/active_support/testing/performance.rb:39

    Fresh Rails3 install, installed ruby-prof and added to Gemfile.

    September 28th, 2010 @ 10:37 AM

  11. MikZ
    MikZ

    Using Ruby 1.9.2 and ruby-pref 0.9.2

    September 28th, 2010 @ 11:04 AM

  12. MikZ
  13. Jeremy Kemper
  14. jnimety
    jnimety

    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.

    February 15th, 2011 @ 07:15 PM