burke / zeus

Boot any rails app in under a second.
MIT License
3.33k stars 231 forks source link

Zeus taking minutes to run tests, Rspec taking seconds? #453

Open TrevorHinesley opened 10 years ago

TrevorHinesley commented 10 years ago

Some of the individual tests are lightning fast with Zeus, and others are pretty dang slow.

If I do:

time rspec spec/

The result is:

Finished in 35.36 seconds
220 examples, 0 failures

real    0m59.018s
user    0m43.723s
sys 0m2.495s

But if I use Zeus:

time zeus rspec spec/

The result is:

Finished in 7 minutes 9 seconds
220 examples, 0 failures

real    7m13.053s
user    0m0.279s
sys 0m0.047s

What's up with this? Below is my spec_helper file:

    require File.expand_path("../../config/environment", __FILE__)
    require 'rubygems'
    require 'shoulda-matchers'
    require 'capybara/rspec'
    require 'capybara/rails'
    require 'sidekiq/testing'
    require "paperclip/matchers"
    require 'rspec/rails'
    require 'database_cleaner'
    require 'selenium-webdriver'
    require 'sunspot/rails/spec_helper'
    require 'timecop'
    # require 'webmock/rspec'
    #uncomment the following line to use spork with the debugger
    #require 'spork/ext/ruby-debug'

    def spork?
      defined?(Spork) && Spork.using_spork?
    end

    def setup_environment
      # This file is copied to spec/ when you run 'rails generate rspec:install'
      ENV["RAILS_ENV"] ||= 'test'

      if spork?
        ENV['DRB'] = 'true'
        Spork.trap_method(Rails::Application::RoutesReloader, :reload!)
      end

      Rails.backtrace_cleaner.remove_silencers!

      DatabaseCleaner.strategy = :transaction

      RSpec.configure do |config|

        Warden.test_mode!

        config.use_transactional_fixtures = false

        config.before(:suite) do
          DatabaseCleaner.clean_with(:transaction)
        end

        # Use transactions by default
        config.before :each do
          DatabaseCleaner.strategy = :transaction
        end

        config.before(:each) do
          DatabaseCleaner.start
        end

        config.after :each do
          DatabaseCleaner.clean
        end

        config.mock_with :rspec

        config.after(:each) do
          Warden.test_reset!
        end

        config.include Rails.application.routes.url_helpers
        config.include Capybara::DSL
        config.include Devise::TestHelpers, :type => :controller
        config.include Warden::Test::Helpers
        config.include FactoryGirl::Syntax::Methods
        config.include Paperclip::Shoulda::Matchers

        config.before(:each) do
          ::Sunspot.session = ::Sunspot::Rails::StubSessionProxy.new(::Sunspot.session)
        end

        config.after(:each) do
          ::Sunspot.session = ::Sunspot.session.original_session
        end
      end

      OmniAuth.config.test_mode = true
    end

    prefork = lambda {
      setup_environment
    }

    each_run = lambda {
      if spork?
        ActiveSupport::Dependencies.clear
        FactoryGirl.reload
      end

      # Requires supporting ruby files with custom matchers and macros, etc,
      # in spec/support/ and its subdirectories.
      Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
    }

    # If zeus is available in the Gemfile it'll be used but we don't force it.
    if defined?(Zeus)
      prefork.call
      $each_run = each_run
      class << Zeus.plan
        def after_fork_with_test
          after_fork_without_test
          $each_run.call
        end
        alias_method_chain :after_fork, :test
      end
    # Same with spork.
    elsif ENV['spork'] || $0 =~ /\bspork$/
      require 'spork'
      Spork.prefork(&prefork)
      Spork.each_run(&each_run)
    else
      prefork.call
      each_run.call
    end
camol commented 9 years ago

I'm having exactly same issue. Zeus starts properly but all commands like rspec or console run very very slow, liked there was nothing preloaded by the initial start of zeus. The problem is somehow probably connected with my system, because other people working on the same project run the latest zeus 0.15.4 without any issues. I'm on Mac system version 10.9.5. The same really small tests take even about 2-3 seconds longer than normally runned by rspec.

The zeus is installed globally not from the project Gemfile. I'm using latest stable RVM 1.26.11 with ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin13]. I tried many ruby versions (every time reinstalling the zeus) and no result. Strange thing is that the zeus 0.4.4 works properly :confused:.

Any thoughts?