Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my "boot time" of `rake test:units` on Rails 3.2.1 so slow?

We're developing an app on Ruby 1.9.3 and Rails 3.2.1.

Recently, our unit tests have become sluggish at the beginning. It takes ~15 seconds for the invocations & executions to take place. Once I see "Execute test:units", it takes another 10 seconds before I see any output. Finally, the task completes and tests only take 3 seconds to execute themselves.

3 seconds for unit tests is acceptable. 25 second load time isn't realistic for BDD/TDD.

Here's what happens when I run with rake test:units --trace:

** 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
** 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:test:load_schema (first_time)
** Invoke db:test:purge 
** Execute db:test:load_schema
** Invoke db:schema:load (first_time)
** Invoke environment 
** Execute db:schema:load
** Execute test:prepare
** Execute test:units

I wouldn't doubt that the database schema being loaded, then re-loaded, might be a key source of slowness. However, I haven't done anything to our Rakefile related to unit tests. Where can I peek to see what's really happening under the hood?

This is what's at the top of test/test_helper.rb:

require 'simplecov'
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'

What I've tried:

  1. Commenting out simplecov, as we only use that for our CI server, not during development (made no difference in execution time)
  2. Commenting out the other stuff, but that broke the tests from even executing. I'm not entirely sure why those other items are there, as I thought that the Rails environment would be loaded in "test" automatically.

Any ideas on where/how I can poke my head next to see?

Is there any chance that Rails is running migrations instead of just schema:load? As we develop, we have a large number of migrations (~30).

EDIT:

I am using a 2011-model Macbook Pro with 8G RAM and Core i7 - don't think it's my machine. I've seen in this question that on Windows, require can cause problems.

I've also considered that fixtures may be the problem, but if fixtures were the problem, the tests themselves, not the load time to the tests, would be slow, right?

EDIT 2:

Thanks to pchap10k's answer I think that it has nothing to do with rake -- it's about our Gemfile. Maybe I should search in that area...

like image 864
makdad Avatar asked May 27 '12 01:05

makdad


1 Answers

Could be your gems loading slowly. See this thread for similar complaints about slow rake load times in Rails 3.x > slow rails stack

like image 73
pchap10k Avatar answered Oct 20 '22 08:10

pchap10k