This project is archived and is in readonly mode.

#4759 new
August Lilleaas

`rake test(:functionals|:units|....)` loads the environment twice

Reported by August Lilleaas | June 3rd, 2010 @ 04:16 PM

Here's the current flow.

** Invoke test:units (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
==> [config/environments/development.rb loads here] <==
** ultrasphinx: configuration file not found for "development" environment
** ultrasphinx: please run 'rake ultrasphinx:configure'
** ultrasphinx: spelling support not available (raspell configuration raised "uninitialized constant Ultrasphinx::Spell::Aspell")
** 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:units
==> [config/environment.rb loads here] <==
==> [config/environments/test.rb loads here] <==
Loaded suite /home/augustl/.rvm/gems/ruby-1.8.7-p249@global/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
......................................

The data for the bracketed annotations were found by adding puts statements to those files.

This becomes more of a problem the longer the environment takes to load. For example, the rails3 branch of gitorious.org takes 20-25 seconds to load because of the high number of routes (which I will probably file a separate issue for - that's a long time!). Here (and attached) is the output of rake routes. Having to wait about a minute for the tests to start running makes TDD rather tedious.

Comments and changes to this ticket

  • Daniel Abrahamsson

    Daniel Abrahamsson December 16th, 2010 @ 11:27 AM

    I'm facing the same issue with running my tests, due to the double loading of the environment.What is the reason that the environment is loaded twice?

  • Roger Leite

    Roger Leite February 16th, 2011 @ 10:36 AM

    I tested with rails 3.0.4, created an empty application and scaffold of users.
    With a "puts" in config/environment.rb, i did:

    rake test -t
    (in /home/roger/dev/trivial/temp/raketest) Invoke test (first_time) Execute test Invoke test:units (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 ENV LOADED !
    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:units ENV LOADED !
    Loaded suite /home/roger/.rvm/gems/ruby-1.8.7-p330@global/gems/rake-0.8.7/lib/rake/rake_test_loader
    Started
    . Finished in 0.027144 seconds.

    1 tests, 1 assertions, 0 failures, 0 errors
    Invoke test:functionals (first_time) Invoke test:prepare ** Execute test:functionals ENV LOADED !
    Loaded suite /home/roger/.rvm/gems/ruby-1.8.7-p330@global/gems/rake-0.8.7/lib/rake/rake_test_loader
    Started
    ....... Finished in 0.171518 seconds.

    7 tests, 10 assertions, 0 failures, 0 errors
    Invoke test:integration (first_time) Invoke test:prepare ** Execute test:integration

    I tried to test with rails edge too (changing Gemfile to use gem 'rails', :git => 'git://github.com/rails/rails.git'), and i got an error:


    (in /home/roger/dev/trivial/temp/raketest) Invoke test (first_time) Execute test Invoke test:units (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 Invoke test:functionals (first_time) Invoke test:prepare ** Execute test:functionals /home/roger/.rvm/gems/ruby-1.8.7-p330@rails-edge/bundler/gems/rails-8276a240207a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb:23: uninitialized constant Rack::Session::Abstract::SessionHash (NameError)

    {mkd-extraction-a95f96cb27b5f9de47f004b440afe16e}

    Invoke test:integration (first_time) Invoke test:prepare ** Execute test:integration Errors running test:units, test:functionals!

  • Roger Leite

    Roger Leite February 16th, 2011 @ 10:43 AM

    Trying to clean the previous message

    I tested with rails 3.0.4, created an empty application and scaffold of users.
    With a "puts" in config/environment.rb, i did:

    rake test -t

    I tried to test with rails edge too (changing Gemfile to use gem 'rails', :git => 'git://github.com/rails/rails.git'), and i got an error.

    Put the output at gist: https://gist.github.com/829168

  • Roger Leite

    Roger Leite February 16th, 2011 @ 10:56 AM

    Looking at source, i realized two things:
    1. https://github.com/rails/rails/blob/master/railties/lib/rails/appli... Rails, raises exception if application is already initialized.
    2. Task test ( https://github.com/rails/rails/blob/master/railties/lib/rails/test_... ) invokes "test:units test:functionals test:integration". I think they are running in different process.

    Somebody can help me ?

  • Christopher Meiklejohn

    Christopher Meiklejohn March 3rd, 2011 @ 04:37 AM

    Hi Roger,

    I'm not running into any problems running the test suite on the rails master branch -- can you try doing this again?

    Thanks,
    Chris

  • Christopher Meiklejohn

    Christopher Meiklejohn March 3rd, 2011 @ 05:18 AM

    Roger,

    Keep in mind if you are running edge rails, you need to be running edge rack as well, which is probably why you are getting the SessionHash error.

  • Roger Leite

    Roger Leite March 3rd, 2011 @ 02:42 PM

    I didn't know about edge rack ...
    Sorry for the false positive.

    Thanks for the tip Christopher! It worked.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Tags

Pages